]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/thread.c
ruby: First attempt at fixing gc for ruby-1.9
[notmuch] / bindings / ruby / thread.c
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010 Ali Polatel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Ali Polatel <alip@exherbo.org>
19  */
20
21 #include "defs.h"
22
23 /*
24  * call-seq: THREAD.thread_id => String
25  *
26  * Returns the thread id
27  */
28 VALUE
29 notmuch_rb_thread_get_thread_id(VALUE self)
30 {
31     const char *tid;
32     notmuch_rb_thread_t *thread;
33
34     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
35
36     tid = notmuch_thread_get_thread_id(thread->nm_thread);
37     return tid ? rb_str_new2(tid) : Qnil;
38 }
39
40 /*
41  * call-seq: THREAD.total_messages => fixnum
42  *
43  * Returns the number of total messages
44  */
45 VALUE
46 notmuch_rb_thread_get_total_messages(VALUE self)
47 {
48     notmuch_rb_thread_t *thread;
49
50     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
51
52     return INT2FIX(notmuch_thread_get_total_messages(thread->nm_thread));
53 }
54
55 /*
56  * call-seq: THREAD.toplevel_messages => MESSAGES
57  *
58  * Get a Notmuch::Messages iterator for the top level messages in thread.
59  */
60 VALUE
61 notmuch_rb_thread_get_toplevel_messages(VALUE self)
62 {
63     notmuch_rb_messages_t *messages;
64     notmuch_rb_thread_t *thread;
65     VALUE messagesv;
66
67     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
68
69     messagesv = Data_Make_Struct(notmuch_rb_cMessages, notmuch_rb_messages_t,
70             notmuch_rb_messages_mark, notmuch_rb_messages_free, messages);
71     messages->nm_messages = notmuch_thread_get_toplevel_messages(thread->nm_thread);
72     messages->parent = self;
73     if (!messages->nm_messages)
74         rb_raise(notmuch_rb_eMemoryError, "out of memory");
75
76     return messagesv;
77 }
78
79 /*
80  * call-seq: THREAD.matched_messages => fixnum
81  *
82  * Get the number of messages in thread that matched the search
83  */
84 VALUE
85 notmuch_rb_thread_get_matched_messages(VALUE self)
86 {
87     notmuch_rb_thread_t *thread;
88
89     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
90
91     return INT2FIX(notmuch_thread_get_matched_messages(thread->nm_thread));
92 }
93
94 /*
95  * call-seq: THREAD.authors => String
96  *
97  * Get a comma-separated list of the names of the authors.
98  */
99 VALUE
100 notmuch_rb_thread_get_authors(VALUE self)
101 {
102     const char *authors;
103     notmuch_rb_thread_t *thread;
104
105     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
106
107     authors = notmuch_thread_get_authors(thread->nm_thread);
108     return authors ? rb_str_new2(authors) : Qnil;
109 }
110
111 /*
112  * call-seq: THREAD.subject => String
113  *
114  * Returns the subject of the thread
115  */
116 VALUE
117 notmuch_rb_thread_get_subject(VALUE self)
118 {
119     const char *subject;
120     notmuch_rb_thread_t *thread;
121
122     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
123
124     subject = notmuch_thread_get_subject(thread->nm_thread);
125     return subject ? rb_str_new2(subject) : Qnil;
126 }
127
128 /*
129  * call-seq: THREAD.oldest_date => Fixnum
130  *
131  * Get the date of the oldest message in thread.
132  */
133 VALUE
134 notmuch_rb_thread_get_oldest_date(VALUE self)
135 {
136     notmuch_rb_thread_t *thread;
137
138     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
139
140     return UINT2NUM(notmuch_thread_get_oldest_date(thread->nm_thread));
141 }
142
143 /*
144  * call-seq: THREAD.newest_date => fixnum
145  *
146  * Get the date of the newest message in thread.
147  */
148 VALUE
149 notmuch_rb_thread_get_newest_date(VALUE self)
150 {
151     notmuch_rb_thread_t *thread;
152
153     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
154
155     return UINT2NUM(notmuch_thread_get_newest_date(thread->nm_thread));
156 }
157
158 /*
159  * call-seq: THREAD.tags => TAGS
160  *
161  * Get a Notmuch::Tags iterator for the tags of the thread
162  */
163 VALUE
164 notmuch_rb_thread_get_tags(VALUE self)
165 {
166     notmuch_rb_thread_t *thread;
167     notmuch_rb_tags_t *tags;
168     VALUE tagsv;
169
170     Data_Get_Struct(self, notmuch_rb_thread_t, thread);
171
172     tagsv = Data_Make_Struct(notmuch_rb_cTags, notmuch_rb_tags_t,
173             notmuch_rb_tags_mark, notmuch_rb_tags_free, tags);
174     tags->nm_tags = notmuch_thread_get_tags(thread->nm_thread);
175     tags->parent = self;
176     if (!tags->nm_tags)
177         rb_raise(notmuch_rb_eMemoryError, "out of memory");
178
179     return tagsv;
180 }