]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/thread.c
Merge branch 'release'
[notmuch] / bindings / ruby / thread.c
1 /* The Ruby interface to the notmuch mail library
2  *
3  * Copyright © 2010, 2011 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.destroy! => nil
25  *
26  * Destroys the thread, freeing all resources allocated for it.
27  */
28 VALUE
29 notmuch_rb_thread_destroy (VALUE self)
30 {
31     notmuch_thread_t *thread;
32
33     Data_Get_Notmuch_Thread (self, thread);
34
35     notmuch_thread_destroy (thread);
36     DATA_PTR (self) = NULL;
37
38     return Qnil;
39 }
40
41 /*
42  * call-seq: THREAD.thread_id => String
43  *
44  * Returns the thread id
45  */
46 VALUE
47 notmuch_rb_thread_get_thread_id (VALUE self)
48 {
49     const char *tid;
50     notmuch_thread_t *thread;
51
52     Data_Get_Notmuch_Thread (self, thread);
53
54     tid = notmuch_thread_get_thread_id (thread);
55
56     return rb_str_new2 (tid);
57 }
58
59 /*
60  * call-seq: THREAD.total_messages => fixnum
61  *
62  * Returns the number of total messages
63  */
64 VALUE
65 notmuch_rb_thread_get_total_messages (VALUE self)
66 {
67     notmuch_thread_t *thread;
68
69     Data_Get_Notmuch_Thread (self, thread);
70
71     return INT2FIX (notmuch_thread_get_total_messages (thread));
72 }
73
74 /*
75  * call-seq: THREAD.toplevel_messages => MESSAGES
76  *
77  * Get a Notmuch::Messages iterator for the top level messages in thread.
78  */
79 VALUE
80 notmuch_rb_thread_get_toplevel_messages (VALUE self)
81 {
82     notmuch_messages_t *messages;
83     notmuch_thread_t *thread;
84
85     Data_Get_Notmuch_Thread (self, thread);
86
87     messages = notmuch_thread_get_toplevel_messages (thread);
88     if (!messages)
89         rb_raise (notmuch_rb_eMemoryError, "Out of memory");
90
91     return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
92 }
93
94 /*
95  * call-seq: THREAD.messages => MESSAGES
96  *
97  * Get a Notmuch::Messages iterator for the all messages in thread.
98  */
99 VALUE
100 notmuch_rb_thread_get_messages (VALUE self)
101 {
102     notmuch_messages_t *messages;
103     notmuch_thread_t *thread;
104
105     Data_Get_Notmuch_Thread (self, thread);
106
107     messages = notmuch_thread_get_messages (thread);
108     if (!messages)
109         rb_raise (notmuch_rb_eMemoryError, "Out of memory");
110
111     return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
112 }
113
114 /*
115  * call-seq: THREAD.matched_messages => fixnum
116  *
117  * Get the number of messages in thread that matched the search
118  */
119 VALUE
120 notmuch_rb_thread_get_matched_messages (VALUE self)
121 {
122     notmuch_thread_t *thread;
123
124     Data_Get_Notmuch_Thread (self, thread);
125
126     return INT2FIX (notmuch_thread_get_matched_messages (thread));
127 }
128
129 /*
130  * call-seq: THREAD.authors => String
131  *
132  * Get a comma-separated list of the names of the authors.
133  */
134 VALUE
135 notmuch_rb_thread_get_authors (VALUE self)
136 {
137     const char *authors;
138     notmuch_thread_t *thread;
139
140     Data_Get_Notmuch_Thread (self, thread);
141
142     authors = notmuch_thread_get_authors (thread);
143
144     return rb_str_new2 (authors);
145 }
146
147 /*
148  * call-seq: THREAD.subject => String
149  *
150  * Returns the subject of the thread
151  */
152 VALUE
153 notmuch_rb_thread_get_subject (VALUE self)
154 {
155     const char *subject;
156     notmuch_thread_t *thread;
157
158     Data_Get_Notmuch_Thread (self, thread);
159
160     subject = notmuch_thread_get_subject (thread);
161
162     return rb_str_new2 (subject);
163 }
164
165 /*
166  * call-seq: THREAD.oldest_date => Fixnum
167  *
168  * Get the date of the oldest message in thread.
169  */
170 VALUE
171 notmuch_rb_thread_get_oldest_date (VALUE self)
172 {
173     notmuch_thread_t *thread;
174
175     Data_Get_Notmuch_Thread (self, thread);
176
177     return UINT2NUM (notmuch_thread_get_oldest_date (thread));
178 }
179
180 /*
181  * call-seq: THREAD.newest_date => fixnum
182  *
183  * Get the date of the newest message in thread.
184  */
185 VALUE
186 notmuch_rb_thread_get_newest_date (VALUE self)
187 {
188     notmuch_thread_t *thread;
189
190     Data_Get_Notmuch_Thread (self, thread);
191
192     return UINT2NUM (notmuch_thread_get_newest_date (thread));
193 }
194
195 /*
196  * call-seq: THREAD.tags => TAGS
197  *
198  * Get a Notmuch::Tags iterator for the tags of the thread
199  */
200 VALUE
201 notmuch_rb_thread_get_tags (VALUE self)
202 {
203     notmuch_thread_t *thread;
204     notmuch_tags_t *tags;
205
206     Data_Get_Notmuch_Thread (self, thread);
207
208     tags = notmuch_thread_get_tags (thread);
209     if (!tags)
210         rb_raise (notmuch_rb_eMemoryError, "Out of memory");
211
212     return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
213 }