import cffi ffibuilder = cffi.FFI() ffibuilder.set_source( 'notdb._capi', r""" #include #include """, libraries=['notmuch'], ) ffibuilder.cdef( r""" void free(void *ptr); #define NOTMUCH_TAG_MAX ... typedef enum _notmuch_status { NOTMUCH_STATUS_SUCCESS = 0, NOTMUCH_STATUS_OUT_OF_MEMORY, NOTMUCH_STATUS_READ_ONLY_DATABASE, NOTMUCH_STATUS_XAPIAN_EXCEPTION, NOTMUCH_STATUS_FILE_ERROR, NOTMUCH_STATUS_FILE_NOT_EMAIL, NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID, NOTMUCH_STATUS_NULL_POINTER, NOTMUCH_STATUS_TAG_TOO_LONG, NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW, NOTMUCH_STATUS_UNBALANCED_ATOMIC, NOTMUCH_STATUS_UNSUPPORTED_OPERATION, NOTMUCH_STATUS_UPGRADE_REQUIRED, NOTMUCH_STATUS_PATH_ERROR, NOTMUCH_STATUS_ILLEGAL_ARGUMENT, NOTMUCH_STATUS_LAST_STATUS } notmuch_status_t; typedef enum { NOTMUCH_DATABASE_MODE_READ_ONLY = 0, NOTMUCH_DATABASE_MODE_READ_WRITE } notmuch_database_mode_t; typedef int notmuch_bool_t; // These are fully opaque types for us, we only ever use pointers. typedef struct _notmuch_database notmuch_database_t; typedef struct _notmuch_query notmuch_query_t; typedef struct _notmuch_threads notmuch_threads_t; typedef struct _notmuch_thread notmuch_thread_t; typedef struct _notmuch_messages notmuch_messages_t; typedef struct _notmuch_message notmuch_message_t; typedef struct _notmuch_tags notmuch_tags_t; typedef struct _notmuch_directory notmuch_directory_t; typedef struct _notmuch_filenames notmuch_filenames_t; typedef struct _notmuch_config_list notmuch_config_list_t; const char * notmuch_status_to_string (notmuch_status_t status); notmuch_status_t notmuch_database_create_verbose (const char *path, notmuch_database_t **database, char **error_message); notmuch_status_t notmuch_database_create (const char *path, notmuch_database_t **database); notmuch_status_t notmuch_database_open_verbose (const char *path, notmuch_database_mode_t mode, notmuch_database_t **database, char **error_message); notmuch_status_t notmuch_database_open (const char *path, notmuch_database_mode_t mode, notmuch_database_t **database); notmuch_status_t notmuch_database_close (notmuch_database_t *database); notmuch_status_t notmuch_database_destroy (notmuch_database_t *database); const char * notmuch_database_get_path (notmuch_database_t *database); unsigned int notmuch_database_get_version (notmuch_database_t *database); notmuch_bool_t notmuch_database_needs_upgrade (notmuch_database_t *database); notmuch_status_t notmuch_database_begin_atomic (notmuch_database_t *notmuch); notmuch_status_t notmuch_database_end_atomic (notmuch_database_t *notmuch); unsigned long notmuch_database_get_revision (notmuch_database_t *notmuch, const char **uuid); notmuch_status_t notmuch_database_add_message (notmuch_database_t *database, const char *filename, notmuch_message_t **message); notmuch_status_t notmuch_database_remove_message (notmuch_database_t *database, const char *filename); notmuch_status_t notmuch_database_find_message (notmuch_database_t *database, const char *message_id, notmuch_message_t **message); notmuch_status_t notmuch_database_find_message_by_filename (notmuch_database_t *notmuch, const char *filename, notmuch_message_t **message); notmuch_tags_t * notmuch_database_get_all_tags (notmuch_database_t *db); const char * notmuch_message_get_message_id (notmuch_message_t *message); const char * notmuch_message_get_filename (notmuch_message_t *message); notmuch_tags_t * notmuch_message_get_tags (notmuch_message_t *message); notmuch_status_t notmuch_message_add_tag (notmuch_message_t *message, const char *tag); notmuch_status_t notmuch_message_remove_tag (notmuch_message_t *message, const char *tag); notmuch_status_t notmuch_message_remove_all_tags (notmuch_message_t *message); notmuch_status_t notmuch_message_maildir_flags_to_tags (notmuch_message_t *message); notmuch_status_t notmuch_message_tags_to_maildir_flags (notmuch_message_t *message); void notmuch_message_destroy (notmuch_message_t *message); notmuch_bool_t notmuch_tags_valid (notmuch_tags_t *tags); const char * notmuch_tags_get (notmuch_tags_t *tags); void notmuch_tags_move_to_next (notmuch_tags_t *tags); void notmuch_tags_destroy (notmuch_tags_t *tags); """ ) if __name__ == '__main__': ffibuilder.compile(verbose=True)