]> git.notmuchmail.org Git - notmuch/blob - bindings/python-cffi/notmuch2/_build.py
lib: add new status code for query syntax errors.
[notmuch] / bindings / python-cffi / notmuch2 / _build.py
1 import cffi
2
3
4 ffibuilder = cffi.FFI()
5 ffibuilder.set_source(
6     'notmuch2._capi',
7     r"""
8     #include <stdlib.h>
9     #include <time.h>
10     #include <notmuch.h>
11
12     #if LIBNOTMUCH_MAJOR_VERSION < 5
13         #error libnotmuch version not supported by notmuch2 python bindings
14     #endif
15     #if LIBNOTMUCH_MINOR_VERSION < 1
16         #ERROR libnotmuch  version < 5.1 not supported
17     #endif
18     """,
19     include_dirs=['../../lib'],
20     library_dirs=['../../lib'],
21     libraries=['notmuch'],
22 )
23 ffibuilder.cdef(
24     r"""
25     void free(void *ptr);
26     typedef int... time_t;
27
28     #define LIBNOTMUCH_MAJOR_VERSION ...
29     #define LIBNOTMUCH_MINOR_VERSION ...
30     #define LIBNOTMUCH_MICRO_VERSION ...
31
32     #define NOTMUCH_TAG_MAX ...
33
34     typedef enum _notmuch_status {
35         NOTMUCH_STATUS_SUCCESS = 0,
36         NOTMUCH_STATUS_OUT_OF_MEMORY,
37         NOTMUCH_STATUS_READ_ONLY_DATABASE,
38         NOTMUCH_STATUS_XAPIAN_EXCEPTION,
39         NOTMUCH_STATUS_FILE_ERROR,
40         NOTMUCH_STATUS_FILE_NOT_EMAIL,
41         NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
42         NOTMUCH_STATUS_NULL_POINTER,
43         NOTMUCH_STATUS_TAG_TOO_LONG,
44         NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
45         NOTMUCH_STATUS_UNBALANCED_ATOMIC,
46         NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
47         NOTMUCH_STATUS_UPGRADE_REQUIRED,
48         NOTMUCH_STATUS_PATH_ERROR,
49         NOTMUCH_STATUS_ILLEGAL_ARGUMENT,
50         NOTMUCH_STATUS_MALFORMED_CRYPTO_PROTOCOL,
51         NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION,
52         NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL,
53         NOTMUCH_STATUS_NO_CONFIG,
54         NOTMUCH_STATUS_NO_DATABASE,
55         NOTMUCH_STATUS_DATABASE_EXISTS,
56         NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
57         NOTMUCH_STATUS_LAST_STATUS
58     } notmuch_status_t;
59     typedef enum {
60         NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
61         NOTMUCH_DATABASE_MODE_READ_WRITE
62     } notmuch_database_mode_t;
63     typedef int notmuch_bool_t;
64     typedef enum _notmuch_message_flag {
65         NOTMUCH_MESSAGE_FLAG_MATCH,
66         NOTMUCH_MESSAGE_FLAG_EXCLUDED,
67         NOTMUCH_MESSAGE_FLAG_GHOST,
68     } notmuch_message_flag_t;
69     typedef enum {
70         NOTMUCH_SORT_OLDEST_FIRST,
71         NOTMUCH_SORT_NEWEST_FIRST,
72         NOTMUCH_SORT_MESSAGE_ID,
73         NOTMUCH_SORT_UNSORTED
74     } notmuch_sort_t;
75     typedef enum {
76         NOTMUCH_EXCLUDE_FLAG,
77         NOTMUCH_EXCLUDE_TRUE,
78         NOTMUCH_EXCLUDE_FALSE,
79         NOTMUCH_EXCLUDE_ALL
80     } notmuch_exclude_t;
81     typedef enum {
82         NOTMUCH_DECRYPT_FALSE,
83         NOTMUCH_DECRYPT_TRUE,
84         NOTMUCH_DECRYPT_AUTO,
85         NOTMUCH_DECRYPT_NOSTASH,
86     } notmuch_decryption_policy_t;
87
88     // These are fully opaque types for us, we only ever use pointers.
89     typedef struct _notmuch_database notmuch_database_t;
90     typedef struct _notmuch_query notmuch_query_t;
91     typedef struct _notmuch_threads notmuch_threads_t;
92     typedef struct _notmuch_thread notmuch_thread_t;
93     typedef struct _notmuch_messages notmuch_messages_t;
94     typedef struct _notmuch_message notmuch_message_t;
95     typedef struct _notmuch_tags notmuch_tags_t;
96     typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
97     typedef struct _notmuch_directory notmuch_directory_t;
98     typedef struct _notmuch_filenames notmuch_filenames_t;
99     typedef struct _notmuch_config_list notmuch_config_list_t;
100     typedef struct _notmuch_indexopts notmuch_indexopts_t;
101
102     const char *
103     notmuch_status_to_string (notmuch_status_t status);
104
105     notmuch_status_t
106     notmuch_database_create_verbose (const char *path,
107                                      notmuch_database_t **database,
108                                      char **error_message);
109     notmuch_status_t
110     notmuch_database_create (const char *path, notmuch_database_t **database);
111     notmuch_status_t
112     notmuch_database_open_verbose (const char *path,
113                                    notmuch_database_mode_t mode,
114                                    notmuch_database_t **database,
115                                    char **error_message);
116     notmuch_status_t
117     notmuch_database_open (const char *path,
118                            notmuch_database_mode_t mode,
119                            notmuch_database_t **database);
120     notmuch_status_t
121     notmuch_database_close (notmuch_database_t *database);
122     notmuch_status_t
123     notmuch_database_destroy (notmuch_database_t *database);
124     const char *
125     notmuch_database_get_path (notmuch_database_t *database);
126     unsigned int
127     notmuch_database_get_version (notmuch_database_t *database);
128     notmuch_bool_t
129     notmuch_database_needs_upgrade (notmuch_database_t *database);
130     notmuch_status_t
131     notmuch_database_begin_atomic (notmuch_database_t *notmuch);
132     notmuch_status_t
133     notmuch_database_end_atomic (notmuch_database_t *notmuch);
134     unsigned long
135     notmuch_database_get_revision (notmuch_database_t *notmuch,
136                                    const char **uuid);
137     notmuch_status_t
138     notmuch_database_index_file (notmuch_database_t *database,
139                                  const char *filename,
140                                  notmuch_indexopts_t *indexopts,
141                                  notmuch_message_t **message);
142     notmuch_status_t
143     notmuch_database_remove_message (notmuch_database_t *database,
144                                      const char *filename);
145     notmuch_status_t
146     notmuch_database_find_message (notmuch_database_t *database,
147                                    const char *message_id,
148                                    notmuch_message_t **message);
149     notmuch_status_t
150     notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
151                                                const char *filename,
152                                                notmuch_message_t **message);
153     notmuch_tags_t *
154     notmuch_database_get_all_tags (notmuch_database_t *db);
155
156     notmuch_query_t *
157     notmuch_query_create (notmuch_database_t *database,
158                           const char *query_string);
159     const char *
160     notmuch_query_get_query_string (const notmuch_query_t *query);
161     notmuch_database_t *
162     notmuch_query_get_database (const notmuch_query_t *query);
163     void
164     notmuch_query_set_omit_excluded (notmuch_query_t *query,
165                                      notmuch_exclude_t omit_excluded);
166     void
167     notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
168     notmuch_sort_t
169     notmuch_query_get_sort (const notmuch_query_t *query);
170     notmuch_status_t
171     notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
172     notmuch_status_t
173     notmuch_query_search_threads (notmuch_query_t *query,
174                                   notmuch_threads_t **out);
175     notmuch_status_t
176     notmuch_query_search_messages (notmuch_query_t *query,
177                                    notmuch_messages_t **out);
178     notmuch_status_t
179     notmuch_query_count_messages (notmuch_query_t *query, unsigned int *count);
180     notmuch_status_t
181     notmuch_query_count_threads (notmuch_query_t *query, unsigned *count);
182     void
183     notmuch_query_destroy (notmuch_query_t *query);
184
185     notmuch_bool_t
186     notmuch_threads_valid (notmuch_threads_t *threads);
187     notmuch_thread_t *
188     notmuch_threads_get (notmuch_threads_t *threads);
189     void
190     notmuch_threads_move_to_next (notmuch_threads_t *threads);
191     void
192     notmuch_threads_destroy (notmuch_threads_t *threads);
193
194     const char *
195     notmuch_thread_get_thread_id (notmuch_thread_t *thread);
196     notmuch_messages_t *
197     notmuch_message_get_replies (notmuch_message_t *message);
198     int
199     notmuch_thread_get_total_messages (notmuch_thread_t *thread);
200     notmuch_messages_t *
201     notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
202     notmuch_messages_t *
203     notmuch_thread_get_messages (notmuch_thread_t *thread);
204     int
205     notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
206     const char *
207     notmuch_thread_get_authors (notmuch_thread_t *thread);
208     const char *
209     notmuch_thread_get_subject (notmuch_thread_t *thread);
210     time_t
211     notmuch_thread_get_oldest_date (notmuch_thread_t *thread);
212     time_t
213     notmuch_thread_get_newest_date (notmuch_thread_t *thread);
214     notmuch_tags_t *
215     notmuch_thread_get_tags (notmuch_thread_t *thread);
216     void
217     notmuch_thread_destroy (notmuch_thread_t *thread);
218
219     notmuch_bool_t
220     notmuch_messages_valid (notmuch_messages_t *messages);
221     notmuch_message_t *
222     notmuch_messages_get (notmuch_messages_t *messages);
223     void
224     notmuch_messages_move_to_next (notmuch_messages_t *messages);
225     void
226     notmuch_messages_destroy (notmuch_messages_t *messages);
227     notmuch_tags_t *
228     notmuch_messages_collect_tags (notmuch_messages_t *messages);
229
230     const char *
231     notmuch_message_get_message_id (notmuch_message_t *message);
232     const char *
233     notmuch_message_get_thread_id (notmuch_message_t *message);
234     const char *
235     notmuch_message_get_filename (notmuch_message_t *message);
236     notmuch_filenames_t *
237     notmuch_message_get_filenames (notmuch_message_t *message);
238     notmuch_bool_t
239     notmuch_message_get_flag (notmuch_message_t *message,
240                               notmuch_message_flag_t flag);
241     void
242     notmuch_message_set_flag (notmuch_message_t *message,
243                               notmuch_message_flag_t flag,
244                               notmuch_bool_t value);
245     time_t
246     notmuch_message_get_date  (notmuch_message_t *message);
247     const char *
248     notmuch_message_get_header (notmuch_message_t *message,
249                                 const char *header);
250     notmuch_tags_t *
251     notmuch_message_get_tags (notmuch_message_t *message);
252     notmuch_status_t
253     notmuch_message_add_tag (notmuch_message_t *message, const char *tag);
254     notmuch_status_t
255     notmuch_message_remove_tag (notmuch_message_t *message, const char *tag);
256     notmuch_status_t
257     notmuch_message_remove_all_tags (notmuch_message_t *message);
258     notmuch_status_t
259     notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
260     notmuch_status_t
261     notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
262     notmuch_status_t
263     notmuch_message_freeze (notmuch_message_t *message);
264     notmuch_status_t
265     notmuch_message_thaw (notmuch_message_t *message);
266     notmuch_status_t
267     notmuch_message_get_property (notmuch_message_t *message,
268                                   const char *key, const char **value);
269     notmuch_status_t
270     notmuch_message_add_property (notmuch_message_t *message,
271                                   const char *key, const char *value);
272     notmuch_status_t
273     notmuch_message_remove_property (notmuch_message_t *message,
274                                      const char *key, const char *value);
275     notmuch_status_t
276     notmuch_message_remove_all_properties (notmuch_message_t *message,
277                                            const char *key);
278     notmuch_message_properties_t *
279     notmuch_message_get_properties (notmuch_message_t *message,
280                                     const char *key, notmuch_bool_t exact);
281     notmuch_bool_t
282     notmuch_message_properties_valid (notmuch_message_properties_t
283                                           *properties);
284     void
285     notmuch_message_properties_move_to_next (notmuch_message_properties_t
286                                                  *properties);
287     const char *
288     notmuch_message_properties_key (notmuch_message_properties_t *properties);
289     const char *
290     notmuch_message_properties_value (notmuch_message_properties_t
291                                           *properties);
292     void
293     notmuch_message_properties_destroy (notmuch_message_properties_t
294                                             *properties);
295     void
296     notmuch_message_destroy (notmuch_message_t *message);
297
298     notmuch_bool_t
299     notmuch_tags_valid (notmuch_tags_t *tags);
300     const char *
301     notmuch_tags_get (notmuch_tags_t *tags);
302     void
303     notmuch_tags_move_to_next (notmuch_tags_t *tags);
304     void
305     notmuch_tags_destroy (notmuch_tags_t *tags);
306
307     notmuch_bool_t
308     notmuch_filenames_valid (notmuch_filenames_t *filenames);
309     const char *
310     notmuch_filenames_get (notmuch_filenames_t *filenames);
311     void
312     notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
313     void
314     notmuch_filenames_destroy (notmuch_filenames_t *filenames);
315     notmuch_indexopts_t *
316     notmuch_database_get_default_indexopts (notmuch_database_t *db);
317     notmuch_status_t
318     notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
319                                           notmuch_decryption_policy_t decrypt_policy);
320     notmuch_decryption_policy_t
321     notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts);
322     void
323     notmuch_indexopts_destroy (notmuch_indexopts_t *options);
324
325     notmuch_status_t
326     notmuch_database_set_config (notmuch_database_t *db, const char *key, const char *value);
327     notmuch_status_t
328     notmuch_database_get_config (notmuch_database_t *db, const char *key, char **value);
329     notmuch_status_t
330     notmuch_database_get_config_list (notmuch_database_t *db, const char *prefix, notmuch_config_list_t **out);
331     notmuch_bool_t
332     notmuch_config_list_valid (notmuch_config_list_t *config_list);
333     const char *
334     notmuch_config_list_key (notmuch_config_list_t *config_list);
335     const char *
336     notmuch_config_list_value (notmuch_config_list_t *config_list);
337     void
338     notmuch_config_list_move_to_next (notmuch_config_list_t *config_list);
339     void
340     notmuch_config_list_destroy (notmuch_config_list_t *config_list);
341     """
342 )
343
344
345 if __name__ == '__main__':
346     ffibuilder.compile(verbose=True)