1 /* The Ruby interface to the notmuch mail library
3 * Copyright © 2010 Ali Polatel
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.
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.
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/ .
18 * Author: Ali Polatel <alip@exherbo.org>
24 * call-seq: THREAD.thread_id => String
26 * Returns the thread id
29 notmuch_rb_thread_get_thread_id(VALUE self)
32 notmuch_rb_thread_t *thread;
34 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
36 tid = notmuch_thread_get_thread_id(thread->nm_thread);
37 return tid ? rb_str_new2(tid) : Qnil;
41 * call-seq: THREAD.total_messages => fixnum
43 * Returns the number of total messages
46 notmuch_rb_thread_get_total_messages(VALUE self)
48 notmuch_rb_thread_t *thread;
50 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
52 return INT2FIX(notmuch_thread_get_total_messages(thread->nm_thread));
56 * call-seq: THREAD.toplevel_messages => MESSAGES
58 * Get a Notmuch::Messages iterator for the top level messages in thread.
61 notmuch_rb_thread_get_toplevel_messages(VALUE self)
63 notmuch_rb_messages_t *messages;
64 notmuch_rb_thread_t *thread;
67 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
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");
80 * call-seq: THREAD.matched_messages => fixnum
82 * Get the number of messages in thread that matched the search
85 notmuch_rb_thread_get_matched_messages(VALUE self)
87 notmuch_rb_thread_t *thread;
89 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
91 return INT2FIX(notmuch_thread_get_matched_messages(thread->nm_thread));
95 * call-seq: THREAD.authors => String
97 * Get a comma-separated list of the names of the authors.
100 notmuch_rb_thread_get_authors(VALUE self)
103 notmuch_rb_thread_t *thread;
105 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
107 authors = notmuch_thread_get_authors(thread->nm_thread);
108 return authors ? rb_str_new2(authors) : Qnil;
112 * call-seq: THREAD.subject => String
114 * Returns the subject of the thread
117 notmuch_rb_thread_get_subject(VALUE self)
120 notmuch_rb_thread_t *thread;
122 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
124 subject = notmuch_thread_get_subject(thread->nm_thread);
125 return subject ? rb_str_new2(subject) : Qnil;
129 * call-seq: THREAD.oldest_date => Fixnum
131 * Get the date of the oldest message in thread.
134 notmuch_rb_thread_get_oldest_date(VALUE self)
136 notmuch_rb_thread_t *thread;
138 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
140 return UINT2NUM(notmuch_thread_get_oldest_date(thread->nm_thread));
144 * call-seq: THREAD.newest_date => fixnum
146 * Get the date of the newest message in thread.
149 notmuch_rb_thread_get_newest_date(VALUE self)
151 notmuch_rb_thread_t *thread;
153 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
155 return UINT2NUM(notmuch_thread_get_newest_date(thread->nm_thread));
159 * call-seq: THREAD.tags => TAGS
161 * Get a Notmuch::Tags iterator for the tags of the thread
164 notmuch_rb_thread_get_tags(VALUE self)
166 notmuch_rb_thread_t *thread;
167 notmuch_rb_tags_t *tags;
170 Data_Get_Struct(self, notmuch_rb_thread_t, thread);
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);
177 rb_raise(notmuch_rb_eMemoryError, "out of memory");