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>
28 extern VALUE notmuch_rb_cDatabase;
29 extern VALUE notmuch_rb_cDirectory;
30 extern VALUE notmuch_rb_cFileNames;
31 extern VALUE notmuch_rb_cQuery;
32 extern VALUE notmuch_rb_cThreads;
33 extern VALUE notmuch_rb_cThread;
34 extern VALUE notmuch_rb_cMessages;
35 extern VALUE notmuch_rb_cMessage;
37 extern VALUE notmuch_rb_eBaseError;
38 extern VALUE notmuch_rb_eDatabaseError;
39 extern VALUE notmuch_rb_eMemoryError;
40 extern VALUE notmuch_rb_eReadOnlyError;
41 extern VALUE notmuch_rb_eXapianError;
42 extern VALUE notmuch_rb_eFileError;
43 extern VALUE notmuch_rb_eFileNotEmailError;
44 extern VALUE notmuch_rb_eNullPointerError;
45 extern VALUE notmuch_rb_eTagTooLongError;
46 extern VALUE notmuch_rb_eUnbalancedFreezeThawError;
47 extern VALUE notmuch_rb_eUnbalancedAtomicError;
50 extern ID ID_db_create;
53 /* RSTRING_PTR() is new in ruby-1.9 */
54 #if !defined(RSTRING_PTR)
55 # define RSTRING_PTR(v) (RSTRING((v))->ptr)
56 #endif /* !defined (RSTRING_PTR) */
58 extern const rb_data_type_t notmuch_rb_object_type;
59 extern const rb_data_type_t notmuch_rb_database_type;
60 extern const rb_data_type_t notmuch_rb_directory_type;
61 extern const rb_data_type_t notmuch_rb_filenames_type;
62 extern const rb_data_type_t notmuch_rb_query_type;
63 extern const rb_data_type_t notmuch_rb_threads_type;
64 extern const rb_data_type_t notmuch_rb_thread_type;
65 extern const rb_data_type_t notmuch_rb_messages_type;
66 extern const rb_data_type_t notmuch_rb_message_type;
67 extern const rb_data_type_t notmuch_rb_tags_type;
69 #define Data_Get_Notmuch_Rb_Object(obj, type, ptr) \
71 (ptr) = rb_check_typeddata ((obj), (type)); \
72 if (RB_UNLIKELY (!(ptr))) { \
73 VALUE cname = rb_class_name (CLASS_OF ((obj))); \
74 rb_raise (rb_eRuntimeError, "%"PRIsVALUE" object destroyed", cname); \
78 #define Data_Get_Notmuch_Object(obj, type, ptr) \
80 notmuch_rb_object_t *rb_wrapper; \
81 Data_Get_Notmuch_Rb_Object ((obj), (type), rb_wrapper); \
82 (ptr) = rb_wrapper->nm_object; \
85 #define Data_Wrap_Notmuch_Object(klass, type, ptr) \
86 TypedData_Wrap_Struct ((klass), (type), notmuch_rb_object_create ((ptr), "notmuch_rb_object: " __location__))
88 #define Data_Get_Notmuch_Database(obj, ptr) \
89 Data_Get_Notmuch_Object ((obj), ¬much_rb_database_type, (ptr))
91 #define Data_Get_Notmuch_Directory(obj, ptr) \
92 Data_Get_Notmuch_Object ((obj), ¬much_rb_directory_type, (ptr))
94 #define Data_Get_Notmuch_FileNames(obj, ptr) \
95 Data_Get_Notmuch_Object ((obj), ¬much_rb_filenames_type, (ptr))
97 #define Data_Get_Notmuch_Query(obj, ptr) \
98 Data_Get_Notmuch_Object ((obj), ¬much_rb_query_type, (ptr))
100 #define Data_Get_Notmuch_Threads(obj, ptr) \
101 Data_Get_Notmuch_Object ((obj), ¬much_rb_threads_type, (ptr))
103 #define Data_Get_Notmuch_Messages(obj, ptr) \
104 Data_Get_Notmuch_Object ((obj), ¬much_rb_messages_type, (ptr))
106 #define Data_Get_Notmuch_Thread(obj, ptr) \
107 Data_Get_Notmuch_Object ((obj), ¬much_rb_thread_type, (ptr))
109 #define Data_Get_Notmuch_Message(obj, ptr) \
110 Data_Get_Notmuch_Object ((obj), ¬much_rb_message_type, (ptr))
112 #define Data_Get_Notmuch_Tags(obj, ptr) \
113 Data_Get_Notmuch_Object ((obj), ¬much_rb_tags_type, (ptr))
117 } notmuch_rb_object_t;
120 notmuch_rb_object_create (void *nm_object, const char *name)
122 notmuch_rb_object_t *rb_wrapper = talloc_named_const (NULL, sizeof (*rb_wrapper), name);
124 if (RB_UNLIKELY (!rb_wrapper))
127 rb_wrapper->nm_object = nm_object;
128 talloc_steal (rb_wrapper, nm_object);
133 notmuch_rb_object_free (void *rb_wrapper)
135 talloc_free (rb_wrapper);
139 notmuch_rb_object_destroy (VALUE rb_object, const rb_data_type_t *type)
141 notmuch_rb_object_t *rb_wrapper;
143 Data_Get_Notmuch_Rb_Object (rb_object, type, rb_wrapper);
145 /* Call the corresponding notmuch_*_destroy function */
146 ((void (*)(void *)) type->data) (rb_wrapper->nm_object);
147 notmuch_rb_object_free (rb_wrapper);
148 DATA_PTR (rb_object) = NULL;
153 notmuch_rb_status_raise (notmuch_status_t status);
157 notmuch_rb_database_alloc (VALUE klass);
160 notmuch_rb_database_destroy (VALUE self);
163 notmuch_rb_database_initialize (int argc, VALUE *argv, VALUE klass);
166 notmuch_rb_database_open (int argc, VALUE *argv, VALUE klass);
169 notmuch_rb_database_close (VALUE self);
172 notmuch_rb_database_path (VALUE self);
175 notmuch_rb_database_version (VALUE self);
178 notmuch_rb_database_needs_upgrade (VALUE self);
181 notmuch_rb_database_upgrade (VALUE self);
184 notmuch_rb_database_begin_atomic (VALUE self);
187 notmuch_rb_database_end_atomic (VALUE self);
190 notmuch_rb_database_get_directory (VALUE self, VALUE pathv);
193 notmuch_rb_database_add_message (VALUE self, VALUE pathv);
196 notmuch_rb_database_remove_message (VALUE self, VALUE pathv);
199 notmuch_rb_database_find_message (VALUE self, VALUE idv);
202 notmuch_rb_database_find_message_by_filename (VALUE self, VALUE pathv);
205 notmuch_rb_database_get_all_tags (VALUE self);
208 notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
212 notmuch_rb_directory_destroy (VALUE self);
215 notmuch_rb_directory_get_mtime (VALUE self);
218 notmuch_rb_directory_set_mtime (VALUE self, VALUE mtimev);
221 notmuch_rb_directory_get_child_files (VALUE self);
224 notmuch_rb_directory_get_child_directories (VALUE self);
228 notmuch_rb_filenames_get (notmuch_filenames_t *fnames);
231 notmuch_rb_filenames_destroy (VALUE self);
234 notmuch_rb_filenames_each (VALUE self);
238 notmuch_rb_query_destroy (VALUE self);
241 notmuch_rb_query_get_sort (VALUE self);
244 notmuch_rb_query_set_sort (VALUE self, VALUE sortv);
247 notmuch_rb_query_get_string (VALUE self);
250 notmuch_rb_query_add_tag_exclude (VALUE self, VALUE tagv);
253 notmuch_rb_query_set_omit_excluded (VALUE self, VALUE omitv);
256 notmuch_rb_query_search_threads (VALUE self);
259 notmuch_rb_query_search_messages (VALUE self);
262 notmuch_rb_query_count_messages (VALUE self);
265 notmuch_rb_query_count_threads (VALUE self);
269 notmuch_rb_threads_destroy (VALUE self);
272 notmuch_rb_threads_each (VALUE self);
276 notmuch_rb_messages_destroy (VALUE self);
279 notmuch_rb_messages_each (VALUE self);
282 notmuch_rb_messages_collect_tags (VALUE self);
286 notmuch_rb_thread_destroy (VALUE self);
289 notmuch_rb_thread_get_thread_id (VALUE self);
292 notmuch_rb_thread_get_total_messages (VALUE self);
295 notmuch_rb_thread_get_toplevel_messages (VALUE self);
298 notmuch_rb_thread_get_messages (VALUE self);
301 notmuch_rb_thread_get_matched_messages (VALUE self);
304 notmuch_rb_thread_get_authors (VALUE self);
307 notmuch_rb_thread_get_subject (VALUE self);
310 notmuch_rb_thread_get_oldest_date (VALUE self);
313 notmuch_rb_thread_get_newest_date (VALUE self);
316 notmuch_rb_thread_get_tags (VALUE self);
320 notmuch_rb_message_destroy (VALUE self);
323 notmuch_rb_message_get_message_id (VALUE self);
326 notmuch_rb_message_get_thread_id (VALUE self);
329 notmuch_rb_message_get_replies (VALUE self);
332 notmuch_rb_message_get_filename (VALUE self);
335 notmuch_rb_message_get_filenames (VALUE self);
338 notmuch_rb_message_get_flag (VALUE self, VALUE flagv);
341 notmuch_rb_message_set_flag (VALUE self, VALUE flagv, VALUE valuev);
344 notmuch_rb_message_get_date (VALUE self);
347 notmuch_rb_message_get_header (VALUE self, VALUE headerv);
350 notmuch_rb_message_get_tags (VALUE self);
353 notmuch_rb_message_add_tag (VALUE self, VALUE tagv);
356 notmuch_rb_message_remove_tag (VALUE self, VALUE tagv);
359 notmuch_rb_message_remove_all_tags (VALUE self);
362 notmuch_rb_message_maildir_flags_to_tags (VALUE self);
365 notmuch_rb_message_tags_to_maildir_flags (VALUE self);
368 notmuch_rb_message_freeze (VALUE self);
371 notmuch_rb_message_thaw (VALUE self);
375 notmuch_rb_tags_get (notmuch_tags_t *tags);