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