1 /* notmuch - Not much of an email library, (just index and search)
3 * Copyright © 2009 Carl Worth
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: Carl Worth <cworth@cworth.org>
22 * @defgroup notmuch The notmuch API
24 * Not much of an email library, (just index and search)
35 # define NOTMUCH_BEGIN_DECLS extern "C" {
36 # define NOTMUCH_END_DECLS }
38 # define NOTMUCH_BEGIN_DECLS
39 # define NOTMUCH_END_DECLS
46 #pragma GCC visibility push(default)
57 * The library version number. This must agree with the soname
58 * version in Makefile.local.
60 #define LIBNOTMUCH_MAJOR_VERSION 5
61 #define LIBNOTMUCH_MINOR_VERSION 6
62 #define LIBNOTMUCH_MICRO_VERSION 0
65 #if defined (__clang_major__) && __clang_major__ >= 3 \
66 || defined (__GNUC__) && __GNUC__ >= 5 \
67 || defined (__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 5
68 #define NOTMUCH_DEPRECATED(major, minor) \
69 __attribute__ ((deprecated ("function deprecated as of libnotmuch " #major "." #minor)))
71 #define NOTMUCH_DEPRECATED(major, minor) __attribute__ ((deprecated))
75 #endif /* __DOXYGEN__ */
78 * Check the version of the notmuch library being compiled against.
80 * Return true if the library being compiled against is of the
81 * specified version or above. For example:
84 * #if LIBNOTMUCH_CHECK_VERSION(3, 1, 0)
85 * (code requiring libnotmuch 3.1.0 or above)
89 * LIBNOTMUCH_CHECK_VERSION has been defined since version 3.1.0; to
90 * check for versions prior to that, use:
93 * #if !defined(NOTMUCH_CHECK_VERSION)
94 * (code requiring libnotmuch prior to 3.1.0)
98 #define LIBNOTMUCH_CHECK_VERSION(major, minor, micro) \
99 (LIBNOTMUCH_MAJOR_VERSION > (major) || \
100 (LIBNOTMUCH_MAJOR_VERSION == (major) && LIBNOTMUCH_MINOR_VERSION > (minor)) || \
101 (LIBNOTMUCH_MAJOR_VERSION == (major) && LIBNOTMUCH_MINOR_VERSION == (minor) && \
102 LIBNOTMUCH_MICRO_VERSION >= (micro)))
105 * Notmuch boolean type.
107 typedef int notmuch_bool_t;
110 * Status codes used for the return values of most functions.
112 * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
113 * completed without error. Any other value indicates an error.
119 NOTMUCH_STATUS_SUCCESS = 0,
123 NOTMUCH_STATUS_OUT_OF_MEMORY,
125 * An attempt was made to write to a database opened in read-only
128 NOTMUCH_STATUS_READ_ONLY_DATABASE,
130 * A Xapian exception occurred.
132 * @todo We don't really want to expose this lame XAPIAN_EXCEPTION
133 * value. Instead we should map to things like DATABASE_LOCKED or
136 NOTMUCH_STATUS_XAPIAN_EXCEPTION,
138 * An error occurred trying to read or write to a file (this could
139 * be file not found, permission denied, etc.)
141 NOTMUCH_STATUS_FILE_ERROR,
143 * A file was presented that doesn't appear to be an email
146 NOTMUCH_STATUS_FILE_NOT_EMAIL,
148 * A file contains a message ID that is identical to a message
149 * already in the database.
151 NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
153 * The user erroneously passed a NULL pointer to a notmuch
156 NOTMUCH_STATUS_NULL_POINTER,
158 * A tag value is too long (exceeds NOTMUCH_TAG_MAX).
160 NOTMUCH_STATUS_TAG_TOO_LONG,
162 * The notmuch_message_thaw function has been called more times
163 * than notmuch_message_freeze.
165 NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
167 * notmuch_database_end_atomic has been called more times than
168 * notmuch_database_begin_atomic.
170 NOTMUCH_STATUS_UNBALANCED_ATOMIC,
172 * The operation is not supported.
174 NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
176 * The operation requires a database upgrade.
178 NOTMUCH_STATUS_UPGRADE_REQUIRED,
180 * There is a problem with the proposed path, e.g. a relative path
181 * passed to a function expecting an absolute path.
183 NOTMUCH_STATUS_PATH_ERROR,
185 * The requested operation was ignored. Depending on the function,
186 * this may not be an actual error.
188 NOTMUCH_STATUS_IGNORED,
190 * One of the arguments violates the preconditions for the
191 * function, in a way not covered by a more specific argument.
193 NOTMUCH_STATUS_ILLEGAL_ARGUMENT,
195 * A MIME object claimed to have cryptographic protection which
196 * notmuch tried to handle, but the protocol was not specified in
197 * an intelligible way.
199 NOTMUCH_STATUS_MALFORMED_CRYPTO_PROTOCOL,
201 * Notmuch attempted to do crypto processing, but could not
202 * initialize the engine needed to do so.
204 NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION,
206 * A MIME object claimed to have cryptographic protection, and
207 * notmuch attempted to process it, but the specific protocol was
208 * something that notmuch doesn't know how to handle.
210 NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL,
212 * Unable to load a config file
214 NOTMUCH_STATUS_NO_CONFIG,
216 * Unable to load a database
218 NOTMUCH_STATUS_NO_DATABASE,
220 * Database exists, so not (re)-created
222 NOTMUCH_STATUS_DATABASE_EXISTS,
224 * Syntax error in query
226 NOTMUCH_STATUS_BAD_QUERY_SYNTAX,
228 * No mail root could be deduced from parameters and environment
230 NOTMUCH_STATUS_NO_MAIL_ROOT,
232 * Database is not fully opened, or has been closed
234 NOTMUCH_STATUS_CLOSED_DATABASE,
236 * The iterator being examined has been exhausted and contains no more
239 NOTMUCH_STATUS_ITERATOR_EXHAUSTED,
241 * An operation that was being performed on the database has been
242 * invalidated while in progress, and must be re-executed.
244 * This will typically happen while iterating over query results and the
245 * underlying Xapian database is modified by another process so that the
246 * currently open version cannot be read anymore.
248 NOTMUCH_STATUS_OPERATION_INVALIDATED,
250 * Not an actual status value. Just a way to find out how many
251 * valid status values there are.
253 NOTMUCH_STATUS_LAST_STATUS
257 * Get a string representation of a notmuch_status_t value.
259 * The result is read-only.
262 notmuch_status_to_string (notmuch_status_t status);
264 /* Various opaque data types. For each notmuch_<foo>_t see the various
265 * notmuch_<foo> functions below. */
267 typedef struct _notmuch_database notmuch_database_t;
268 typedef struct _notmuch_query notmuch_query_t;
269 typedef struct _notmuch_threads notmuch_threads_t;
270 typedef struct _notmuch_thread notmuch_thread_t;
271 typedef struct _notmuch_messages notmuch_messages_t;
272 typedef struct _notmuch_message notmuch_message_t;
273 typedef struct _notmuch_tags notmuch_tags_t;
274 typedef struct _notmuch_directory notmuch_directory_t;
275 typedef struct _notmuch_filenames notmuch_filenames_t;
276 typedef struct _notmuch_config_list notmuch_config_list_t;
277 typedef struct _notmuch_config_values notmuch_config_values_t;
278 typedef struct _notmuch_config_pairs notmuch_config_pairs_t;
279 typedef struct _notmuch_indexopts notmuch_indexopts_t;
280 #endif /* __DOXYGEN__ */
283 * Create a new, empty notmuch database located at 'path'.
285 * The path should be a top-level directory to a collection of
286 * plain-text email messages (one message per file). This call will
287 * create a new ".notmuch" directory within 'path' where notmuch will
290 * After a successful call to notmuch_database_create, the returned
291 * database will be open so the caller should call
292 * notmuch_database_destroy when finished with it.
294 * The database will not yet have any data in it
295 * (notmuch_database_create itself is a very cheap function). Messages
296 * contained within 'path' can be added to the database by calling
297 * notmuch_database_index_file.
299 * In case of any failure, this function returns an error status and
300 * sets *database to NULL (after printing an error message on stderr).
304 * NOTMUCH_STATUS_SUCCESS: Successfully created the database.
306 * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.
308 * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
310 * NOTMUCH_STATUS_PATH_ERROR: filename is too long
312 * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the
313 * database file (such as permission denied, or file not found,
314 * etc.), or the database already exists.
316 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
319 notmuch_database_create (const char *path, notmuch_database_t **database);
322 * Like notmuch_database_create, except optionally return an error
323 * message. This message is allocated by malloc and should be freed by
327 notmuch_database_create_verbose (const char *path,
328 notmuch_database_t **database,
329 char **error_message);
332 * Database open mode for notmuch_database_open.
336 * Open database for reading only.
338 NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
340 * Open database for reading and writing.
342 NOTMUCH_DATABASE_MODE_READ_WRITE
343 } notmuch_database_mode_t;
346 * Deprecated alias for notmuch_database_open_with_config with
347 * config_path="" and error_message=NULL
348 * @deprecated Deprecated as of libnotmuch 5.4 (notmuch 0.32)
350 NOTMUCH_DEPRECATED(5, 4)
352 notmuch_database_open (const char *path,
353 notmuch_database_mode_t mode,
354 notmuch_database_t **database);
356 * Deprecated alias for notmuch_database_open_with_config with
359 * @deprecated Deprecated as of libnotmuch 5.4 (notmuch 0.32)
362 NOTMUCH_DEPRECATED(5, 4)
364 notmuch_database_open_verbose (const char *path,
365 notmuch_database_mode_t mode,
366 notmuch_database_t **database,
367 char **error_message);
370 * Open an existing notmuch database located at 'database_path', using
371 * configuration in 'config_path'.
373 * @param[in] database_path
375 * Path to existing database.
377 * A notmuch database is a Xapian database containing appropriate
380 * The database should have been created at some time in the past,
381 * (not necessarily by this process), by calling
382 * notmuch_database_create.
384 * If 'database_path' is NULL, use the location specified
386 * - in the environment variable NOTMUCH_DATABASE, if non-empty
388 * - in a configuration file, located as described under 'config_path'
390 * - by $XDG_DATA_HOME/notmuch/$PROFILE where XDG_DATA_HOME defaults
391 * to "$HOME/.local/share" and PROFILE as as discussed in
394 * If 'database_path' is non-NULL, but does not appear to be a Xapian
395 * database, check for a directory '.notmuch/xapian' below
396 * 'database_path' (this is the behavior of
397 * notmuch_database_open_verbose pre-0.32).
402 * Mode to open database. Use one of #NOTMUCH_DATABASE_MODE_READ_WRITE
403 * or #NOTMUCH_DATABASE_MODE_READ_ONLY
406 * @param[in] config_path
408 * Path to config file.
410 * Config file is key-value, with mandatory sections. See
411 * <em>notmuch-config(5)</em> for more information. The key-value pair
412 * overrides the corresponding configuration data stored in the
413 * database (see <em>notmuch_database_get_config</em>)
415 * If <em>config_path</em> is NULL use the path specified
417 * - in environment variable <em>NOTMUCH_CONFIG</em>, if non-empty
419 * - by <em>XDG_CONFIG_HOME</em>/notmuch/ where
420 * XDG_CONFIG_HOME defaults to "$HOME/.config".
422 * - by $HOME/.notmuch-config
424 * If <em>config_path</em> is "" (empty string) then do not
425 * open any configuration file.
427 * @param[in] profile:
429 * Name of profile (configuration/database variant).
431 * If non-NULL, append to the directory / file path determined for
432 * <em>config_path</em> and <em>database_path</em>.
435 * - environment variable NOTMUCH_PROFILE if defined,
436 * - otherwise "default" for directories and "" (empty string) for paths.
439 * @param[out] database
441 * Pointer to database object. May not be NULL.
443 * The caller should call notmuch_database_destroy when finished with
446 * In case of any failure, this function returns an error status and
447 * sets *database to NULL.
450 * @param[out] error_message
451 * If non-NULL, store error message from opening the database.
452 * Any such message is allocated by \a malloc(3) and should be freed
455 * @retval NOTMUCH_STATUS_SUCCESS: Successfully opened the database.
457 * @retval NOTMUCH_STATUS_NULL_POINTER: The given \a database
460 * @retval NOTMUCH_STATUS_NO_CONFIG: No config file was found. Fatal.
462 * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
464 * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
465 * database or config file (such as permission denied, or file not found,
466 * etc.), or the database version is unknown.
468 * @retval NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
470 * @since libnotmuch 5.4 (notmuch 0.32)
474 notmuch_database_open_with_config (const char *database_path,
475 notmuch_database_mode_t mode,
476 const char *config_path,
478 notmuch_database_t **database,
479 char **error_message);
483 * Loads configuration from config file, database, and/or defaults
485 * For description of arguments, @see notmuch_database_open_with_config
487 * For errors other then NO_DATABASE and NO_CONFIG, *database is set to
490 * @retval NOTMUCH_STATUS_SUCCESS: Successfully loaded configuration.
492 * @retval NOTMUCH_STATUS_NO_CONFIG: No config file was loaded. Not fatal.
494 * @retval NOTMUCH_STATUS_NO_DATABASE: No config information was
495 * loaded from a database. Not fatal.
497 * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
499 * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
500 * database or config file (such as permission denied, or file not found,
503 * @retval NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
505 * @since libnotmuch 5.4 (notmuch 0.32)
509 notmuch_database_load_config (const char *database_path,
510 const char *config_path,
512 notmuch_database_t **database,
513 char **error_message);
516 * Create a new notmuch database located at 'database_path', using
517 * configuration in 'config_path'.
519 * For description of arguments, @see notmuch_database_open_with_config
521 * In case of any failure, this function returns an error status and
522 * sets *database to NULL.
524 * @retval NOTMUCH_STATUS_SUCCESS: Successfully created the database.
526 * @retval NOTMUCH_STATUS_DATABASE_EXISTS: Database already exists, not created
528 * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
530 * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
531 * database or config file (such as permission denied, or file not found,
534 * @retval NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
536 * @since libnotmuch 5.4 (notmuch 0.32)
540 notmuch_database_create_with_config (const char *database_path,
541 const char *config_path,
543 notmuch_database_t **database,
544 char **error_message);
547 * Retrieve last status string for given database.
551 notmuch_database_status_string (const notmuch_database_t *notmuch);
554 * Commit changes and close the given notmuch database.
556 * After notmuch_database_close has been called, calls to other
557 * functions on objects derived from this database may either behave
558 * as if the database had not been closed (e.g., if the required data
559 * has been cached) or may fail with a
560 * NOTMUCH_STATUS_XAPIAN_EXCEPTION. The only further operation
561 * permitted on the database itself is to call
562 * notmuch_database_destroy.
564 * notmuch_database_close can be called multiple times. Later calls
567 * For writable databases, notmuch_database_close commits all changes
568 * to disk before closing the database, unless the caller is currently
569 * in an atomic section (there was a notmuch_database_begin_atomic
570 * without a matching notmuch_database_end_atomic). In this case
571 * changes since the last commit are discarded. @see
572 * notmuch_database_end_atomic for more information.
576 * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.
578 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the
579 * database has been closed but there are no guarantees the
580 * changes to the database, if any, have been flushed to disk.
583 notmuch_database_close (notmuch_database_t *database);
586 * A callback invoked by notmuch_database_compact to notify the user
587 * of the progress of the compaction process.
589 typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure);
592 * Compact a notmuch database, backing up the original database to the
595 * The database will be opened with NOTMUCH_DATABASE_MODE_READ_WRITE
596 * during the compaction process to ensure no writes are made.
598 * If the optional callback function 'status_cb' is non-NULL, it will
599 * be called with diagnostic and informational messages. The argument
600 * 'closure' is passed verbatim to any callback invoked.
603 notmuch_database_compact (const char *path,
604 const char *backup_path,
605 notmuch_compact_status_cb_t status_cb,
609 * Like notmuch_database_compact, but take an open database as a
612 * @since libnnotmuch 5.4 (notmuch 0.32)
615 notmuch_database_compact_db (notmuch_database_t *database,
616 const char *backup_path,
617 notmuch_compact_status_cb_t status_cb,
621 * Destroy the notmuch database, closing it if necessary and freeing
622 * all associated resources.
624 * Return value as in notmuch_database_close if the database was open;
625 * notmuch_database_destroy itself has no failure modes.
628 notmuch_database_destroy (notmuch_database_t *database);
631 * Return the database path of the given database.
633 * The return value is a string owned by notmuch so should not be
634 * modified nor freed by the caller.
637 notmuch_database_get_path (notmuch_database_t *database);
640 * Return the database format version of the given database.
645 notmuch_database_get_version (notmuch_database_t *database);
648 * Can the database be upgraded to a newer database version?
650 * If this function returns TRUE, then the caller may call
651 * notmuch_database_upgrade to upgrade the database. If the caller
652 * does not upgrade an out-of-date database, then some functions may
653 * fail with NOTMUCH_STATUS_UPGRADE_REQUIRED. This always returns
654 * FALSE for a read-only database because there's no way to upgrade a
655 * read-only database.
657 * Also returns FALSE if an error occurs accessing the database.
661 notmuch_database_needs_upgrade (notmuch_database_t *database);
664 * Upgrade the current database to the latest supported version.
666 * This ensures that all current notmuch functionality will be
667 * available on the database. After opening a database in read-write
668 * mode, it is recommended that clients check if an upgrade is needed
669 * (notmuch_database_needs_upgrade) and if so, upgrade with this
670 * function before making any modifications. If
671 * notmuch_database_needs_upgrade returns FALSE, this will be a no-op.
673 * The optional progress_notify callback can be used by the caller to
674 * provide progress indication to the user. If non-NULL it will be
675 * called periodically with 'progress' as a floating-point value in
676 * the range of [0.0 .. 1.0] indicating the progress made so far in
677 * the upgrade process. The argument 'closure' is passed verbatim to
678 * any callback invoked.
681 notmuch_database_upgrade (notmuch_database_t *database,
682 void (*progress_notify)(void *closure,
687 * Begin an atomic database operation.
689 * Any modifications performed between a successful begin and a
690 * notmuch_database_end_atomic will be applied to the database
691 * atomically. Note that, unlike a typical database transaction, this
692 * only ensures atomicity, not durability; neither begin nor end
693 * necessarily flush modifications to disk.
695 * Atomic sections may be nested. begin_atomic and end_atomic must
696 * always be called in pairs.
700 * NOTMUCH_STATUS_SUCCESS: Successfully entered atomic section.
702 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
703 * atomic section not entered.
706 notmuch_database_begin_atomic (notmuch_database_t *notmuch);
709 * Indicate the end of an atomic database operation. If repeated
710 * (with matching notmuch_database_begin_atomic) "database.autocommit"
711 * times, commit the the transaction and all previous (non-cancelled)
712 * transactions to the database.
716 * NOTMUCH_STATUS_SUCCESS: Successfully completed atomic section.
718 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
719 * atomic section not ended.
721 * NOTMUCH_STATUS_UNBALANCED_ATOMIC: The database is not currently in
725 notmuch_database_end_atomic (notmuch_database_t *notmuch);
728 * Return the committed database revision and UUID.
730 * The database revision number increases monotonically with each
731 * commit to the database. Hence, all messages and message changes
732 * committed to the database (that is, visible to readers) have a last
733 * modification revision <= the committed database revision. Any
734 * messages committed in the future will be assigned a modification
735 * revision > the committed database revision.
737 * The UUID is a NUL-terminated opaque string that uniquely identifies
738 * this database. Two revision numbers are only comparable if they
739 * have the same database UUID. The string 'uuid' is owned by notmuch
740 * and should not be freed or modified by the user.
743 notmuch_database_get_revision (notmuch_database_t *notmuch,
747 * Retrieve a directory object from the database for 'path'.
749 * Here, 'path' should be a path relative to the path of 'database'
750 * (see notmuch_database_get_path), or else should be an absolute path
751 * with initial components that match the path of 'database'.
753 * If this directory object does not exist in the database, this
754 * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL.
756 * Otherwise the returned directory object is owned by the database
757 * and as such, will only be valid until notmuch_database_destroy is
762 * NOTMUCH_STATUS_SUCCESS: Successfully retrieved directory.
764 * NOTMUCH_STATUS_NULL_POINTER: The given 'directory' argument is NULL.
766 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
767 * directory not retrieved.
769 * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
770 * database to use this function.
773 notmuch_database_get_directory (notmuch_database_t *database,
775 notmuch_directory_t **directory);
778 * Add a message file to a database, indexing it for retrieval by
779 * future searches. If a message already exists with the same message
780 * ID as the specified file, their indexes will be merged, and this
781 * new filename will also be associated with the existing message.
783 * Here, 'filename' should be a path relative to the path of
784 * 'database' (see notmuch_database_get_path), or else should be an
785 * absolute filename with initial components that match the path of
788 * The file should be a single mail message (not a multi-message mbox)
789 * that is expected to remain at its current location, (since the
790 * notmuch database will reference the filename, and will not copy the
791 * entire contents of the file.
793 * If another message with the same message ID already exists in the
794 * database, rather than creating a new message, this adds the search
795 * terms from the identified file to the existing message's index, and
796 * adds 'filename' to the list of filenames known for the message.
798 * The 'indexopts' parameter can be NULL (meaning, use the indexing
799 * defaults from the database), or can be an explicit choice of
800 * indexing options that should govern the indexing of this specific
803 * If 'message' is not NULL, then, on successful return
804 * (NOTMUCH_STATUS_SUCCESS or NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) '*message'
805 * will be initialized to a message object that can be used for things
806 * such as adding tags to the just-added message. The user should call
807 * notmuch_message_destroy when done with the message. On any failure
808 * '*message' will be set to NULL.
812 * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
814 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
817 * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
818 * ID as another message already in the database. The new
819 * filename was successfully added to the message in the database
820 * (if not already present) and the existing message is returned.
822 * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the
823 * file, (such as permission denied, or file not found,
824 * etc.). Nothing added to the database.
826 * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
827 * like an email message. Nothing added to the database.
829 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
830 * mode so no message can be added.
832 * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
833 * database to use this function.
835 * @since libnotmuch 5.1 (notmuch 0.26)
838 notmuch_database_index_file (notmuch_database_t *database,
839 const char *filename,
840 notmuch_indexopts_t *indexopts,
841 notmuch_message_t **message);
844 * Deprecated alias for notmuch_database_index_file called with
847 * @deprecated Deprecated as of libnotmuch 5.1 (notmuch 0.26). Please
848 * use notmuch_database_index_file instead.
851 NOTMUCH_DEPRECATED (5, 1)
853 notmuch_database_add_message (notmuch_database_t *database,
854 const char *filename,
855 notmuch_message_t **message);
858 * Remove a message filename from the given notmuch database. If the
859 * message has no more filenames, remove the message.
861 * If the same message (as determined by the message ID) is still
862 * available via other filenames, then the message will persist in the
863 * database for those filenames. When the last filename is removed for
864 * a particular message, the database content for that message will be
869 * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the
870 * message was removed from the database.
872 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
873 * message not removed.
875 * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but
876 * the message persists in the database with at least one other
879 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
880 * mode so no message can be removed.
882 * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
883 * database to use this function.
886 notmuch_database_remove_message (notmuch_database_t *database,
887 const char *filename);
890 * Find a message with the given message_id.
892 * If a message with the given message_id is found then, on successful return
893 * (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to a message
894 * object. The caller should call notmuch_message_destroy when done with the
897 * On any failure or when the message is not found, this function initializes
898 * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
899 * caller is supposed to check '*message' for NULL to find out whether the
900 * message with the given message_id was found.
904 * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'.
906 * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
908 * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating message object
910 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
913 notmuch_database_find_message (notmuch_database_t *database,
914 const char *message_id,
915 notmuch_message_t **message);
918 * Find a message with the given filename.
920 * If the database contains a message with the given filename then, on
921 * successful return (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to
922 * a message object. The caller should call notmuch_message_destroy when done
925 * On any failure or when the message is not found, this function initializes
926 * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
927 * caller is supposed to check '*message' for NULL to find out whether the
928 * message with the given filename is found.
932 * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'
934 * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
936 * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object
938 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
940 * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
941 * database to use this function.
944 notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
945 const char *filename,
946 notmuch_message_t **message);
949 * Return a list of all tags found in the database.
951 * This function creates a list of all tags found in the database. The
952 * resulting list contains all tags from all messages found in the database.
954 * On error this function returns NULL.
957 notmuch_database_get_all_tags (notmuch_database_t *db);
960 * Reopen an open notmuch database.
962 * @param [in] db open notmuch database
963 * @param [in] mode mode (read only or read-write) for reopened database.
965 * @retval #NOTMUCH_STATUS_SUCCESS
966 * @retval #NOTMUCH_STATUS_ILLEGAL_ARGUMENT The passed database was not open.
967 * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION A Xapian exception occured
970 notmuch_database_reopen (notmuch_database_t *db, notmuch_database_mode_t mode);
973 * Create a new query for 'database'.
975 * Here, 'database' should be an open database, (see
976 * notmuch_database_open and notmuch_database_create).
978 * For the query string, we'll document the syntax here more
979 * completely in the future, but it's likely to be a specialized
980 * version of the general Xapian query syntax:
982 * https://xapian.org/docs/queryparser.html
984 * As a special case, passing either a length-zero string, (that is ""),
985 * or a string consisting of a single asterisk (that is "*"), will
986 * result in a query that returns all messages in the database.
988 * See notmuch_query_set_sort for controlling the order of results.
989 * See notmuch_query_search_messages and notmuch_query_search_threads
990 * to actually execute the query.
992 * User should call notmuch_query_destroy when finished with this
995 * Will return NULL if insufficient memory is available.
998 notmuch_query_create (notmuch_database_t *database,
999 const char *query_string);
1002 NOTMUCH_QUERY_SYNTAX_XAPIAN,
1003 NOTMUCH_QUERY_SYNTAX_SEXP
1004 } notmuch_query_syntax_t;
1007 notmuch_query_create_with_syntax (notmuch_database_t *database,
1008 const char *query_string,
1009 notmuch_query_syntax_t syntax,
1010 notmuch_query_t **output);
1012 * Sort values for notmuch_query_set_sort.
1018 NOTMUCH_SORT_OLDEST_FIRST,
1022 NOTMUCH_SORT_NEWEST_FIRST,
1024 * Sort by message-id.
1026 NOTMUCH_SORT_MESSAGE_ID,
1030 NOTMUCH_SORT_UNSORTED
1034 * Return the query_string of this query. See notmuch_query_create.
1037 notmuch_query_get_query_string (const notmuch_query_t *query);
1040 * Return the notmuch database of this query. See notmuch_query_create.
1042 notmuch_database_t *
1043 notmuch_query_get_database (const notmuch_query_t *query);
1046 * Exclude values for notmuch_query_set_omit_excluded. The strange
1047 * order is to maintain backward compatibility: the old FALSE/TRUE
1048 * options correspond to the new
1049 * NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options.
1052 NOTMUCH_EXCLUDE_FLAG,
1053 NOTMUCH_EXCLUDE_TRUE,
1054 NOTMUCH_EXCLUDE_FALSE,
1056 } notmuch_exclude_t;
1059 * Specify whether to omit excluded results or simply flag them. By
1060 * default, this is set to TRUE.
1062 * If set to TRUE or ALL, notmuch_query_search_messages will omit excluded
1063 * messages from the results, and notmuch_query_search_threads will omit
1064 * threads that match only in excluded messages. If set to TRUE,
1065 * notmuch_query_search_threads will include all messages in threads that
1066 * match in at least one non-excluded message. Otherwise, if set to ALL,
1067 * notmuch_query_search_threads will omit excluded messages from all threads.
1069 * If set to FALSE or FLAG then both notmuch_query_search_messages and
1070 * notmuch_query_search_threads will return all matching
1071 * messages/threads regardless of exclude status. If set to FLAG then
1072 * the exclude flag will be set for any excluded message that is
1073 * returned by notmuch_query_search_messages, and the thread counts
1074 * for threads returned by notmuch_query_search_threads will be the
1075 * number of non-excluded messages/matches. Otherwise, if set to
1076 * FALSE, then the exclude status is completely ignored.
1078 * The performance difference when calling
1079 * notmuch_query_search_messages should be relatively small (and both
1080 * should be very fast). However, in some cases,
1081 * notmuch_query_search_threads is very much faster when omitting
1082 * excluded messages as it does not need to construct the threads that
1083 * only match in excluded messages.
1086 notmuch_query_set_omit_excluded (notmuch_query_t *query,
1087 notmuch_exclude_t omit_excluded);
1090 * Specify the sorting desired for this query.
1093 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
1096 * Return the sort specified for this query. See
1097 * notmuch_query_set_sort.
1100 notmuch_query_get_sort (const notmuch_query_t *query);
1103 * Add a tag that will be excluded from the query results by default.
1104 * This exclusion will be ignored if this tag appears explicitly in
1109 * NOTMUCH_STATUS_SUCCESS: excluded was added successfully.
1111 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred.
1112 * Most likely a problem lazily parsing the query string.
1114 * NOTMUCH_STATUS_IGNORED: tag is explicitly present in the query, so
1118 notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
1121 * Execute a query for threads, returning a notmuch_threads_t object
1122 * which can be used to iterate over the results. The returned threads
1123 * object is owned by the query and as such, will only be valid until
1124 * notmuch_query_destroy.
1126 * Typical usage might be:
1128 * notmuch_query_t *query;
1129 * notmuch_threads_t *threads;
1130 * notmuch_thread_t *thread;
1131 * notmuch_status_t stat;
1133 * query = notmuch_query_create (database, query_string);
1135 * for (stat = notmuch_query_search_threads (query, &threads);
1136 * stat == NOTMUCH_STATUS_SUCCESS &&
1137 * ! notmuch_threads_status (threads);
1138 * notmuch_threads_move_to_next (threads))
1140 * thread = notmuch_threads_get (threads);
1142 * notmuch_thread_destroy (thread);
1145 * notmuch_query_destroy (query);
1147 * Note: If you are finished with a thread before its containing
1148 * query, you can call notmuch_thread_destroy to clean up some memory
1149 * sooner (as in the above example). Otherwise, if your thread objects
1150 * are long-lived, then you don't need to call notmuch_thread_destroy
1151 * and all the memory will still be reclaimed when the query is
1154 * Note that there's no explicit destructor needed for the
1155 * notmuch_threads_t object. (For consistency, we do provide a
1156 * notmuch_threads_destroy function, but there's no good reason
1157 * to call it if the query is about to be destroyed).
1159 * @since libnotmuch 5.0 (notmuch 0.25)
1162 notmuch_query_search_threads (notmuch_query_t *query,
1163 notmuch_threads_t **out);
1166 * Deprecated alias for notmuch_query_search_threads.
1168 * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please
1169 * use notmuch_query_search_threads instead.
1172 NOTMUCH_DEPRECATED (5, 0)
1174 notmuch_query_search_threads_st (notmuch_query_t *query, notmuch_threads_t **out);
1177 * Execute a query for messages, returning a notmuch_messages_t object
1178 * which can be used to iterate over the results. The returned
1179 * messages object is owned by the query and as such, will only be
1180 * valid until notmuch_query_destroy.
1182 * Typical usage might be:
1184 * notmuch_query_t *query;
1185 * notmuch_messages_t *messages;
1186 * notmuch_message_t *message;
1188 * query = notmuch_query_create (database, query_string);
1190 * if (notmuch_query_search_messages (query, &messages) != NOTMUCH_STATUS_SUCCESS)
1191 * return EXIT_FAILURE;
1194 * ! notmuch_messages_status (messages);
1195 * notmuch_messages_move_to_next (messages))
1197 * message = notmuch_messages_get (messages);
1199 * notmuch_message_destroy (message);
1202 * if (notmuch_messages_status (messages) != NOTMUCH_STATUS_ITERATOR_EXHAUSTED)
1203 * return EXIT_FAILURE;
1205 * notmuch_query_destroy (query);
1207 * Note: If you are finished with a message before its containing
1208 * query, you can call notmuch_message_destroy to clean up some memory
1209 * sooner (as in the above example). Otherwise, if your message
1210 * objects are long-lived, then you don't need to call
1211 * notmuch_message_destroy and all the memory will still be reclaimed
1212 * when the query is destroyed.
1214 * Note that there's no explicit destructor needed for the
1215 * notmuch_messages_t object. (For consistency, we do provide a
1216 * notmuch_messages_destroy function, but there's no good
1217 * reason to call it if the query is about to be destroyed).
1219 * If a Xapian exception occurs this function will return NULL.
1221 * @since libnotmuch 5 (notmuch 0.25)
1224 notmuch_query_search_messages (notmuch_query_t *query,
1225 notmuch_messages_t **out);
1227 * Deprecated alias for notmuch_query_search_messages
1229 * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please use
1230 * notmuch_query_search_messages instead.
1234 NOTMUCH_DEPRECATED (5, 0)
1236 notmuch_query_search_messages_st (notmuch_query_t *query,
1237 notmuch_messages_t **out);
1240 * Destroy a notmuch_query_t along with any associated resources.
1242 * This will in turn destroy any notmuch_threads_t and
1243 * notmuch_messages_t objects generated by this query, (and in
1244 * turn any notmuch_thread_t and notmuch_message_t objects generated
1245 * from those results, etc.), if such objects haven't already been
1249 notmuch_query_destroy (notmuch_query_t *query);
1252 * Is the given 'threads' iterator pointing at a valid thread.
1254 * When this function returns TRUE, notmuch_threads_get will return a
1255 * valid object. Whereas when this function returns FALSE,
1256 * notmuch_threads_get will return NULL.
1258 * If passed a NULL pointer, this function returns FALSE
1260 * See the documentation of notmuch_query_search_threads for example
1261 * code showing how to iterate over a notmuch_threads_t object.
1263 * Note that an iterator may become invalid either due to getting exhausted or
1264 * due to a runtime error. Use notmuch_threads_status to distinguish
1265 * between those cases.
1268 notmuch_threads_valid (notmuch_threads_t *threads);
1271 * Get the status of the given 'threads' iterator.
1275 * @retval #NOTMUCH_STATUS_SUCCESS The iterator is valid; notmuch_threads_get
1276 * may return a valid object
1278 * @retval #NOTMUCH_STATUS_ITERATOR_EXHAUSTED All items have been read
1280 * @retval #NOTMUCH_STATUS_OUT_OF_MEMORY Iteration failed to allocate memory
1282 * @retval #NOTMUCH_STATUS_OPERATION_INVALIDATED Iteration was invalidated by
1283 * the database. Re-open the database and try again.
1285 * See the documentation of notmuch_query_search_threads for example
1286 * code showing how to iterate over a notmuch_threads_t object.
1289 notmuch_threads_status (notmuch_threads_t *threads);
1292 * Get the current thread from 'threads' as a notmuch_thread_t.
1294 * Note: The returned thread belongs to 'threads' and has a lifetime
1295 * identical to it (and the query to which it belongs).
1297 * See the documentation of notmuch_query_search_threads for example
1298 * code showing how to iterate over a notmuch_threads_t object.
1300 * If an out-of-memory situation occurs, this function will return
1304 notmuch_threads_get (notmuch_threads_t *threads);
1307 * Move the 'threads' iterator to the next thread.
1309 * If 'threads' is already pointing at the last thread then the
1310 * iterator will be moved to a point just beyond that last thread,
1311 * (where notmuch_threads_status will return NOTMUCH_STATUS_ITERATOR_EXHAUSTED
1312 * and notmuch_threads_get will return NULL).
1314 * See the documentation of notmuch_query_search_threads for example
1315 * code showing how to iterate over a notmuch_threads_t object.
1318 notmuch_threads_move_to_next (notmuch_threads_t *threads);
1321 * Destroy a notmuch_threads_t object.
1323 * It's not strictly necessary to call this function. All memory from
1324 * the notmuch_threads_t object will be reclaimed when the
1325 * containing query object is destroyed.
1328 notmuch_threads_destroy (notmuch_threads_t *threads);
1331 * Return the number of messages matching a search.
1333 * This function performs a search and returns the number of matching
1338 * NOTMUCH_STATUS_SUCCESS: query completed successfully.
1340 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred. The
1341 * value of *count is not defined.
1343 * @since libnotmuch 5 (notmuch 0.25)
1346 notmuch_query_count_messages (notmuch_query_t *query, unsigned int *count);
1349 * Deprecated alias for notmuch_query_count_messages
1352 * @deprecated Deprecated since libnotmuch 5.0 (notmuch 0.25). Please
1353 * use notmuch_query_count_messages instead.
1355 NOTMUCH_DEPRECATED (5, 0)
1357 notmuch_query_count_messages_st (notmuch_query_t *query, unsigned int *count);
1360 * Return the number of threads matching a search.
1362 * This function performs a search and returns the number of unique thread IDs
1363 * in the matching messages. This is the same as number of threads matching a
1366 * Note that this is a significantly heavier operation than
1367 * notmuch_query_count_messages{_st}().
1371 * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
1372 * of *count is not defined
1374 * NOTMUCH_STATUS_SUCCESS: query completed successfully.
1376 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred. The
1377 * value of *count is not defined.
1379 * @since libnotmuch 5 (notmuch 0.25)
1382 notmuch_query_count_threads (notmuch_query_t *query, unsigned *count);
1385 * Deprecated alias for notmuch_query_count_threads
1387 * @deprecated Deprecated as of libnotmuch 5.0 (notmuch 0.25). Please
1388 * use notmuch_query_count_threads_st instead.
1390 NOTMUCH_DEPRECATED (5, 0)
1392 notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
1395 * Get the thread ID of 'thread'.
1397 * The returned string belongs to 'thread' and as such, should not be
1398 * modified by the caller and will only be valid for as long as the
1399 * thread is valid, (which is until notmuch_thread_destroy or until
1400 * the query from which it derived is destroyed).
1403 notmuch_thread_get_thread_id (notmuch_thread_t *thread);
1406 * Get the total number of messages in 'thread'.
1408 * This count consists of all messages in the database belonging to
1409 * this thread. Contrast with notmuch_thread_get_matched_messages() .
1412 notmuch_thread_get_total_messages (notmuch_thread_t *thread);
1415 * Get the total number of files in 'thread'.
1417 * This sums notmuch_message_count_files over all messages in the
1419 * @returns Non-negative integer
1420 * @since libnotmuch 5.0 (notmuch 0.25)
1424 notmuch_thread_get_total_files (notmuch_thread_t *thread);
1427 * Get a notmuch_messages_t iterator for the top-level messages in
1428 * 'thread' in oldest-first order.
1430 * This iterator will not necessarily iterate over all of the messages
1431 * in the thread. It will only iterate over the messages in the thread
1432 * which are not replies to other messages in the thread.
1434 * The returned list will be destroyed when the thread is destroyed.
1436 notmuch_messages_t *
1437 notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
1440 * Get a notmuch_thread_t iterator for all messages in 'thread' in
1441 * oldest-first order.
1443 * The returned list will be destroyed when the thread is destroyed.
1445 notmuch_messages_t *
1446 notmuch_thread_get_messages (notmuch_thread_t *thread);
1449 * Get the number of messages in 'thread' that matched the search.
1451 * This count includes only the messages in this thread that were
1452 * matched by the search from which the thread was created and were
1453 * not excluded by any exclude tags passed in with the query (see
1454 * notmuch_query_add_tag_exclude). Contrast with
1455 * notmuch_thread_get_total_messages() .
1458 notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
1461 * Get the authors of 'thread' as a UTF-8 string.
1463 * The returned string is a comma-separated list of the names of the
1464 * authors of mail messages in the query results that belong to this
1467 * The string contains authors of messages matching the query first, then
1468 * non-matched authors (with the two groups separated by '|'). Within
1469 * each group, authors are ordered by date.
1471 * The returned string belongs to 'thread' and as such, should not be
1472 * modified by the caller and will only be valid for as long as the
1473 * thread is valid, (which is until notmuch_thread_destroy or until
1474 * the query from which it derived is destroyed).
1477 notmuch_thread_get_authors (notmuch_thread_t *thread);
1480 * Get the subject of 'thread' as a UTF-8 string.
1482 * The subject is taken from the first message (according to the query
1483 * order---see notmuch_query_set_sort) in the query results that
1484 * belongs to this thread.
1486 * The returned string belongs to 'thread' and as such, should not be
1487 * modified by the caller and will only be valid for as long as the
1488 * thread is valid, (which is until notmuch_thread_destroy or until
1489 * the query from which it derived is destroyed).
1492 notmuch_thread_get_subject (notmuch_thread_t *thread);
1495 * Get the date of the oldest message in 'thread' as a time_t value.
1498 notmuch_thread_get_oldest_date (notmuch_thread_t *thread);
1501 * Get the date of the newest message in 'thread' as a time_t value.
1504 notmuch_thread_get_newest_date (notmuch_thread_t *thread);
1507 * Get the tags for 'thread', returning a notmuch_tags_t object which
1508 * can be used to iterate over all tags.
1510 * Note: In the Notmuch database, tags are stored on individual
1511 * messages, not on threads. So the tags returned here will be all
1512 * tags of the messages which matched the search and which belong to
1515 * The tags object is owned by the thread and as such, will only be
1516 * valid for as long as the thread is valid, (for example, until
1517 * notmuch_thread_destroy or until the query from which it derived is
1520 * Typical usage might be:
1522 * notmuch_thread_t *thread;
1523 * notmuch_tags_t *tags;
1526 * thread = notmuch_threads_get (threads);
1528 * for (tags = notmuch_thread_get_tags (thread);
1529 * notmuch_tags_valid (tags);
1530 * notmuch_tags_move_to_next (tags))
1532 * tag = notmuch_tags_get (tags);
1536 * notmuch_thread_destroy (thread);
1538 * Note that there's no explicit destructor needed for the
1539 * notmuch_tags_t object. (For consistency, we do provide a
1540 * notmuch_tags_destroy function, but there's no good reason to call
1541 * it if the message is about to be destroyed).
1544 notmuch_thread_get_tags (notmuch_thread_t *thread);
1547 * Destroy a notmuch_thread_t object.
1550 notmuch_thread_destroy (notmuch_thread_t *thread);
1553 * Is the given 'messages' iterator pointing at a valid message.
1555 * When this function returns TRUE, notmuch_messages_get will return a
1556 * valid object. Whereas when this function returns FALSE,
1557 * notmuch_messages_get will return NULL.
1559 * See the documentation of notmuch_query_search_messages for example
1560 * code showing how to iterate over a notmuch_messages_t object.
1562 * Note that an iterator may become invalid either due to getting exhausted or
1563 * due to a runtime error. Use notmuch_messages_status to distinguish
1564 * between those cases.
1567 notmuch_messages_valid (notmuch_messages_t *messages);
1570 * Get the status of the given 'messages' iterator.
1574 * NOTMUCH_STATUS_SUCCESS: The iterator is valid; notmuch_messages_get will
1575 * return a valid object
1577 * NOTMUCH_STATUS_ITERATOR_EXHAUSTED: All items have been read
1579 * NOTMUCH_STATUS_OUT_OF_MEMORY: Iteration failed to allocate memory
1581 * NOTMUCH_STATUS_OPERATION_INVALIDATED: Iteration was invalidated by the
1582 * database. Re-open the database and try again.
1584 * See the documentation of notmuch_query_search_messages for example
1585 * code showing how to iterate over a notmuch_messages_t object.
1588 notmuch_messages_status (notmuch_messages_t *messages);
1591 * Get the current message from 'messages' as a notmuch_message_t.
1593 * Note: The returned message belongs to 'messages' and has a lifetime
1594 * identical to it (and the query to which it belongs).
1596 * See the documentation of notmuch_query_search_messages for example
1597 * code showing how to iterate over a notmuch_messages_t object.
1599 * If an out-of-memory situation occurs, this function will return
1603 notmuch_messages_get (notmuch_messages_t *messages);
1606 * Move the 'messages' iterator to the next message.
1608 * If 'messages' is already pointing at the last message then the
1609 * iterator will be moved to a point just beyond that last message,
1610 * (where notmuch_messages_status will return NOTMUCH_STATUS_ITERATOR_EXHAUSTED
1611 * and notmuch_messages_get will return NULL).
1613 * See the documentation of notmuch_query_search_messages for example
1614 * code showing how to iterate over a notmuch_messages_t object.
1617 notmuch_messages_move_to_next (notmuch_messages_t *messages);
1620 * Destroy a notmuch_messages_t object.
1622 * It's not strictly necessary to call this function. All memory from
1623 * the notmuch_messages_t object will be reclaimed when the containing
1624 * query object is destroyed.
1627 notmuch_messages_destroy (notmuch_messages_t *messages);
1630 * Return a list of tags from all messages.
1632 * The resulting list is guaranteed not to contain duplicated tags.
1634 * WARNING: You can no longer iterate over messages after calling this
1635 * function, because the iterator will point at the end of the list.
1636 * We do not have a function to reset the iterator yet and the only
1637 * way how you can iterate over the list again is to recreate the
1640 * The function returns NULL on error.
1643 notmuch_messages_collect_tags (notmuch_messages_t *messages);
1646 * Get the database associated with this message.
1648 * @since libnotmuch 5.2 (notmuch 0.27)
1650 notmuch_database_t *
1651 notmuch_message_get_database (const notmuch_message_t *message);
1654 * Get the message ID of 'message'.
1656 * The returned string belongs to 'message' and as such, should not be
1657 * modified by the caller and will only be valid for as long as the
1658 * message is valid, (which is until the query from which it derived
1661 * This function will return NULL if triggers an unhandled Xapian
1665 notmuch_message_get_message_id (notmuch_message_t *message);
1668 * Get the thread ID of 'message'.
1670 * The returned string belongs to 'message' and as such, should not be
1671 * modified by the caller and will only be valid for as long as the
1672 * message is valid, (for example, until the user calls
1673 * notmuch_message_destroy on 'message' or until a query from which it
1674 * derived is destroyed).
1676 * This function will return NULL if triggers an unhandled Xapian
1680 notmuch_message_get_thread_id (notmuch_message_t *message);
1683 * Get a notmuch_messages_t iterator for all of the replies to
1686 * Note: This call only makes sense if 'message' was ultimately
1687 * obtained from a notmuch_thread_t object, (such as by coming
1688 * directly from the result of calling notmuch_thread_get_
1689 * toplevel_messages or by any number of subsequent
1690 * calls to notmuch_message_get_replies).
1692 * If 'message' was obtained through some non-thread means, (such as
1693 * by a call to notmuch_query_search_messages), then this function
1696 * If there are no replies to 'message', this function will return
1697 * NULL. (Note that notmuch_messages_status will accept that NULL
1698 * value as legitimate, and simply return NOTMUCH_STATUS_ITERATOR_EXHAUSTED
1701 * This function also returns NULL if it triggers a Xapian exception.
1703 * The returned list will be destroyed when the thread is
1706 notmuch_messages_t *
1707 notmuch_message_get_replies (notmuch_message_t *message);
1710 * Get the total number of files associated with a message.
1711 * @returns Non-negative integer for file count.
1712 * @returns Negative integer for error.
1713 * @since libnotmuch 5.0 (notmuch 0.25)
1716 notmuch_message_count_files (notmuch_message_t *message);
1719 * Get a filename for the email corresponding to 'message'.
1721 * The returned filename is an absolute filename, (the initial
1722 * component will match notmuch_database_get_path() ).
1724 * The returned string belongs to the message so should not be
1725 * modified or freed by the caller (nor should it be referenced after
1726 * the message is destroyed).
1728 * Note: If this message corresponds to multiple files in the mail
1729 * store, (that is, multiple files contain identical message IDs),
1730 * this function will arbitrarily return a single one of those
1731 * filenames. See notmuch_message_get_filenames for returning the
1732 * complete list of filenames.
1734 * This function returns NULL if it triggers a Xapian exception.
1737 notmuch_message_get_filename (notmuch_message_t *message);
1740 * Get all filenames for the email corresponding to 'message'.
1742 * Returns a notmuch_filenames_t iterator listing all the filenames
1743 * associated with 'message'. These files may not have identical
1744 * content, but each will have the identical Message-ID.
1746 * Each filename in the iterator is an absolute filename, (the initial
1747 * component will match notmuch_database_get_path() ).
1749 * This function returns NULL if it triggers a Xapian exception.
1751 notmuch_filenames_t *
1752 notmuch_message_get_filenames (notmuch_message_t *message);
1755 * Re-index the e-mail corresponding to 'message' using the supplied index options
1757 * Returns the status of the re-index operation. (see the return
1758 * codes documented in notmuch_database_index_file)
1760 * After reindexing, the user should discard the message object passed
1761 * in here by calling notmuch_message_destroy, since it refers to the
1762 * original message, not to the reindexed message.
1765 notmuch_message_reindex (notmuch_message_t *message,
1766 notmuch_indexopts_t *indexopts);
1772 NOTMUCH_MESSAGE_FLAG_MATCH,
1773 NOTMUCH_MESSAGE_FLAG_EXCLUDED,
1775 /* This message is a "ghost message", meaning it has no filenames
1776 * or content, but we know it exists because it was referenced by
1777 * some other message. A ghost message has only a message ID and
1780 NOTMUCH_MESSAGE_FLAG_GHOST,
1781 } notmuch_message_flag_t;
1784 * Get a value of a flag for the email corresponding to 'message'.
1786 * returns FALSE in case of errors.
1788 * @deprecated Deprecated as of libnotmuch 5.3 (notmuch 0.31). Please
1789 * use notmuch_message_get_flag_st instead.
1791 NOTMUCH_DEPRECATED (5, 3)
1793 notmuch_message_get_flag (notmuch_message_t *message,
1794 notmuch_message_flag_t flag);
1797 * Get a value of a flag for the email corresponding to 'message'.
1799 * @param message a message object
1800 * @param flag flag to check
1801 * @param is_set pointer to boolean to store flag value.
1803 * @retval #NOTMUCH_STATUS_SUCCESS
1804 * @retval #NOTMUCH_STATUS_NULL_POINTER is_set is NULL
1805 * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION Accessing the database
1806 * triggered an exception.
1808 * @since libnotmuch 5.3 (notmuch 0.31)
1811 notmuch_message_get_flag_st (notmuch_message_t *message,
1812 notmuch_message_flag_t flag,
1813 notmuch_bool_t *is_set);
1816 * Set a value of a flag for the email corresponding to 'message'.
1819 notmuch_message_set_flag (notmuch_message_t *message,
1820 notmuch_message_flag_t flag, notmuch_bool_t value);
1823 * Get the date of 'message' as a time_t value.
1825 * For the original textual representation of the Date header from the
1826 * message call notmuch_message_get_header() with a header value of
1829 * Returns 0 in case of error.
1832 notmuch_message_get_date (notmuch_message_t *message);
1835 * Get the value of the specified header from 'message' as a UTF-8 string.
1837 * Common headers are stored in the database when the message is
1838 * indexed and will be returned from the database. Other headers will
1839 * be read from the actual message file.
1841 * The header name is case insensitive.
1843 * The returned string belongs to the message so should not be
1844 * modified or freed by the caller (nor should it be referenced after
1845 * the message is destroyed).
1847 * Returns an empty string ("") if the message does not contain a
1848 * header line matching 'header'. Returns NULL if any error occurs.
1851 notmuch_message_get_header (notmuch_message_t *message, const char *header);
1854 * Get the tags for 'message', returning a notmuch_tags_t object which
1855 * can be used to iterate over all tags.
1857 * The tags object is owned by the message and as such, will only be
1858 * valid for as long as the message is valid, (which is until the
1859 * query from which it derived is destroyed).
1861 * Typical usage might be:
1863 * notmuch_message_t *message;
1864 * notmuch_tags_t *tags;
1867 * message = notmuch_database_find_message (database, message_id);
1869 * for (tags = notmuch_message_get_tags (message);
1870 * notmuch_tags_valid (tags);
1871 * notmuch_tags_move_to_next (tags))
1873 * tag = notmuch_tags_get (tags);
1877 * notmuch_message_destroy (message);
1879 * Note that there's no explicit destructor needed for the
1880 * notmuch_tags_t object. (For consistency, we do provide a
1881 * notmuch_tags_destroy function, but there's no good reason to call
1882 * it if the message is about to be destroyed).
1885 notmuch_message_get_tags (notmuch_message_t *message);
1888 * The longest possible tag value.
1890 #define NOTMUCH_TAG_MAX 200
1893 * Add a tag to the given message.
1897 * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message
1899 * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1901 * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1902 * (exceeds NOTMUCH_TAG_MAX)
1904 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1905 * mode so message cannot be modified.
1908 notmuch_message_add_tag (notmuch_message_t *message, const char *tag);
1911 * Remove a tag from the given message.
1915 * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message
1917 * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1919 * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1920 * (exceeds NOTMUCH_TAG_MAX)
1922 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1923 * mode so message cannot be modified.
1926 notmuch_message_remove_tag (notmuch_message_t *message, const char *tag);
1929 * Remove all tags from the given message.
1931 * See notmuch_message_freeze for an example showing how to safely
1932 * replace tag values.
1934 * @retval #NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
1935 * read-only mode so message cannot be modified.
1936 * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION: an exception was thrown
1937 * accessing the database.
1940 notmuch_message_remove_all_tags (notmuch_message_t *message);
1943 * Add/remove tags according to maildir flags in the message filename(s).
1945 * This function examines the filenames of 'message' for maildir
1946 * flags, and adds or removes tags on 'message' as follows when these
1947 * flags are present:
1949 * Flag Action if present
1950 * ---- -----------------
1951 * 'D' Adds the "draft" tag to the message
1952 * 'F' Adds the "flagged" tag to the message
1953 * 'P' Adds the "passed" tag to the message
1954 * 'R' Adds the "replied" tag to the message
1955 * 'S' Removes the "unread" tag from the message
1957 * For each flag that is not present, the opposite action (add/remove)
1958 * is performed for the corresponding tags.
1960 * Flags are identified as trailing components of the filename after a
1961 * sequence of ":2,".
1963 * If there are multiple filenames associated with this message, the
1964 * flag is considered present if it appears in one or more
1965 * filenames. (That is, the flags from the multiple filenames are
1966 * combined with the logical OR operator.)
1968 * A client can ensure that notmuch database tags remain synchronized
1969 * with maildir flags by calling this function after each call to
1970 * notmuch_database_index_file. See also
1971 * notmuch_message_tags_to_maildir_flags for synchronizing tag changes
1972 * back to maildir flags.
1975 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
1978 * return TRUE if any filename of 'message' has maildir flag 'flag',
1981 * Deprecated wrapper for notmuch_message_has_maildir_flag_st
1983 * @returns FALSE in case of error
1984 * @deprecated libnotmuch 5.3 (notmuch 0.31)
1986 NOTMUCH_DEPRECATED (5, 3)
1988 notmuch_message_has_maildir_flag (notmuch_message_t *message, char flag);
1991 * check message for maildir flag
1993 * @param [in,out] message message to check
1994 * @param [in] flag flag to check for
1995 * @param [out] is_set pointer to boolean
1997 * @retval #NOTMUCH_STATUS_SUCCESS
1998 * @retval #NOTMUCH_STATUS_NULL_POINTER is_set is NULL
1999 * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION Accessing the database
2000 * triggered an exception.
2003 notmuch_message_has_maildir_flag_st (notmuch_message_t *message,
2005 notmuch_bool_t *is_set);
2008 * Rename message filename(s) to encode tags as maildir flags.
2010 * Specifically, for each filename corresponding to this message:
2012 * If the filename is not in a maildir directory, do nothing. (A
2013 * maildir directory is determined as a directory named "new" or
2014 * "cur".) Similarly, if the filename has invalid maildir info,
2015 * (repeated or outof-ASCII-order flag characters after ":2,"), then
2018 * If the filename is in a maildir directory, rename the file so that
2019 * its filename ends with the sequence ":2," followed by zero or more
2020 * of the following single-character flags (in ASCII order):
2022 * * flag 'D' iff the message has the "draft" tag
2023 * * flag 'F' iff the message has the "flagged" tag
2024 * * flag 'P' iff the message has the "passed" tag
2025 * * flag 'R' iff the message has the "replied" tag
2026 * * flag 'S' iff the message does not have the "unread" tag
2028 * Any existing flags unmentioned in the list above will be preserved
2031 * Also, if this filename is in a directory named "new", rename it to
2032 * be within the neighboring directory named "cur".
2034 * A client can ensure that maildir filename flags remain synchronized
2035 * with notmuch database tags by calling this function after changing
2036 * tags, (after calls to notmuch_message_add_tag,
2037 * notmuch_message_remove_tag, or notmuch_message_freeze/
2038 * notmuch_message_thaw). See also notmuch_message_maildir_flags_to_tags
2039 * for synchronizing maildir flag changes back to tags.
2042 notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
2045 * Freeze the current state of 'message' within the database.
2047 * This means that changes to the message state, (via
2048 * notmuch_message_add_tag, notmuch_message_remove_tag, and
2049 * notmuch_message_remove_all_tags), will not be committed to the
2050 * database until the message is thawed with notmuch_message_thaw.
2052 * Multiple calls to freeze/thaw are valid and these calls will
2053 * "stack". That is there must be as many calls to thaw as to freeze
2054 * before a message is actually thawed.
2056 * The ability to do freeze/thaw allows for safe transactions to
2057 * change tag values. For example, explicitly setting a message to
2058 * have a given set of tags might look like this:
2060 * notmuch_message_freeze (message);
2062 * notmuch_message_remove_all_tags (message);
2064 * for (i = 0; i < NUM_TAGS; i++)
2065 * notmuch_message_add_tag (message, tags[i]);
2067 * notmuch_message_thaw (message);
2069 * With freeze/thaw used like this, the message in the database is
2070 * guaranteed to have either the full set of original tag values, or
2071 * the full set of new tag values, but nothing in between.
2073 * Imagine the example above without freeze/thaw and the operation
2074 * somehow getting interrupted. This could result in the message being
2075 * left with no tags if the interruption happened after
2076 * notmuch_message_remove_all_tags but before notmuch_message_add_tag.
2080 * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.
2082 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
2083 * mode so message cannot be modified.
2086 notmuch_message_freeze (notmuch_message_t *message);
2089 * Thaw the current 'message', synchronizing any changes that may have
2090 * occurred while 'message' was frozen into the notmuch database.
2092 * See notmuch_message_freeze for an example of how to use this
2093 * function to safely provide tag changes.
2095 * Multiple calls to freeze/thaw are valid and these calls with
2096 * "stack". That is there must be as many calls to thaw as to freeze
2097 * before a message is actually thawed.
2101 * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least
2102 * its frozen count has successfully been reduced by 1).
2104 * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw
2105 * an unfrozen message. That is, there have been an unbalanced
2106 * number of calls to notmuch_message_freeze and
2107 * notmuch_message_thaw.
2110 notmuch_message_thaw (notmuch_message_t *message);
2113 * Destroy a notmuch_message_t object.
2115 * It can be useful to call this function in the case of a single
2116 * query object with many messages in the result, (such as iterating
2117 * over the entire database). Otherwise, it's fine to never call this
2118 * function and there will still be no memory leaks. (The memory from
2119 * the messages get reclaimed when the containing query is destroyed.)
2122 notmuch_message_destroy (notmuch_message_t *message);
2125 * @name Message Properties
2127 * This interface provides the ability to attach arbitrary (key,value)
2128 * string pairs to a message, to remove such pairs, and to iterate
2129 * over them. The caller should take some care as to what keys they
2130 * add or delete values for, as other subsystems or extensions may
2131 * depend on these properties.
2133 * Please see notmuch-properties(7) for more details about specific
2134 * properties and conventions around their use.
2139 * Retrieve the value for a single property key
2141 * *value* is set to a string owned by the message or NULL if there is
2142 * no such key. In the case of multiple values for the given key, the
2143 * first one is retrieved.
2146 * - NOTMUCH_STATUS_NULL_POINTER: *value* may not be NULL.
2147 * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2148 * @since libnotmuch 4.4 (notmuch 0.23)
2151 notmuch_message_get_property (notmuch_message_t *message, const char *key, const char **value);
2154 * Add a (key,value) pair to a message
2157 * - NOTMUCH_STATUS_ILLEGAL_ARGUMENT: *key* may not contain an '=' character.
2158 * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL.
2159 * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2160 * @since libnotmuch 4.4 (notmuch 0.23)
2163 notmuch_message_add_property (notmuch_message_t *message, const char *key, const char *value);
2166 * Remove a (key,value) pair from a message.
2168 * It is not an error to remove a non-existent (key,value) pair
2171 * - NOTMUCH_STATUS_ILLEGAL_ARGUMENT: *key* may not contain an '=' character.
2172 * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL.
2173 * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2174 * @since libnotmuch 4.4 (notmuch 0.23)
2177 notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
2180 * Remove all (key,value) pairs from the given message.
2182 * @param[in,out] message message to operate on.
2183 * @param[in] key key to delete properties for. If NULL, delete
2184 * properties for all keys
2186 * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
2187 * read-only mode so message cannot be modified.
2188 * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2190 * @since libnotmuch 4.4 (notmuch 0.23)
2193 notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key);
2196 * Remove all (prefix*,value) pairs from the given message
2198 * @param[in,out] message message to operate on.
2199 * @param[in] prefix delete properties with keys that start with prefix.
2200 * If NULL, delete all properties
2202 * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
2203 * read-only mode so message cannot be modified.
2204 * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2206 * @since libnotmuch 5.1 (notmuch 0.26)
2209 notmuch_message_remove_all_properties_with_prefix (notmuch_message_t *message, const char *prefix);
2212 * Opaque message property iterator
2214 typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
2217 * Get the properties for *message*, returning a
2218 * notmuch_message_properties_t object which can be used to iterate
2219 * over all properties.
2221 * The notmuch_message_properties_t object is owned by the message and
2222 * as such, will only be valid for as long as the message is valid,
2223 * (which is until the query from which it derived is destroyed).
2225 * @param[in] message The message to examine
2226 * @param[in] key key or key prefix
2227 * @param[in] exact if TRUE, require exact match with key. Otherwise
2230 * Typical usage might be:
2232 * notmuch_message_properties_t *list;
2234 * for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
2235 * notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
2236 * printf("%s\n", notmuch_message_properties_value(list));
2239 * notmuch_message_properties_destroy (list);
2241 * Note that there's no explicit destructor needed for the
2242 * notmuch_message_properties_t object. (For consistency, we do
2243 * provide a notmuch_message_properities_destroy function, but there's
2244 * no good reason to call it if the message is about to be destroyed).
2246 * @since libnotmuch 4.4 (notmuch 0.23)
2248 notmuch_message_properties_t *
2249 notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
2252 * Return the number of properties named "key" belonging to the specific message.
2254 * @param[in] message The message to examine
2255 * @param[in] key key to count
2256 * @param[out] count The number of matching properties associated with this message.
2260 * NOTMUCH_STATUS_SUCCESS: successful count, possibly some other error.
2262 * @since libnotmuch 5.2 (notmuch 0.27)
2265 notmuch_message_count_properties (notmuch_message_t *message, const char *key, unsigned int *count);
2268 * Is the given *properties* iterator pointing at a valid (key,value)
2271 * When this function returns TRUE,
2272 * notmuch_message_properties_{key,value} will return a valid string,
2273 * and notmuch_message_properties_move_to_next will do what it
2274 * says. Whereas when this function returns FALSE, calling any of
2275 * these functions results in undefined behaviour.
2277 * See the documentation of notmuch_message_get_properties for example
2278 * code showing how to iterate over a notmuch_message_properties_t
2281 * @since libnotmuch 4.4 (notmuch 0.23)
2284 notmuch_message_properties_valid (notmuch_message_properties_t *properties);
2287 * Move the *properties* iterator to the next (key,value) pair
2289 * If *properties* is already pointing at the last pair then the iterator
2290 * will be moved to a point just beyond that last pair, (where
2291 * notmuch_message_properties_valid will return FALSE).
2293 * See the documentation of notmuch_message_get_properties for example
2294 * code showing how to iterate over a notmuch_message_properties_t object.
2296 * @since libnotmuch 4.4 (notmuch 0.23)
2299 notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);
2302 * Return the key from the current (key,value) pair.
2304 * this could be useful if iterating for a prefix
2306 * @since libnotmuch 4.4 (notmuch 0.23)
2309 notmuch_message_properties_key (notmuch_message_properties_t *properties);
2312 * Return the value from the current (key,value) pair.
2314 * This could be useful if iterating for a prefix.
2316 * @since libnotmuch 4.4 (notmuch 0.23)
2319 notmuch_message_properties_value (notmuch_message_properties_t *properties);
2323 * Destroy a notmuch_message_properties_t object.
2325 * It's not strictly necessary to call this function. All memory from
2326 * the notmuch_message_properties_t object will be reclaimed when the
2327 * containing message object is destroyed.
2329 * @since libnotmuch 4.4 (notmuch 0.23)
2332 notmuch_message_properties_destroy (notmuch_message_properties_t *properties);
2337 * Is the given 'tags' iterator pointing at a valid tag.
2339 * When this function returns TRUE, notmuch_tags_get will return a
2340 * valid string. Whereas when this function returns FALSE,
2341 * notmuch_tags_get will return NULL.
2343 * It is acceptable to pass NULL for 'tags', in which case this
2344 * function will always return FALSE.
2346 * See the documentation of notmuch_message_get_tags for example code
2347 * showing how to iterate over a notmuch_tags_t object.
2350 notmuch_tags_valid (notmuch_tags_t *tags);
2353 * Get the current tag from 'tags' as a string.
2355 * Note: The returned string belongs to 'tags' and has a lifetime
2356 * identical to it (and the query to which it ultimately belongs).
2358 * See the documentation of notmuch_message_get_tags for example code
2359 * showing how to iterate over a notmuch_tags_t object.
2362 notmuch_tags_get (notmuch_tags_t *tags);
2365 * Move the 'tags' iterator to the next tag.
2367 * If 'tags' is already pointing at the last tag then the iterator
2368 * will be moved to a point just beyond that last tag, (where
2369 * notmuch_tags_valid will return FALSE and notmuch_tags_get will
2372 * See the documentation of notmuch_message_get_tags for example code
2373 * showing how to iterate over a notmuch_tags_t object.
2376 notmuch_tags_move_to_next (notmuch_tags_t *tags);
2379 * Destroy a notmuch_tags_t object.
2381 * It's not strictly necessary to call this function. All memory from
2382 * the notmuch_tags_t object will be reclaimed when the containing
2383 * message or query objects are destroyed.
2386 notmuch_tags_destroy (notmuch_tags_t *tags);
2389 * Store an mtime within the database for 'directory'.
2391 * The 'directory' should be an object retrieved from the database
2392 * with notmuch_database_get_directory for a particular path.
2394 * The intention is for the caller to use the mtime to allow efficient
2395 * identification of new messages to be added to the database. The
2396 * recommended usage is as follows:
2398 * o Read the mtime of a directory from the filesystem
2400 * o Call index_file for all mail files in the directory
2402 * o Call notmuch_directory_set_mtime with the mtime read from the
2405 * Then, when wanting to check for updates to the directory in the
2406 * future, the client can call notmuch_directory_get_mtime and know
2407 * that it only needs to add files if the mtime of the directory and
2408 * files are newer than the stored timestamp.
2410 * Note: The notmuch_directory_get_mtime function does not allow the
2411 * caller to distinguish a timestamp of 0 from a non-existent
2412 * timestamp. So don't store a timestamp of 0 unless you are
2413 * comfortable with that.
2417 * NOTMUCH_STATUS_SUCCESS: mtime successfully stored in database.
2419 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception
2420 * occurred, mtime not stored.
2422 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
2423 * mode so directory mtime cannot be modified.
2426 notmuch_directory_set_mtime (notmuch_directory_t *directory,
2430 * Get the mtime of a directory, (as previously stored with
2431 * notmuch_directory_set_mtime).
2433 * Returns 0 if no mtime has previously been stored for this
2437 notmuch_directory_get_mtime (notmuch_directory_t *directory);
2440 * Get a notmuch_filenames_t iterator listing all the filenames of
2441 * messages in the database within the given directory.
2443 * The returned filenames will be the basename-entries only (not
2446 * Returns NULL if it triggers a Xapian exception
2448 notmuch_filenames_t *
2449 notmuch_directory_get_child_files (notmuch_directory_t *directory);
2452 * Get a notmuch_filenames_t iterator listing all the filenames of
2453 * sub-directories in the database within the given directory.
2455 * The returned filenames will be the basename-entries only (not
2458 * Returns NULL if it triggers a Xapian exception
2460 notmuch_filenames_t *
2461 notmuch_directory_get_child_directories (notmuch_directory_t *directory);
2464 * Delete directory document from the database, and destroy the
2465 * notmuch_directory_t object. Assumes any child directories and files
2466 * have been deleted by the caller.
2468 * @since libnotmuch 4.3 (notmuch 0.21)
2471 notmuch_directory_delete (notmuch_directory_t *directory);
2474 * Destroy a notmuch_directory_t object.
2477 notmuch_directory_destroy (notmuch_directory_t *directory);
2480 * Is the given 'filenames' iterator pointing at a valid filename.
2482 * When this function returns TRUE, notmuch_filenames_get will return
2483 * a valid string. Whereas when this function returns FALSE,
2484 * notmuch_filenames_get will return NULL.
2486 * It is acceptable to pass NULL for 'filenames', in which case this
2487 * function will always return FALSE.
2490 notmuch_filenames_valid (notmuch_filenames_t *filenames);
2493 * Get the current filename from 'filenames' as a string.
2495 * Note: The returned string belongs to 'filenames' and has a lifetime
2496 * identical to it (and the directory to which it ultimately belongs).
2498 * It is acceptable to pass NULL for 'filenames', in which case this
2499 * function will always return NULL.
2502 notmuch_filenames_get (notmuch_filenames_t *filenames);
2505 * Move the 'filenames' iterator to the next filename.
2507 * If 'filenames' is already pointing at the last filename then the
2508 * iterator will be moved to a point just beyond that last filename,
2509 * (where notmuch_filenames_valid will return FALSE and
2510 * notmuch_filenames_get will return NULL).
2512 * It is acceptable to pass NULL for 'filenames', in which case this
2513 * function will do nothing.
2516 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
2519 * Destroy a notmuch_filenames_t object.
2521 * It's not strictly necessary to call this function. All memory from
2522 * the notmuch_filenames_t object will be reclaimed when the
2523 * containing directory object is destroyed.
2525 * It is acceptable to pass NULL for 'filenames', in which case this
2526 * function will do nothing.
2529 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
2533 * set config 'key' to 'value'
2535 * @since libnotmuch 4.4 (notmuch 0.23)
2536 * @retval #NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
2537 * read-only mode so message cannot be modified.
2538 * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION: an exception was thrown
2539 * accessing the database.
2540 * @retval #NOTMUCH_STATUS_SUCCESS
2543 notmuch_database_set_config (notmuch_database_t *db, const char *key, const char *value);
2546 * retrieve config item 'key', assign to 'value'
2548 * keys which have not been previously set with n_d_set_config will
2549 * return an empty string.
2551 * return value is allocated by malloc and should be freed by the
2554 * @since libnotmuch 4.4 (notmuch 0.23)
2558 notmuch_database_get_config (notmuch_database_t *db, const char *key, char **value);
2561 * Create an iterator for all config items with keys matching a given prefix
2563 * @since libnotmuch 4.4 (notmuch 0.23)
2566 notmuch_database_get_config_list (notmuch_database_t *db, const char *prefix,
2567 notmuch_config_list_t **out);
2570 * Is 'config_list' iterator valid (i.e. _key, _value, _move_to_next can be called).
2572 * @since libnotmuch 4.4 (notmuch 0.23)
2575 notmuch_config_list_valid (notmuch_config_list_t *config_list);
2578 * return key for current config pair
2580 * return value is owned by the iterator, and will be destroyed by the
2581 * next call to notmuch_config_list_key or notmuch_config_list_destroy.
2583 * @since libnotmuch 4.4 (notmuch 0.23)
2586 notmuch_config_list_key (notmuch_config_list_t *config_list);
2589 * return 'value' for current config pair
2591 * return value is owned by the iterator, and will be destroyed by the
2592 * next call to notmuch_config_list_value or notmuch config_list_destroy
2594 * @since libnotmuch 4.4 (notmuch 0.23)
2595 * @retval NULL for errors
2598 notmuch_config_list_value (notmuch_config_list_t *config_list);
2602 * move 'config_list' iterator to the next pair
2604 * @since libnotmuch 4.4 (notmuch 0.23)
2607 notmuch_config_list_move_to_next (notmuch_config_list_t *config_list);
2610 * free any resources held by 'config_list'
2612 * @since libnotmuch 4.4 (notmuch 0.23)
2615 notmuch_config_list_destroy (notmuch_config_list_t *config_list);
2618 * Configuration keys known to libnotmuch
2621 NOTMUCH_CONFIG_FIRST,
2622 NOTMUCH_CONFIG_DATABASE_PATH = NOTMUCH_CONFIG_FIRST,
2623 NOTMUCH_CONFIG_MAIL_ROOT,
2624 NOTMUCH_CONFIG_HOOK_DIR,
2625 NOTMUCH_CONFIG_BACKUP_DIR,
2626 NOTMUCH_CONFIG_EXCLUDE_TAGS,
2627 NOTMUCH_CONFIG_NEW_TAGS,
2628 NOTMUCH_CONFIG_NEW_IGNORE,
2629 NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS,
2630 NOTMUCH_CONFIG_PRIMARY_EMAIL,
2631 NOTMUCH_CONFIG_OTHER_EMAIL,
2632 NOTMUCH_CONFIG_USER_NAME,
2633 NOTMUCH_CONFIG_AUTOCOMMIT,
2634 NOTMUCH_CONFIG_EXTRA_HEADERS,
2635 NOTMUCH_CONFIG_INDEX_AS_TEXT,
2636 NOTMUCH_CONFIG_AUTHORS_SEPARATOR,
2637 NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR,
2639 } notmuch_config_key_t;
2642 * get a configuration value from an open database.
2644 * This value reflects all configuration information given at the time
2645 * the database was opened.
2647 * @param[in] notmuch database
2648 * @param[in] key configuration key
2650 * @since libnotmuch 5.4 (notmuch 0.32)
2652 * @retval NULL if 'key' unknown or if no value is known for
2653 * 'key'. Otherwise returns a string owned by notmuch which should
2654 * not be modified nor freed by the caller.
2657 notmuch_config_get (notmuch_database_t *notmuch, notmuch_config_key_t key);
2660 * set a configuration value from in an open database.
2662 * This value reflects all configuration information given at the time
2663 * the database was opened.
2665 * @param[in,out] notmuch database open read/write
2666 * @param[in] key configuration key
2667 * @param[in] val configuration value
2669 * @since libnotmuch 5.4 (notmuch 0.32)
2671 * @retval returns any return value for notmuch_database_set_config.
2674 notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val);
2677 * Returns an iterator for a ';'-delimited list of configuration values
2679 * These values reflect all configuration information given at the
2680 * time the database was opened.
2682 * @param[in] notmuch database
2683 * @param[in] key configuration key
2685 * @since libnotmuch 5.4 (notmuch 0.32)
2687 * @retval NULL in case of error.
2689 notmuch_config_values_t *
2690 notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key);
2693 * Returns an iterator for a ';'-delimited list of configuration values
2695 * These values reflect all configuration information given at the
2696 * time the database was opened.
2698 * @param[in] notmuch database
2699 * @param[in] key configuration key
2701 * @since libnotmuch 5.4 (notmuch 0.32)
2703 * @retval NULL in case of error.
2705 notmuch_config_values_t *
2706 notmuch_config_get_values_string (notmuch_database_t *notmuch, const char *key);
2709 * Is the given 'config_values' iterator pointing at a valid element.
2711 * @param[in] values iterator
2713 * @since libnotmuch 5.4 (notmuch 0.32)
2715 * @retval FALSE if passed a NULL pointer, or the iterator is exhausted.
2719 notmuch_config_values_valid (notmuch_config_values_t *values);
2722 * Get the current value from the 'values' iterator
2724 * @param[in] values iterator
2726 * @since libnotmuch 5.4 (notmuch 0.32)
2728 * @retval a string with the same lifetime as the iterator
2731 notmuch_config_values_get (notmuch_config_values_t *values);
2734 * Move the 'values' iterator to the next element
2736 * @param[in,out] values iterator
2738 * @since libnotmuch 5.4 (notmuch 0.32)
2742 notmuch_config_values_move_to_next (notmuch_config_values_t *values);
2746 * reset the 'values' iterator to the first element
2748 * @param[in,out] values iterator. A NULL value is ignored.
2750 * @since libnotmuch 5.4 (notmuch 0.32)
2754 notmuch_config_values_start (notmuch_config_values_t *values);
2757 * Destroy a config values iterator, along with any associated
2760 * @param[in,out] values iterator
2762 * @since libnotmuch 5.4 (notmuch 0.32)
2765 notmuch_config_values_destroy (notmuch_config_values_t *values);
2769 * Returns an iterator for a (key, value) configuration pairs
2771 * @param[in] notmuch database
2772 * @param[in] prefix prefix for keys. Pass "" for all keys.
2774 * @since libnotmuch 5.4 (notmuch 0.32)
2776 * @retval NULL in case of error.
2778 notmuch_config_pairs_t *
2779 notmuch_config_get_pairs (notmuch_database_t *notmuch,
2780 const char *prefix);
2783 * Is the given 'config_pairs' iterator pointing at a valid element.
2785 * @param[in] pairs iterator
2787 * @since libnotmuch 5.4 (notmuch 0.32)
2789 * @retval FALSE if passed a NULL pointer, or the iterator is exhausted.
2793 notmuch_config_pairs_valid (notmuch_config_pairs_t *pairs);
2796 * Move the 'config_pairs' iterator to the next element
2798 * @param[in,out] pairs iterator
2800 * @since libnotmuch 5.4 (notmuch 0.32)
2804 notmuch_config_pairs_move_to_next (notmuch_config_pairs_t *pairs);
2807 * Get the current key from the 'config_pairs' iterator
2809 * @param[in] pairs iterator
2811 * @since libnotmuch 5.4 (notmuch 0.32)
2813 * @retval a string with the same lifetime as the iterator
2816 notmuch_config_pairs_key (notmuch_config_pairs_t *pairs);
2819 * Get the current value from the 'config_pairs' iterator
2821 * @param[in] pairs iterator
2823 * @since libnotmuch 5.4 (notmuch 0.32)
2825 * @retval a string with the same lifetime as the iterator
2828 notmuch_config_pairs_value (notmuch_config_pairs_t *pairs);
2831 * Destroy a config_pairs iterator, along with any associated
2834 * @param[in,out] pairs iterator
2836 * @since libnotmuch 5.4 (notmuch 0.32)
2839 notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs);
2842 * get a configuration value from an open database as Boolean
2844 * This value reflects all configuration information given at the time
2845 * the database was opened.
2847 * @param[in] notmuch database
2848 * @param[in] key configuration key
2849 * @param[out] val configuration value, converted to Boolean
2851 * @since libnotmuch 5.4 (notmuch 0.32)
2853 * @retval #NOTMUCH_STATUS_ILLEGAL_ARGUMENT if either key is unknown
2854 * or the corresponding value does not convert to Boolean.
2857 notmuch_config_get_bool (notmuch_database_t *notmuch,
2858 notmuch_config_key_t key,
2859 notmuch_bool_t *val);
2862 * return the path of the config file loaded, if any
2864 * @retval NULL if no config file was loaded
2867 notmuch_config_path (notmuch_database_t *notmuch);
2870 * get the current default indexing options for a given database.
2872 * This object will survive until the database itself is destroyed,
2873 * but the caller may also release it earlier with
2874 * notmuch_indexopts_destroy.
2876 * This object represents a set of options on how a message can be
2877 * added to the index. At the moment it is a featureless stub.
2879 * @since libnotmuch 5.1 (notmuch 0.26)
2880 * @retval NULL in case of error
2882 notmuch_indexopts_t *
2883 notmuch_database_get_default_indexopts (notmuch_database_t *db);
2886 * Stating a policy about how to decrypt messages.
2888 * See index.decrypt in notmuch-config(1) for more details.
2891 NOTMUCH_DECRYPT_FALSE,
2892 NOTMUCH_DECRYPT_TRUE,
2893 NOTMUCH_DECRYPT_AUTO,
2894 NOTMUCH_DECRYPT_NOSTASH,
2895 } notmuch_decryption_policy_t;
2898 * Specify whether to decrypt encrypted parts while indexing.
2900 * Be aware that the index is likely sufficient to reconstruct the
2901 * cleartext of the message itself, so please ensure that the notmuch
2902 * message index is adequately protected. DO NOT SET THIS FLAG TO TRUE
2903 * without considering the security of your index.
2905 * @since libnotmuch 5.1 (notmuch 0.26)
2908 notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
2909 notmuch_decryption_policy_t decrypt_policy);
2912 * Return whether to decrypt encrypted parts while indexing.
2913 * see notmuch_indexopts_set_decrypt_policy.
2915 * @since libnotmuch 5.1 (notmuch 0.26)
2917 notmuch_decryption_policy_t
2918 notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts);
2921 * Destroy a notmuch_indexopts_t object.
2923 * @since libnotmuch 5.1 (notmuch 0.26)
2926 notmuch_indexopts_destroy (notmuch_indexopts_t *options);
2930 * interrogate the library for compile time features
2932 * @since libnotmuch 4.4 (notmuch 0.23)
2935 notmuch_built_with (const char *name);
2938 #pragma GCC visibility pop