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