]> git.notmuchmail.org Git - notmuch/blob - bindings/ruby/messages.c
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / bindings / ruby / messages.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: MESSAGES.destroy! => nil
25  *
26  * Destroys the messages, freeing all resources allocated for it.
27  */
28 VALUE
29 notmuch_rb_messages_destroy (VALUE self)
30 {
31     notmuch_rb_object_destroy (self, &notmuch_rb_messages_type);
32
33     return Qnil;
34 }
35
36 /* call-seq: MESSAGES.each {|item| block } => MESSAGES
37  *
38  * Calls +block+ once for each message in +self+, passing that element as a
39  * parameter.
40  */
41 VALUE
42 notmuch_rb_messages_each (VALUE self)
43 {
44     notmuch_message_t *message;
45     notmuch_messages_t *messages;
46
47     Data_Get_Notmuch_Messages (self, messages);
48
49     for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) {
50         message = notmuch_messages_get (messages);
51         rb_yield (Data_Wrap_Notmuch_Object (notmuch_rb_cMessage, &notmuch_rb_message_type, message));
52     }
53
54     return self;
55 }
56
57 /*
58  * call-seq: MESSAGES.tags => TAGS
59  *
60  * Collect tags from the messages
61  */
62 VALUE
63 notmuch_rb_messages_collect_tags (VALUE self)
64 {
65     notmuch_tags_t *tags;
66     notmuch_messages_t *messages;
67
68     Data_Get_Notmuch_Messages (self, messages);
69
70     tags = notmuch_messages_collect_tags (messages);
71     if (!tags)
72         rb_raise (notmuch_rb_eMemoryError, "Out of memory");
73
74     return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, &notmuch_rb_tags_type, tags);
75 }