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.destroy => nil
26 * Destroys the message, freeing all resources allocated for it.
29 notmuch_rb_message_destroy(VALUE self)
31 notmuch_message_t *message;
33 Data_Get_Struct(self, notmuch_message_t, message);
35 notmuch_message_destroy(message);
41 * call-seq: MESSAGE.message_id => String
43 * Get the message ID of 'message'.
46 notmuch_rb_message_get_message_id(VALUE self)
49 notmuch_message_t *message;
51 Data_Get_Struct(self, notmuch_message_t, message);
53 msgid = notmuch_message_get_message_id(message);
55 return rb_str_new2(msgid);
59 * call-seq: MESSAGE.thread_id => String
61 * Get the thread ID of 'message'.
64 notmuch_rb_message_get_thread_id(VALUE self)
67 notmuch_message_t *message;
69 Data_Get_Struct(self, notmuch_message_t, message);
71 tid = notmuch_message_get_thread_id(message);
73 return rb_str_new2(tid);
77 * call-seq: MESSAGE.replies => MESSAGES
79 * Get a Notmuch::Messages enumerable for all of the replies to 'message'.
82 notmuch_rb_message_get_replies(VALUE self)
84 notmuch_messages_t *messages;
85 notmuch_message_t *message;
87 Data_Get_Struct(self, notmuch_message_t, message);
89 messages = notmuch_message_get_replies(message);
91 return Data_Wrap_Struct(notmuch_rb_cMessages, NULL, NULL, messages);
95 * call-seq: MESSAGE.filename => String
97 * Get a filename for the email corresponding to 'message'
100 notmuch_rb_message_get_filename(VALUE self)
103 notmuch_message_t *message;
105 Data_Get_Struct(self, notmuch_message_t, message);
107 fname = notmuch_message_get_filename(message);
109 return rb_str_new2(fname);
113 * call-seq: MESSAGE.get_flag(flag) => true or false
115 * Get a value of a flag for the email corresponding to 'message'
118 notmuch_rb_message_get_flag(VALUE self, VALUE flagv)
120 notmuch_message_t *message;
122 Data_Get_Struct(self, notmuch_message_t, message);
124 if (!FIXNUM_P(flagv))
125 rb_raise(rb_eTypeError, "Flag not a Fixnum");
127 return notmuch_message_get_flag(message, FIX2INT(flagv)) ? Qtrue : Qfalse;
131 * call-seq: MESSAGE.set_flag(flag, value) => nil
133 * Set a value of a flag for the email corresponding to 'message'
136 notmuch_rb_message_set_flag(VALUE self, VALUE flagv, VALUE valuev)
138 notmuch_message_t *message;
140 Data_Get_Struct(self, notmuch_message_t, message);
142 if (!FIXNUM_P(flagv))
143 rb_raise(rb_eTypeError, "Flag not a Fixnum");
145 notmuch_message_set_flag(message, FIX2INT(flagv), RTEST(valuev));
151 * call-seq: MESSAGE.date => Fixnum
153 * Get the date of 'message'
156 notmuch_rb_message_get_date(VALUE self)
158 notmuch_message_t *message;
160 Data_Get_Struct(self, notmuch_message_t, message);
162 return UINT2NUM(notmuch_message_get_date(message));
166 * call-seq: MESSAGE.header(name) => String
168 * Get the value of the specified header from 'message'
171 notmuch_rb_message_get_header(VALUE self, VALUE headerv)
173 const char *header, *value;
174 notmuch_message_t *message;
176 Data_Get_Struct(self, notmuch_message_t, message);
178 #if !defined(RSTRING_PTR)
179 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
180 #endif /* !defined(RSTRING_PTR) */
182 SafeStringValue(headerv);
183 header = RSTRING_PTR(headerv);
185 value = notmuch_message_get_header(message, header);
187 rb_raise(notmuch_rb_eMemoryError, "Out of memory");
189 return rb_str_new2(value);
193 * call-seq: MESSAGE.tags => TAGS
195 * Get a Notmuch::Tags enumerable for all of the tags of 'message'.
198 notmuch_rb_message_get_tags(VALUE self)
200 notmuch_message_t *message;
201 notmuch_tags_t *tags;
203 Data_Get_Struct(self, notmuch_message_t, message);
205 tags = notmuch_message_get_tags(message);
207 rb_raise(notmuch_rb_eMemoryError, "Out of memory");
209 return Data_Wrap_Struct(notmuch_rb_cTags, NULL, NULL, tags);
213 * call-seq: MESSAGE.add_tag(tag) => true
215 * Add a tag to the 'message'
218 notmuch_rb_message_add_tag(VALUE self, VALUE tagv)
221 notmuch_status_t ret;
222 notmuch_message_t *message;
224 Data_Get_Struct(self, notmuch_message_t, message);
226 #if !defined(RSTRING_PTR)
227 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
228 #endif /* !defined(RSTRING_PTR) */
230 SafeStringValue(tagv);
231 tag = RSTRING_PTR(tagv);
233 ret = notmuch_message_add_tag(message, tag);
234 notmuch_rb_status_raise(ret);
240 * call-seq: MESSAGE.remove_tag(tag) => true
242 * Remove a tag from the 'message'
245 notmuch_rb_message_remove_tag(VALUE self, VALUE tagv)
248 notmuch_status_t ret;
249 notmuch_message_t *message;
251 Data_Get_Struct(self, notmuch_message_t, message);
253 #if !defined(RSTRING_PTR)
254 #define RSTRING_PTR(v) (RSTRING((v))->ptr)
255 #endif /* !defined(RSTRING_PTR) */
257 SafeStringValue(tagv);
258 tag = RSTRING_PTR(tagv);
260 ret = notmuch_message_remove_tag(message, tag);
261 notmuch_rb_status_raise(ret);
267 * call-seq: MESSAGE.remove_all_tags => true
269 * Remove all tags of the 'message'
272 notmuch_rb_message_remove_all_tags(VALUE self)
274 notmuch_status_t ret;
275 notmuch_message_t *message;
277 Data_Get_Struct(self, notmuch_message_t, message);
279 ret = notmuch_message_remove_all_tags(message);
280 notmuch_rb_status_raise(ret);
286 * call-seq: MESSAGE.freeze => true
288 * Freeze the 'message'
291 notmuch_rb_message_freeze(VALUE self)
293 notmuch_status_t ret;
294 notmuch_message_t *message;
296 Data_Get_Struct(self, notmuch_message_t, message);
298 ret = notmuch_message_freeze(message);
299 notmuch_rb_status_raise(ret);
305 * call-seq: MESSAGE.thaw => true
310 notmuch_rb_message_thaw(VALUE self)
312 notmuch_status_t ret;
313 notmuch_message_t *message;
315 Data_Get_Struct(self, notmuch_message_t, message);
317 ret = notmuch_message_thaw(message);
318 notmuch_rb_status_raise(ret);