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