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