1 /* The Ruby interface to the notmuch mail library
3 * Copyright © 2010, 2011, 2012 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: QUERY.destroy! => nil
26 * Destroys the query, freeing all resources allocated for it.
29 notmuch_rb_query_destroy (VALUE self)
31 notmuch_rb_object_destroy (self, ¬much_rb_query_type);
37 * call-seq: QUERY.sort => fixnum
39 * Get sort type of the +QUERY+
42 notmuch_rb_query_get_sort (VALUE self)
44 notmuch_query_t *query;
46 Data_Get_Notmuch_Query (self, query);
48 return INT2FIX (notmuch_query_get_sort (query));
52 * call-seq: QUERY.sort=(fixnum) => nil
54 * Set sort type of the +QUERY+
57 notmuch_rb_query_set_sort (VALUE self, VALUE sortv)
59 notmuch_query_t *query;
61 Data_Get_Notmuch_Query (self, query);
63 if (!FIXNUM_P (sortv))
64 rb_raise (rb_eTypeError, "Not a Fixnum");
66 notmuch_query_set_sort (query, FIX2UINT (sortv));
72 * call-seq: QUERY.to_s => string
74 * Get query string of the +QUERY+
77 notmuch_rb_query_get_string (VALUE self)
79 notmuch_query_t *query;
81 Data_Get_Notmuch_Query (self, query);
83 return rb_str_new2 (notmuch_query_get_query_string (query));
87 * call-seq: QUERY.add_tag_exclude(tag) => nil
89 * Add a tag that will be excluded from the query results by default.
92 notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv)
94 notmuch_query_t *query;
97 Data_Get_Notmuch_Query (self, query);
98 tag = RSTRING_PTR(tagv);
100 notmuch_query_add_tag_exclude(query, tag);
105 * call-seq: QUERY.omit_excluded=(fixnum) => nil
107 * Specify whether to omit excluded results or simply flag them.
108 * By default, this is set to +Notmuch::EXCLUDE_TRUE+.
111 notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv)
113 notmuch_query_t *query;
114 notmuch_exclude_t value;
116 Data_Get_Notmuch_Query (self, query);
118 value = FIXNUM_P (omitv) ? FIX2UINT (omitv) : RTEST(omitv);
119 notmuch_query_set_omit_excluded (query, value);
125 * call-seq: QUERY.search_threads => THREADS
130 notmuch_rb_query_search_threads (VALUE self)
132 notmuch_query_t *query;
133 notmuch_threads_t *threads;
134 notmuch_status_t status;
136 Data_Get_Notmuch_Query (self, query);
138 status = notmuch_query_search_threads (query, &threads);
140 notmuch_rb_status_raise (status);
142 return Data_Wrap_Notmuch_Object (notmuch_rb_cThreads, ¬much_rb_threads_type, threads);
146 * call-seq: QUERY.search_messages => MESSAGES
148 * Search for messages
151 notmuch_rb_query_search_messages (VALUE self)
153 notmuch_query_t *query;
154 notmuch_messages_t *messages;
155 notmuch_status_t status;
157 Data_Get_Notmuch_Query (self, query);
159 status = notmuch_query_search_messages (query, &messages);
161 notmuch_rb_status_raise (status);
163 return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, ¬much_rb_messages_type, messages);
167 * call-seq: QUERY.count_messages => Fixnum
169 * Return an estimate of the number of messages matching a search
172 notmuch_rb_query_count_messages (VALUE self)
174 notmuch_query_t *query;
175 notmuch_status_t status;
178 Data_Get_Notmuch_Query (self, query);
180 status = notmuch_query_count_messages (query, &count);
182 notmuch_rb_status_raise (status);
184 return UINT2NUM(count);
188 * call-seq: QUERY.count_threads => Fixnum
190 * Return an estimate of the number of threads matching a search
193 notmuch_rb_query_count_threads (VALUE self)
195 notmuch_query_t *query;
196 notmuch_status_t status;
199 Data_Get_Notmuch_Query (self, query);
201 status = notmuch_query_count_threads (query, &count);
203 notmuch_rb_status_raise (status);
205 return UINT2NUM(count);