1 /* The Ruby interface to the notmuch mail library
3 * Copyright © 2010, 2011 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 https://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_Notmuch_Message (self, message);
35 notmuch_message_destroy (message);
36 DATA_PTR (self) = NULL;
42 * call-seq: MESSAGE.message_id => String
44 * Get the message ID of 'message'.
47 notmuch_rb_message_get_message_id (VALUE self)
50 notmuch_message_t *message;
52 Data_Get_Notmuch_Message (self, message);
54 msgid = notmuch_message_get_message_id (message);
56 return rb_str_new2 (msgid);
60 * call-seq: MESSAGE.thread_id => String
62 * Get the thread ID of 'message'.
65 notmuch_rb_message_get_thread_id (VALUE self)
68 notmuch_message_t *message;
70 Data_Get_Notmuch_Message (self, message);
72 tid = notmuch_message_get_thread_id (message);
74 return rb_str_new2 (tid);
78 * call-seq: MESSAGE.replies => MESSAGES
80 * Get a Notmuch::Messages enumerable for all of the replies to 'message'.
83 notmuch_rb_message_get_replies (VALUE self)
85 notmuch_messages_t *messages;
86 notmuch_message_t *message;
88 Data_Get_Notmuch_Message (self, message);
90 messages = notmuch_message_get_replies (message);
92 return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
96 * call-seq: MESSAGE.filename => String
98 * Get a filename for the email corresponding to 'message'
101 notmuch_rb_message_get_filename (VALUE self)
104 notmuch_message_t *message;
106 Data_Get_Notmuch_Message (self, message);
108 fname = notmuch_message_get_filename (message);
110 return rb_str_new2 (fname);
114 * call-seq: MESSAGE.filenames => FILENAMES
116 * Get all filenames for the email corresponding to MESSAGE.
119 notmuch_rb_message_get_filenames (VALUE self)
121 notmuch_filenames_t *fnames;
122 notmuch_message_t *message;
124 Data_Get_Notmuch_Message (self, message);
126 fnames = notmuch_message_get_filenames (message);
128 return Data_Wrap_Struct (notmuch_rb_cFileNames, NULL, NULL, fnames);
132 * call-seq: MESSAGE.get_flag (flag) => true or false
134 * Get a value of a flag for the email corresponding to 'message'
137 notmuch_rb_message_get_flag (VALUE self, VALUE flagv)
139 notmuch_message_t *message;
140 notmuch_bool_t is_set;
141 notmuch_status_t status;
143 Data_Get_Notmuch_Message (self, message);
145 if (!FIXNUM_P (flagv))
146 rb_raise (rb_eTypeError, "Flag not a Fixnum");
148 status = notmuch_message_get_flag_st (message, FIX2INT (flagv), &is_set);
149 notmuch_rb_status_raise (status);
151 return is_set ? Qtrue : Qfalse;
155 * call-seq: MESSAGE.set_flag (flag, value) => nil
157 * Set a value of a flag for the email corresponding to 'message'
160 notmuch_rb_message_set_flag (VALUE self, VALUE flagv, VALUE valuev)
162 notmuch_message_t *message;
164 Data_Get_Notmuch_Message (self, message);
166 if (!FIXNUM_P (flagv))
167 rb_raise (rb_eTypeError, "Flag not a Fixnum");
169 notmuch_message_set_flag (message, FIX2INT (flagv), RTEST (valuev));
175 * call-seq: MESSAGE.date => Fixnum
177 * Get the date of 'message'
180 notmuch_rb_message_get_date (VALUE self)
182 notmuch_message_t *message;
184 Data_Get_Notmuch_Message (self, message);
186 return UINT2NUM (notmuch_message_get_date (message));
190 * call-seq: MESSAGE.header (name) => String
192 * Get the value of the specified header from 'message'
195 notmuch_rb_message_get_header (VALUE self, VALUE headerv)
197 const char *header, *value;
198 notmuch_message_t *message;
200 Data_Get_Notmuch_Message (self, message);
202 SafeStringValue (headerv);
203 header = RSTRING_PTR (headerv);
205 value = notmuch_message_get_header (message, header);
207 rb_raise (notmuch_rb_eMemoryError, "Out of memory");
209 return rb_str_new2 (value);
213 * call-seq: MESSAGE.tags => TAGS
215 * Get a Notmuch::Tags enumerable for all of the tags of 'message'.
218 notmuch_rb_message_get_tags (VALUE self)
220 notmuch_message_t *message;
221 notmuch_tags_t *tags;
223 Data_Get_Notmuch_Message (self, message);
225 tags = notmuch_message_get_tags (message);
227 rb_raise (notmuch_rb_eMemoryError, "Out of memory");
229 return Data_Wrap_Struct (notmuch_rb_cTags, NULL, NULL, tags);
233 * call-seq: MESSAGE.add_tag (tag) => true
235 * Add a tag to the 'message'
238 notmuch_rb_message_add_tag (VALUE self, VALUE tagv)
241 notmuch_status_t ret;
242 notmuch_message_t *message;
244 Data_Get_Notmuch_Message (self, message);
246 SafeStringValue (tagv);
247 tag = RSTRING_PTR (tagv);
249 ret = notmuch_message_add_tag (message, tag);
250 notmuch_rb_status_raise (ret);
256 * call-seq: MESSAGE.remove_tag (tag) => true
258 * Remove a tag from the 'message'
261 notmuch_rb_message_remove_tag (VALUE self, VALUE tagv)
264 notmuch_status_t ret;
265 notmuch_message_t *message;
267 Data_Get_Notmuch_Message (self, message);
269 SafeStringValue (tagv);
270 tag = RSTRING_PTR (tagv);
272 ret = notmuch_message_remove_tag (message, tag);
273 notmuch_rb_status_raise (ret);
279 * call-seq: MESSAGE.remove_all_tags => true
281 * Remove all tags of the 'message'
284 notmuch_rb_message_remove_all_tags (VALUE self)
286 notmuch_status_t ret;
287 notmuch_message_t *message;
289 Data_Get_Notmuch_Message (self, message);
291 ret = notmuch_message_remove_all_tags (message);
292 notmuch_rb_status_raise (ret);
298 * call-seq: MESSAGE.maildir_flags_to_tags => true
300 * Add/remove tags according to maildir flags in the message filename (s)
303 notmuch_rb_message_maildir_flags_to_tags (VALUE self)
305 notmuch_status_t ret;
306 notmuch_message_t *message;
308 Data_Get_Notmuch_Message (self, message);
310 ret = notmuch_message_maildir_flags_to_tags (message);
311 notmuch_rb_status_raise (ret);
317 * call-seq: MESSAGE.tags_to_maildir_flags => true
319 * Rename message filename (s) to encode tags as maildir flags
322 notmuch_rb_message_tags_to_maildir_flags (VALUE self)
324 notmuch_status_t ret;
325 notmuch_message_t *message;
327 Data_Get_Notmuch_Message (self, message);
329 ret = notmuch_message_tags_to_maildir_flags (message);
330 notmuch_rb_status_raise (ret);
336 * call-seq: MESSAGE.freeze => true
338 * Freeze the 'message'
341 notmuch_rb_message_freeze (VALUE self)
343 notmuch_status_t ret;
344 notmuch_message_t *message;
346 Data_Get_Notmuch_Message (self, message);
348 ret = notmuch_message_freeze (message);
349 notmuch_rb_status_raise (ret);
355 * call-seq: MESSAGE.thaw => true
360 notmuch_rb_message_thaw (VALUE self)
362 notmuch_status_t ret;
363 notmuch_message_t *message;
365 Data_Get_Notmuch_Message (self, message);
367 ret = notmuch_message_thaw (message);
368 notmuch_rb_status_raise (ret);