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 FIX2INT (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=(boolean) => nil
107 * Specify whether to omit excluded results or simply flag them.
108 * By default, this is set to +true+.
111 notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv)
113 notmuch_query_t *query;
115 Data_Get_Notmuch_Query (self, query);
117 notmuch_query_set_omit_excluded (query, RTEST (omitv));
123 * call-seq: QUERY.search_threads => THREADS
128 notmuch_rb_query_search_threads (VALUE self)
130 notmuch_query_t *query;
131 notmuch_threads_t *threads;
132 notmuch_status_t status;
134 Data_Get_Notmuch_Query (self, query);
136 status = notmuch_query_search_threads (query, &threads);
138 notmuch_rb_status_raise (status);
140 return Data_Wrap_Notmuch_Object (notmuch_rb_cThreads, ¬much_rb_threads_type, threads);
144 * call-seq: QUERY.search_messages => MESSAGES
146 * Search for messages
149 notmuch_rb_query_search_messages (VALUE self)
151 notmuch_query_t *query;
152 notmuch_messages_t *messages;
153 notmuch_status_t status;
155 Data_Get_Notmuch_Query (self, query);
157 status = notmuch_query_search_messages (query, &messages);
159 notmuch_rb_status_raise (status);
161 return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, ¬much_rb_messages_type, messages);
165 * call-seq: QUERY.count_messages => Fixnum
167 * Return an estimate of the number of messages matching a search
170 notmuch_rb_query_count_messages (VALUE self)
172 notmuch_query_t *query;
173 notmuch_status_t status;
176 Data_Get_Notmuch_Query (self, query);
178 status = notmuch_query_count_messages (query, &count);
180 notmuch_rb_status_raise (status);
182 return UINT2NUM(count);
186 * call-seq: QUERY.count_threads => Fixnum
188 * Return an estimate of the number of threads matching a search
191 notmuch_rb_query_count_threads (VALUE self)
193 notmuch_query_t *query;
194 notmuch_status_t status;
197 Data_Get_Notmuch_Query (self, query);
199 status = notmuch_query_count_threads (query, &count);
201 notmuch_rb_status_raise (status);
203 return UINT2NUM(count);