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: MESSAGE.message_id => String
26 * Get the message ID of 'message'.
29 notmuch_rb_message_get_message_id(VALUE self)
32 notmuch_rb_message_t *message;
34 Data_Get_Struct(self, notmuch_rb_message_t, message);
36 msgid = notmuch_message_get_message_id(message->nm_message);
37 return msgid ? rb_str_new2(msgid) : Qnil;
41 * call-seq: MESSAGE.thread_id => String
43 * Get the thread ID of 'message'.
46 notmuch_rb_message_get_thread_id(VALUE self)
49 notmuch_rb_message_t *message;
51 Data_Get_Struct(self, notmuch_rb_message_t, message);
53 tid = notmuch_message_get_thread_id(message->nm_message);
54 return tid ? rb_str_new2(tid) : Qnil;
58 * call-seq: MESSAGE.replies => MESSAGES
60 * Get a Notmuch::Messages enumerable for all of the replies to 'message'.
63 notmuch_rb_message_get_replies(VALUE self)
65 notmuch_rb_messages_t *messages;
66 notmuch_rb_message_t *message;
69 Data_Get_Struct(self, notmuch_rb_message_t, message);
71 messagesv = Data_Make_Struct(notmuch_rb_cMessages, notmuch_rb_messages_t,
72 notmuch_rb_messages_mark, notmuch_rb_messages_free, messages);
73 messages->nm_messages = notmuch_message_get_replies(message->nm_message);
74 messages->parent = self;
76 return messages->nm_messages ? messagesv : Qnil;
80 * call-seq: MESSAGE.filename => String
82 * Get a filename for the email corresponding to 'message'
85 notmuch_rb_message_get_filename(VALUE self)
88 notmuch_rb_message_t *message;
90 Data_Get_Struct(self, notmuch_rb_message_t, message);
92 fname = notmuch_message_get_filename(message->nm_message);
93 return fname ? rb_str_new2(fname) : Qnil;
97 * call-seq: MESSAGE.get_flag(flag) => true or false
99 * Get a value of a flag for the email corresponding to 'message'
102 notmuch_rb_message_get_flag(VALUE self, VALUE flagv)
104 notmuch_rb_message_t *message;
106 Data_Get_Struct(self, notmuch_rb_message_t, message);
108 if (!FIXNUM_P(flagv))
109 rb_raise(rb_eTypeError, "Flag not a Fixnum");
111 return notmuch_message_get_flag(message->nm_message, FIX2INT(flagv)) ? Qtrue : Qfalse;
115 * call-seq: MESSAGE.set_flag(flag, value) => nil
117 * Set a value of a flag for the email corresponding to 'message'
120 notmuch_rb_message_set_flag(VALUE self, VALUE flagv, VALUE valuev)
122 notmuch_rb_message_t *message;
124 Data_Get_Struct(self, notmuch_rb_message_t, message);
126 if (!FIXNUM_P(flagv))
127 rb_raise(rb_eTypeError, "Flag not a Fixnum");
129 notmuch_message_set_flag(message->nm_message, FIX2INT(flagv), RTEST(valuev));
134 * call-seq: MESSAGE.date => Fixnum
136 * Get the date of 'message'
139 notmuch_rb_message_get_date(VALUE self)
141 notmuch_rb_message_t *message;
143 Data_Get_Struct(self, notmuch_rb_message_t, message);
145 return UINT2NUM(notmuch_message_get_date(message->nm_message));
149 * call-seq: MESSAGE.header(name) => String
151 * Get the value of the specified header from 'message'
154 notmuch_rb_message_get_header(VALUE self, VALUE headerv)
156 const char *header, *value;
157 notmuch_rb_message_t *message;
159 Data_Get_Struct(self, notmuch_rb_message_t, message);
161 #if !defined(RSTRING_PTR)
162 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
163 #endif /* !defined(RSTRING_PTR) */
165 SafeStringValue(headerv);
166 header = RSTRING_PTR(headerv);
168 value = notmuch_message_get_header(message->nm_message, header);
170 rb_raise(notmuch_rb_eMemoryError, "out of memory");
172 return rb_str_new2(value);
176 * call-seq: MESSAGE.tags => TAGS
178 * Get a Notmuch::Tags enumerable for all of the tags of 'message'.
181 notmuch_rb_message_get_tags(VALUE self)
183 notmuch_rb_message_t *message;
184 notmuch_rb_tags_t *tags;
187 Data_Get_Struct(self, notmuch_rb_message_t, message);
189 tagsv = Data_Make_Struct(notmuch_rb_cTags, notmuch_rb_tags_t,
190 notmuch_rb_tags_mark, notmuch_rb_tags_free, tags);
191 tags->nm_tags = notmuch_message_get_tags(message->nm_message);
194 rb_raise(notmuch_rb_eMemoryError, "out of memory");
200 * call-seq: MESSAGE.add_tag(tag) => true
202 * Add a tag to the 'message'
205 notmuch_rb_message_add_tag(VALUE self, VALUE tagv)
208 notmuch_status_t ret;
209 notmuch_rb_message_t *message;
211 Data_Get_Struct(self, notmuch_rb_message_t, message);
213 #if !defined(RSTRING_PTR)
214 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
215 #endif /* !defined(RSTRING_PTR) */
217 SafeStringValue(tagv);
218 tag = RSTRING_PTR(tagv);
220 ret = notmuch_message_add_tag(message->nm_message, tag);
221 notmuch_rb_status_raise(ret);
226 * call-seq: MESSAGE.remove_tag(tag) => true
228 * Remove a tag from the 'message'
231 notmuch_rb_message_remove_tag(VALUE self, VALUE tagv)
234 notmuch_status_t ret;
235 notmuch_rb_message_t *message;
237 Data_Get_Struct(self, notmuch_rb_message_t, message);
239 #if !defined(RSTRING_PTR)
240 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
241 #endif /* !defined(RSTRING_PTR) */
243 SafeStringValue(tagv);
244 tag = RSTRING_PTR(tagv);
246 ret = notmuch_message_remove_tag(message->nm_message, tag);
247 notmuch_rb_status_raise(ret);
252 * call-seq: MESSAGE.remove_all_tags => true
254 * Remove all tags of the 'message'
257 notmuch_rb_message_remove_all_tags(VALUE self)
259 notmuch_status_t ret;
260 notmuch_rb_message_t *message;
262 Data_Get_Struct(self, notmuch_rb_message_t, message);
264 ret = notmuch_message_remove_all_tags(message->nm_message);
265 notmuch_rb_status_raise(ret);
270 * call-seq: MESSAGE.freeze => true
272 * Freeze the 'message'
275 notmuch_rb_message_freeze(VALUE self)
277 notmuch_status_t ret;
278 notmuch_rb_message_t *message;
280 Data_Get_Struct(self, notmuch_rb_message_t, message);
282 ret = notmuch_message_freeze(message->nm_message);
283 notmuch_rb_status_raise(ret);
288 * call-seq: MESSAGE.thaw => true
293 notmuch_rb_message_thaw(VALUE self)
295 notmuch_status_t ret;
296 notmuch_rb_message_t *message;
298 Data_Get_Struct(self, notmuch_rb_message_t, message);
300 ret = notmuch_message_thaw(message->nm_message);
301 notmuch_rb_status_raise(ret);