]> git.notmuchmail.org Git - notmuch/blob - lib/notmuch.h
lib: add notmuch_config_get_bool
[notmuch] / lib / notmuch.h
1 /* notmuch - Not much of an email library, (just index and search)
2  *
3  * Copyright © 2009 Carl Worth
4  *
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.
9  *
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.
14  *
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/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 /**
22  * @defgroup notmuch The notmuch API
23  *
24  * Not much of an email library, (just index and search)
25  *
26  * @{
27  */
28
29 #ifndef NOTMUCH_H
30 #define NOTMUCH_H
31
32 #ifndef __DOXYGEN__
33
34 #ifdef  __cplusplus
35 # define NOTMUCH_BEGIN_DECLS  extern "C" {
36 # define NOTMUCH_END_DECLS    }
37 #else
38 # define NOTMUCH_BEGIN_DECLS
39 # define NOTMUCH_END_DECLS
40 #endif
41
42 NOTMUCH_BEGIN_DECLS
43
44 #include <time.h>
45
46 #pragma GCC visibility push(default)
47
48 #ifndef FALSE
49 #define FALSE 0
50 #endif
51
52 #ifndef TRUE
53 #define TRUE 1
54 #endif
55
56 /*
57  * The library version number.  This must agree with the soname
58  * version in Makefile.local.
59  */
60 #define LIBNOTMUCH_MAJOR_VERSION        5
61 #define LIBNOTMUCH_MINOR_VERSION        3
62 #define LIBNOTMUCH_MICRO_VERSION        0
63
64
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)))
70 #else
71 #define NOTMUCH_DEPRECATED(major, minor) __attribute__ ((deprecated))
72 #endif
73
74
75 #endif /* __DOXYGEN__ */
76
77 /**
78  * Check the version of the notmuch library being compiled against.
79  *
80  * Return true if the library being compiled against is of the
81  * specified version or above. For example:
82  *
83  * @code
84  * #if LIBNOTMUCH_CHECK_VERSION(3, 1, 0)
85  *     (code requiring libnotmuch 3.1.0 or above)
86  * #endif
87  * @endcode
88  *
89  * LIBNOTMUCH_CHECK_VERSION has been defined since version 3.1.0; to
90  * check for versions prior to that, use:
91  *
92  * @code
93  * #if !defined(NOTMUCH_CHECK_VERSION)
94  *     (code requiring libnotmuch prior to 3.1.0)
95  * #endif
96  * @endcode
97  */
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)))
103
104 /**
105  * Notmuch boolean type.
106  */
107 typedef int notmuch_bool_t;
108
109 /**
110  * Status codes used for the return values of most functions.
111  *
112  * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
113  * completed without error. Any other value indicates an error.
114  */
115 typedef enum _notmuch_status {
116     /**
117      * No error occurred.
118      */
119     NOTMUCH_STATUS_SUCCESS = 0,
120     /**
121      * Out of memory.
122      */
123     NOTMUCH_STATUS_OUT_OF_MEMORY,
124     /**
125      * An attempt was made to write to a database opened in read-only
126      * mode.
127      */
128     NOTMUCH_STATUS_READ_ONLY_DATABASE,
129     /**
130      * A Xapian exception occurred.
131      *
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
134      * whatever.
135      */
136     NOTMUCH_STATUS_XAPIAN_EXCEPTION,
137     /**
138      * An error occurred trying to read or write to a file (this could
139      * be file not found, permission denied, etc.)
140      */
141     NOTMUCH_STATUS_FILE_ERROR,
142     /**
143      * A file was presented that doesn't appear to be an email
144      * message.
145      */
146     NOTMUCH_STATUS_FILE_NOT_EMAIL,
147     /**
148      * A file contains a message ID that is identical to a message
149      * already in the database.
150      */
151     NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
152     /**
153      * The user erroneously passed a NULL pointer to a notmuch
154      * function.
155      */
156     NOTMUCH_STATUS_NULL_POINTER,
157     /**
158      * A tag value is too long (exceeds NOTMUCH_TAG_MAX).
159      */
160     NOTMUCH_STATUS_TAG_TOO_LONG,
161     /**
162      * The notmuch_message_thaw function has been called more times
163      * than notmuch_message_freeze.
164      */
165     NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
166     /**
167      * notmuch_database_end_atomic has been called more times than
168      * notmuch_database_begin_atomic.
169      */
170     NOTMUCH_STATUS_UNBALANCED_ATOMIC,
171     /**
172      * The operation is not supported.
173      */
174     NOTMUCH_STATUS_UNSUPPORTED_OPERATION,
175     /**
176      * The operation requires a database upgrade.
177      */
178     NOTMUCH_STATUS_UPGRADE_REQUIRED,
179     /**
180      * There is a problem with the proposed path, e.g. a relative path
181      * passed to a function expecting an absolute path.
182      */
183     NOTMUCH_STATUS_PATH_ERROR,
184     /**
185      * The requested operation was ignored. Depending on the function,
186      * this may not be an actual error.
187      */
188     NOTMUCH_STATUS_IGNORED,
189     /**
190      * One of the arguments violates the preconditions for the
191      * function, in a way not covered by a more specific argument.
192      */
193     NOTMUCH_STATUS_ILLEGAL_ARGUMENT,
194     /**
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.
198      */
199     NOTMUCH_STATUS_MALFORMED_CRYPTO_PROTOCOL,
200     /**
201      * Notmuch attempted to do crypto processing, but could not
202      * initialize the engine needed to do so.
203      */
204     NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION,
205     /**
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.
209      */
210     NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL,
211     /**
212      * Not an actual status value. Just a way to find out how many
213      * valid status values there are.
214      */
215     NOTMUCH_STATUS_LAST_STATUS
216 } notmuch_status_t;
217
218 /**
219  * Get a string representation of a notmuch_status_t value.
220  *
221  * The result is read-only.
222  */
223 const char *
224 notmuch_status_to_string (notmuch_status_t status);
225
226 /* Various opaque data types. For each notmuch_<foo>_t see the various
227  * notmuch_<foo> functions below. */
228 #ifndef __DOXYGEN__
229 typedef struct _notmuch_database notmuch_database_t;
230 typedef struct _notmuch_query notmuch_query_t;
231 typedef struct _notmuch_threads notmuch_threads_t;
232 typedef struct _notmuch_thread notmuch_thread_t;
233 typedef struct _notmuch_messages notmuch_messages_t;
234 typedef struct _notmuch_message notmuch_message_t;
235 typedef struct _notmuch_tags notmuch_tags_t;
236 typedef struct _notmuch_directory notmuch_directory_t;
237 typedef struct _notmuch_filenames notmuch_filenames_t;
238 typedef struct _notmuch_config_list notmuch_config_list_t;
239 typedef struct _notmuch_config_values notmuch_config_values_t;
240 typedef struct _notmuch_indexopts notmuch_indexopts_t;
241 #endif /* __DOXYGEN__ */
242
243 /**
244  * Create a new, empty notmuch database located at 'path'.
245  *
246  * The path should be a top-level directory to a collection of
247  * plain-text email messages (one message per file). This call will
248  * create a new ".notmuch" directory within 'path' where notmuch will
249  * store its data.
250  *
251  * After a successful call to notmuch_database_create, the returned
252  * database will be open so the caller should call
253  * notmuch_database_destroy when finished with it.
254  *
255  * The database will not yet have any data in it
256  * (notmuch_database_create itself is a very cheap function). Messages
257  * contained within 'path' can be added to the database by calling
258  * notmuch_database_index_file.
259  *
260  * In case of any failure, this function returns an error status and
261  * sets *database to NULL (after printing an error message on stderr).
262  *
263  * Return value:
264  *
265  * NOTMUCH_STATUS_SUCCESS: Successfully created the database.
266  *
267  * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.
268  *
269  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
270  *
271  * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to create the
272  *      database file (such as permission denied, or file not found,
273  *      etc.), or the database already exists.
274  *
275  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
276  */
277 notmuch_status_t
278 notmuch_database_create (const char *path, notmuch_database_t **database);
279
280 /**
281  * Like notmuch_database_create, except optionally return an error
282  * message. This message is allocated by malloc and should be freed by
283  * the caller.
284  */
285 notmuch_status_t
286 notmuch_database_create_verbose (const char *path,
287                                  notmuch_database_t **database,
288                                  char **error_message);
289
290 /**
291  * Database open mode for notmuch_database_open.
292  */
293 typedef enum {
294     /**
295      * Open database for reading only.
296      */
297     NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
298     /**
299      * Open database for reading and writing.
300      */
301     NOTMUCH_DATABASE_MODE_READ_WRITE
302 } notmuch_database_mode_t;
303
304 /**
305  * Deprecated alias for notmuch_database_open_with_config with
306  * config_path=error_message=NULL
307  * @deprecated Deprecated as of libnotmuch 5.4 (notmuch 0.32)
308  */
309 /* NOTMUCH_DEPRECATED(5, 4) */
310 notmuch_status_t
311 notmuch_database_open (const char *path,
312                        notmuch_database_mode_t mode,
313                        notmuch_database_t **database);
314 /**
315  * Deprecated alias for notmuch_database_open_with_config with
316  * config_path=NULL
317  *
318  * @deprecated Deprecated as of libnotmuch 5.4 (notmuch 0.32)
319  *
320  */
321 /* NOTMUCH_DEPRECATED(5, 4) */
322 notmuch_status_t
323 notmuch_database_open_verbose (const char *path,
324                                notmuch_database_mode_t mode,
325                                notmuch_database_t **database,
326                                char **error_message);
327
328 /**
329  * Open an existing notmuch database located at 'database_path', using
330  * configuration in 'config_path'.
331  *
332  * @param[in]   database_path
333  * @parblock
334  * Path to existing database.
335  *
336  * A notmuch database is a Xapian database containing appropriate
337  * metadata.
338  *
339  * The database should have been created at some time in the past,
340  * (not necessarily by this process), by calling
341  * notmuch_database_create.
342  *
343  * If 'database_path' is NULL, use the location specified
344  *
345  * - in the environment variable NOTMUCH_DATABASE, if non-empty
346  *
347  * - in a configuration file, located as described under 'config_path'
348  *
349  * - by $XDG_DATA_HOME/notmuch/$PROFILE where XDG_DATA_HOME defaults
350  *   to "$HOME/.local/share" and PROFILE as as discussed in
351  *   'profile'
352  *
353  * If 'database_path' is non-NULL, but does not appear to be a Xapian
354  * database, check for a directory '.notmuch/xapian' below
355  * 'database_path' (this is the behavior of
356  * notmuch_database_open_verbose pre-0.32).
357  *
358  * @endparblock
359  * @param[in]   mode
360  * @parblock
361  * Mode to open database. Use one of #NOTMUCH_DATABASE_MODE_READ_WRITE
362  * or #NOTMUCH_DATABASE_MODE_READ_ONLY
363  *
364  * @endparblock
365  * @param[in]  config_path
366  * @parblock
367  * Path to config file.
368  *
369  * Config file is key-value, with mandatory sections. See
370  * <em>notmuch-config(5)</em> for more information. The key-value pair
371  * overrides the corresponding configuration data stored in the
372  * database (see <em>notmuch_database_get_config</em>)
373  *
374  * If <em>config_path</em> is NULL use the path specified
375  *
376  * - in environment variable <em>NOTMUCH_CONFIG</em>, if non-empty
377  *
378  * - by  <em>XDG_CONFIG_HOME</em>/notmuch/ where
379  *   XDG_CONFIG_HOME defaults to "$HOME/.config".
380  *
381  * - by $HOME/.notmuch-config
382  *
383  * If <em>config_path</em> is "" (empty string) then do not
384  * open any configuration file.
385  * @endparblock
386  * @param[in] profile:
387  * @parblock
388  * Name of profile (configuration/database variant).
389  *
390  * If non-NULL, append to the directory / file path determined for
391  * <em>config_path</em> and <em>database_path</em>.
392  *
393  * If NULL then use
394  * - environment variable NOTMUCH_PROFILE if defined,
395  * - otherwise "default" for directories and "" (empty string) for paths.
396  *
397  * @endparblock
398  * @param[out] database
399  * @parblock
400  * Pointer to database object. May not be NULL.
401  *
402  * The caller should call notmuch_database_destroy when finished with
403  * this database.
404  *
405  * In case of any failure, this function returns an error status and
406  * sets *database to NULL.
407  *
408  * @endparblock
409  * @param[out] error_message
410  * If non-NULL, store error message from opening the database.
411  * Any such message is allocated by \a malloc(3) and should be freed
412  * by the caller.
413  *
414  * @retval NOTMUCH_STATUS_SUCCESS: Successfully opened the database.
415  *
416  * @retval NOTMUCH_STATUS_NULL_POINTER: The given \a database
417  * argument is NULL.
418  *
419  * @retval NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
420  *
421  * @retval NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
422  *      database or config file (such as permission denied, or file not found,
423  *      etc.), or the database version is unknown.
424  *
425  * @retval NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
426  *
427  * @since libnotmuch 5.4 (notmuch 0.32)
428  */
429
430 notmuch_status_t
431 notmuch_database_open_with_config (const char *database_path,
432                                    notmuch_database_mode_t mode,
433                                    const char *config_path,
434                                    const char *profile,
435                                    notmuch_database_t **database,
436                                    char **error_message);
437
438 /**
439  * Retrieve last status string for given database.
440  *
441  */
442 const char *
443 notmuch_database_status_string (const notmuch_database_t *notmuch);
444
445 /**
446  * Commit changes and close the given notmuch database.
447  *
448  * After notmuch_database_close has been called, calls to other
449  * functions on objects derived from this database may either behave
450  * as if the database had not been closed (e.g., if the required data
451  * has been cached) or may fail with a
452  * NOTMUCH_STATUS_XAPIAN_EXCEPTION. The only further operation
453  * permitted on the database itself is to call
454  * notmuch_database_destroy.
455  *
456  * notmuch_database_close can be called multiple times.  Later calls
457  * have no effect.
458  *
459  * For writable databases, notmuch_database_close commits all changes
460  * to disk before closing the database.  If the caller is currently in
461  * an atomic section (there was a notmuch_database_begin_atomic
462  * without a matching notmuch_database_end_atomic), this will discard
463  * changes made in that atomic section (but still commit changes made
464  * prior to entering the atomic section).
465  *
466  * Return value:
467  *
468  * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.
469  *
470  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred; the
471  *      database has been closed but there are no guarantees the
472  *      changes to the database, if any, have been flushed to disk.
473  */
474 notmuch_status_t
475 notmuch_database_close (notmuch_database_t *database);
476
477 /**
478  * A callback invoked by notmuch_database_compact to notify the user
479  * of the progress of the compaction process.
480  */
481 typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure);
482
483 /**
484  * Compact a notmuch database, backing up the original database to the
485  * given path.
486  *
487  * The database will be opened with NOTMUCH_DATABASE_MODE_READ_WRITE
488  * during the compaction process to ensure no writes are made.
489  *
490  * If the optional callback function 'status_cb' is non-NULL, it will
491  * be called with diagnostic and informational messages. The argument
492  * 'closure' is passed verbatim to any callback invoked.
493  */
494 notmuch_status_t
495 notmuch_database_compact (const char *path,
496                           const char *backup_path,
497                           notmuch_compact_status_cb_t status_cb,
498                           void *closure);
499
500 /**
501  * Destroy the notmuch database, closing it if necessary and freeing
502  * all associated resources.
503  *
504  * Return value as in notmuch_database_close if the database was open;
505  * notmuch_database_destroy itself has no failure modes.
506  */
507 notmuch_status_t
508 notmuch_database_destroy (notmuch_database_t *database);
509
510 /**
511  * Return the database path of the given database.
512  *
513  * The return value is a string owned by notmuch so should not be
514  * modified nor freed by the caller.
515  */
516 const char *
517 notmuch_database_get_path (notmuch_database_t *database);
518
519 /**
520  * Return the database format version of the given database.
521  *
522  * @retval 0 on error
523  */
524 unsigned int
525 notmuch_database_get_version (notmuch_database_t *database);
526
527 /**
528  * Can the database be upgraded to a newer database version?
529  *
530  * If this function returns TRUE, then the caller may call
531  * notmuch_database_upgrade to upgrade the database.  If the caller
532  * does not upgrade an out-of-date database, then some functions may
533  * fail with NOTMUCH_STATUS_UPGRADE_REQUIRED.  This always returns
534  * FALSE for a read-only database because there's no way to upgrade a
535  * read-only database.
536  *
537  * Also returns FALSE if an error occurs accessing the database.
538  *
539  */
540 notmuch_bool_t
541 notmuch_database_needs_upgrade (notmuch_database_t *database);
542
543 /**
544  * Upgrade the current database to the latest supported version.
545  *
546  * This ensures that all current notmuch functionality will be
547  * available on the database.  After opening a database in read-write
548  * mode, it is recommended that clients check if an upgrade is needed
549  * (notmuch_database_needs_upgrade) and if so, upgrade with this
550  * function before making any modifications.  If
551  * notmuch_database_needs_upgrade returns FALSE, this will be a no-op.
552  *
553  * The optional progress_notify callback can be used by the caller to
554  * provide progress indication to the user. If non-NULL it will be
555  * called periodically with 'progress' as a floating-point value in
556  * the range of [0.0 .. 1.0] indicating the progress made so far in
557  * the upgrade process.  The argument 'closure' is passed verbatim to
558  * any callback invoked.
559  */
560 notmuch_status_t
561 notmuch_database_upgrade (notmuch_database_t *database,
562                           void (*progress_notify)(void *closure,
563                                                   double progress),
564                           void *closure);
565
566 /**
567  * Begin an atomic database operation.
568  *
569  * Any modifications performed between a successful begin and a
570  * notmuch_database_end_atomic will be applied to the database
571  * atomically.  Note that, unlike a typical database transaction, this
572  * only ensures atomicity, not durability; neither begin nor end
573  * necessarily flush modifications to disk.
574  *
575  * Atomic sections may be nested.  begin_atomic and end_atomic must
576  * always be called in pairs.
577  *
578  * Return value:
579  *
580  * NOTMUCH_STATUS_SUCCESS: Successfully entered atomic section.
581  *
582  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
583  *      atomic section not entered.
584  */
585 notmuch_status_t
586 notmuch_database_begin_atomic (notmuch_database_t *notmuch);
587
588 /**
589  * Indicate the end of an atomic database operation.
590  *
591  * Return value:
592  *
593  * NOTMUCH_STATUS_SUCCESS: Successfully completed atomic section.
594  *
595  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
596  *      atomic section not ended.
597  *
598  * NOTMUCH_STATUS_UNBALANCED_ATOMIC: The database is not currently in
599  *      an atomic section.
600  */
601 notmuch_status_t
602 notmuch_database_end_atomic (notmuch_database_t *notmuch);
603
604 /**
605  * Return the committed database revision and UUID.
606  *
607  * The database revision number increases monotonically with each
608  * commit to the database.  Hence, all messages and message changes
609  * committed to the database (that is, visible to readers) have a last
610  * modification revision <= the committed database revision.  Any
611  * messages committed in the future will be assigned a modification
612  * revision > the committed database revision.
613  *
614  * The UUID is a NUL-terminated opaque string that uniquely identifies
615  * this database.  Two revision numbers are only comparable if they
616  * have the same database UUID.
617  */
618 unsigned long
619 notmuch_database_get_revision (notmuch_database_t *notmuch,
620                                const char **uuid);
621
622 /**
623  * Retrieve a directory object from the database for 'path'.
624  *
625  * Here, 'path' should be a path relative to the path of 'database'
626  * (see notmuch_database_get_path), or else should be an absolute path
627  * with initial components that match the path of 'database'.
628  *
629  * If this directory object does not exist in the database, this
630  * returns NOTMUCH_STATUS_SUCCESS and sets *directory to NULL.
631  *
632  * Otherwise the returned directory object is owned by the database
633  * and as such, will only be valid until notmuch_database_destroy is
634  * called.
635  *
636  * Return value:
637  *
638  * NOTMUCH_STATUS_SUCCESS: Successfully retrieved directory.
639  *
640  * NOTMUCH_STATUS_NULL_POINTER: The given 'directory' argument is NULL.
641  *
642  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
643  *      directory not retrieved.
644  *
645  * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
646  *      database to use this function.
647  */
648 notmuch_status_t
649 notmuch_database_get_directory (notmuch_database_t *database,
650                                 const char *path,
651                                 notmuch_directory_t **directory);
652
653 /**
654  * Add a message file to a database, indexing it for retrieval by
655  * future searches.  If a message already exists with the same message
656  * ID as the specified file, their indexes will be merged, and this
657  * new filename will also be associated with the existing message.
658  *
659  * Here, 'filename' should be a path relative to the path of
660  * 'database' (see notmuch_database_get_path), or else should be an
661  * absolute filename with initial components that match the path of
662  * 'database'.
663  *
664  * The file should be a single mail message (not a multi-message mbox)
665  * that is expected to remain at its current location, (since the
666  * notmuch database will reference the filename, and will not copy the
667  * entire contents of the file.
668  *
669  * If another message with the same message ID already exists in the
670  * database, rather than creating a new message, this adds the search
671  * terms from the identified file to the existing message's index, and
672  * adds 'filename' to the list of filenames known for the message.
673  *
674  * The 'indexopts' parameter can be NULL (meaning, use the indexing
675  * defaults from the database), or can be an explicit choice of
676  * indexing options that should govern the indexing of this specific
677  * 'filename'.
678  *
679  * If 'message' is not NULL, then, on successful return
680  * (NOTMUCH_STATUS_SUCCESS or NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) '*message'
681  * will be initialized to a message object that can be used for things
682  * such as adding tags to the just-added message. The user should call
683  * notmuch_message_destroy when done with the message. On any failure
684  * '*message' will be set to NULL.
685  *
686  * Return value:
687  *
688  * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
689  *
690  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
691  *      message not added.
692  *
693  * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
694  *      ID as another message already in the database. The new
695  *      filename was successfully added to the message in the database
696  *      (if not already present) and the existing message is returned.
697  *
698  * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the
699  *      file, (such as permission denied, or file not found,
700  *      etc.). Nothing added to the database.
701  *
702  * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
703  *      like an email message. Nothing added to the database.
704  *
705  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
706  *      mode so no message can be added.
707  *
708  * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
709  *      database to use this function.
710  *
711  * @since libnotmuch 5.1 (notmuch 0.26)
712  */
713 notmuch_status_t
714 notmuch_database_index_file (notmuch_database_t *database,
715                              const char *filename,
716                              notmuch_indexopts_t *indexopts,
717                              notmuch_message_t **message);
718
719 /**
720  * Deprecated alias for notmuch_database_index_file called with
721  * NULL indexopts.
722  *
723  * @deprecated Deprecated as of libnotmuch 5.1 (notmuch 0.26). Please
724  * use notmuch_database_index_file instead.
725  *
726  */
727 NOTMUCH_DEPRECATED (5, 1)
728 notmuch_status_t
729 notmuch_database_add_message (notmuch_database_t *database,
730                               const char *filename,
731                               notmuch_message_t **message);
732
733 /**
734  * Remove a message filename from the given notmuch database. If the
735  * message has no more filenames, remove the message.
736  *
737  * If the same message (as determined by the message ID) is still
738  * available via other filenames, then the message will persist in the
739  * database for those filenames. When the last filename is removed for
740  * a particular message, the database content for that message will be
741  * entirely removed.
742  *
743  * Return value:
744  *
745  * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the
746  *      message was removed from the database.
747  *
748  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
749  *      message not removed.
750  *
751  * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but
752  *      the message persists in the database with at least one other
753  *      filename.
754  *
755  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
756  *      mode so no message can be removed.
757  *
758  * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
759  *      database to use this function.
760  */
761 notmuch_status_t
762 notmuch_database_remove_message (notmuch_database_t *database,
763                                  const char *filename);
764
765 /**
766  * Find a message with the given message_id.
767  *
768  * If a message with the given message_id is found then, on successful return
769  * (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to a message
770  * object.  The caller should call notmuch_message_destroy when done with the
771  * message.
772  *
773  * On any failure or when the message is not found, this function initializes
774  * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
775  * caller is supposed to check '*message' for NULL to find out whether the
776  * message with the given message_id was found.
777  *
778  * Return value:
779  *
780  * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'.
781  *
782  * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
783  *
784  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating message object
785  *
786  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
787  */
788 notmuch_status_t
789 notmuch_database_find_message (notmuch_database_t *database,
790                                const char *message_id,
791                                notmuch_message_t **message);
792
793 /**
794  * Find a message with the given filename.
795  *
796  * If the database contains a message with the given filename then, on
797  * successful return (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to
798  * a message object. The caller should call notmuch_message_destroy when done
799  * with the message.
800  *
801  * On any failure or when the message is not found, this function initializes
802  * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
803  * caller is supposed to check '*message' for NULL to find out whether the
804  * message with the given filename is found.
805  *
806  * Return value:
807  *
808  * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'
809  *
810  * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
811  *
812  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object
813  *
814  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
815  *
816  * NOTMUCH_STATUS_UPGRADE_REQUIRED: The caller must upgrade the
817  *      database to use this function.
818  */
819 notmuch_status_t
820 notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
821                                            const char *filename,
822                                            notmuch_message_t **message);
823
824 /**
825  * Return a list of all tags found in the database.
826  *
827  * This function creates a list of all tags found in the database. The
828  * resulting list contains all tags from all messages found in the database.
829  *
830  * On error this function returns NULL.
831  */
832 notmuch_tags_t *
833 notmuch_database_get_all_tags (notmuch_database_t *db);
834
835 /**
836  * Create a new query for 'database'.
837  *
838  * Here, 'database' should be an open database, (see
839  * notmuch_database_open and notmuch_database_create).
840  *
841  * For the query string, we'll document the syntax here more
842  * completely in the future, but it's likely to be a specialized
843  * version of the general Xapian query syntax:
844  *
845  * https://xapian.org/docs/queryparser.html
846  *
847  * As a special case, passing either a length-zero string, (that is ""),
848  * or a string consisting of a single asterisk (that is "*"), will
849  * result in a query that returns all messages in the database.
850  *
851  * See notmuch_query_set_sort for controlling the order of results.
852  * See notmuch_query_search_messages and notmuch_query_search_threads
853  * to actually execute the query.
854  *
855  * User should call notmuch_query_destroy when finished with this
856  * query.
857  *
858  * Will return NULL if insufficient memory is available.
859  */
860 notmuch_query_t *
861 notmuch_query_create (notmuch_database_t *database,
862                       const char *query_string);
863
864 /**
865  * Sort values for notmuch_query_set_sort.
866  */
867 typedef enum {
868     /**
869      * Oldest first.
870      */
871     NOTMUCH_SORT_OLDEST_FIRST,
872     /**
873      * Newest first.
874      */
875     NOTMUCH_SORT_NEWEST_FIRST,
876     /**
877      * Sort by message-id.
878      */
879     NOTMUCH_SORT_MESSAGE_ID,
880     /**
881      * Do not sort.
882      */
883     NOTMUCH_SORT_UNSORTED
884 } notmuch_sort_t;
885
886 /**
887  * Return the query_string of this query. See notmuch_query_create.
888  */
889 const char *
890 notmuch_query_get_query_string (const notmuch_query_t *query);
891
892 /**
893  * Return the notmuch database of this query. See notmuch_query_create.
894  */
895 notmuch_database_t *
896 notmuch_query_get_database (const notmuch_query_t *query);
897
898 /**
899  * Exclude values for notmuch_query_set_omit_excluded. The strange
900  * order is to maintain backward compatibility: the old FALSE/TRUE
901  * options correspond to the new
902  * NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options.
903  */
904 typedef enum {
905     NOTMUCH_EXCLUDE_FLAG,
906     NOTMUCH_EXCLUDE_TRUE,
907     NOTMUCH_EXCLUDE_FALSE,
908     NOTMUCH_EXCLUDE_ALL
909 } notmuch_exclude_t;
910
911 /**
912  * Specify whether to omit excluded results or simply flag them.  By
913  * default, this is set to TRUE.
914  *
915  * If set to TRUE or ALL, notmuch_query_search_messages will omit excluded
916  * messages from the results, and notmuch_query_search_threads will omit
917  * threads that match only in excluded messages.  If set to TRUE,
918  * notmuch_query_search_threads will include all messages in threads that
919  * match in at least one non-excluded message.  Otherwise, if set to ALL,
920  * notmuch_query_search_threads will omit excluded messages from all threads.
921  *
922  * If set to FALSE or FLAG then both notmuch_query_search_messages and
923  * notmuch_query_search_threads will return all matching
924  * messages/threads regardless of exclude status. If set to FLAG then
925  * the exclude flag will be set for any excluded message that is
926  * returned by notmuch_query_search_messages, and the thread counts
927  * for threads returned by notmuch_query_search_threads will be the
928  * number of non-excluded messages/matches. Otherwise, if set to
929  * FALSE, then the exclude status is completely ignored.
930  *
931  * The performance difference when calling
932  * notmuch_query_search_messages should be relatively small (and both
933  * should be very fast).  However, in some cases,
934  * notmuch_query_search_threads is very much faster when omitting
935  * excluded messages as it does not need to construct the threads that
936  * only match in excluded messages.
937  */
938 void
939 notmuch_query_set_omit_excluded (notmuch_query_t *query,
940                                  notmuch_exclude_t omit_excluded);
941
942 /**
943  * Specify the sorting desired for this query.
944  */
945 void
946 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
947
948 /**
949  * Return the sort specified for this query. See
950  * notmuch_query_set_sort.
951  */
952 notmuch_sort_t
953 notmuch_query_get_sort (const notmuch_query_t *query);
954
955 /**
956  * Add a tag that will be excluded from the query results by default.
957  * This exclusion will be ignored if this tag appears explicitly in
958  * the query.
959  *
960  * @returns
961  *
962  * NOTMUCH_STATUS_SUCCESS: excluded was added successfully.
963  *
964  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred.
965  *      Most likely a problem lazily parsing the query string.
966  *
967  * NOTMUCH_STATUS_IGNORED: tag is explicitly present in the query, so
968  *              not excluded.
969  */
970 notmuch_status_t
971 notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
972
973 /**
974  * Execute a query for threads, returning a notmuch_threads_t object
975  * which can be used to iterate over the results. The returned threads
976  * object is owned by the query and as such, will only be valid until
977  * notmuch_query_destroy.
978  *
979  * Typical usage might be:
980  *
981  *     notmuch_query_t *query;
982  *     notmuch_threads_t *threads;
983  *     notmuch_thread_t *thread;
984  *     notmuch_status_t stat;
985  *
986  *     query = notmuch_query_create (database, query_string);
987  *
988  *     for (stat = notmuch_query_search_threads (query, &threads);
989  *          stat == NOTMUCH_STATUS_SUCCESS &&
990  *          notmuch_threads_valid (threads);
991  *          notmuch_threads_move_to_next (threads))
992  *     {
993  *         thread = notmuch_threads_get (threads);
994  *         ....
995  *         notmuch_thread_destroy (thread);
996  *     }
997  *
998  *     notmuch_query_destroy (query);
999  *
1000  * Note: If you are finished with a thread before its containing
1001  * query, you can call notmuch_thread_destroy to clean up some memory
1002  * sooner (as in the above example). Otherwise, if your thread objects
1003  * are long-lived, then you don't need to call notmuch_thread_destroy
1004  * and all the memory will still be reclaimed when the query is
1005  * destroyed.
1006  *
1007  * Note that there's no explicit destructor needed for the
1008  * notmuch_threads_t object. (For consistency, we do provide a
1009  * notmuch_threads_destroy function, but there's no good reason
1010  * to call it if the query is about to be destroyed).
1011  *
1012  * @since libnotmuch 5.0 (notmuch 0.25)
1013  */
1014 notmuch_status_t
1015 notmuch_query_search_threads (notmuch_query_t *query,
1016                               notmuch_threads_t **out);
1017
1018 /**
1019  * Deprecated alias for notmuch_query_search_threads.
1020  *
1021  * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please
1022  * use notmuch_query_search_threads instead.
1023  *
1024  */
1025 NOTMUCH_DEPRECATED (5, 0)
1026 notmuch_status_t
1027 notmuch_query_search_threads_st (notmuch_query_t *query, notmuch_threads_t **out);
1028
1029 /**
1030  * Execute a query for messages, returning a notmuch_messages_t object
1031  * which can be used to iterate over the results. The returned
1032  * messages object is owned by the query and as such, will only be
1033  * valid until notmuch_query_destroy.
1034  *
1035  * Typical usage might be:
1036  *
1037  *     notmuch_query_t *query;
1038  *     notmuch_messages_t *messages;
1039  *     notmuch_message_t *message;
1040  *
1041  *     query = notmuch_query_create (database, query_string);
1042  *
1043  *     for (messages = notmuch_query_search_messages (query);
1044  *          notmuch_messages_valid (messages);
1045  *          notmuch_messages_move_to_next (messages))
1046  *     {
1047  *         message = notmuch_messages_get (messages);
1048  *         ....
1049  *         notmuch_message_destroy (message);
1050  *     }
1051  *
1052  *     notmuch_query_destroy (query);
1053  *
1054  * Note: If you are finished with a message before its containing
1055  * query, you can call notmuch_message_destroy to clean up some memory
1056  * sooner (as in the above example). Otherwise, if your message
1057  * objects are long-lived, then you don't need to call
1058  * notmuch_message_destroy and all the memory will still be reclaimed
1059  * when the query is destroyed.
1060  *
1061  * Note that there's no explicit destructor needed for the
1062  * notmuch_messages_t object. (For consistency, we do provide a
1063  * notmuch_messages_destroy function, but there's no good
1064  * reason to call it if the query is about to be destroyed).
1065  *
1066  * If a Xapian exception occurs this function will return NULL.
1067  *
1068  * @since libnotmuch 5 (notmuch 0.25)
1069  */
1070 notmuch_status_t
1071 notmuch_query_search_messages (notmuch_query_t *query,
1072                                notmuch_messages_t **out);
1073 /**
1074  * Deprecated alias for notmuch_query_search_messages
1075  *
1076  * @deprecated Deprecated as of libnotmuch 5 (notmuch 0.25). Please use
1077  * notmuch_query_search_messages instead.
1078  *
1079  */
1080
1081 NOTMUCH_DEPRECATED (5, 0)
1082 notmuch_status_t
1083 notmuch_query_search_messages_st (notmuch_query_t *query,
1084                                   notmuch_messages_t **out);
1085
1086 /**
1087  * Destroy a notmuch_query_t along with any associated resources.
1088  *
1089  * This will in turn destroy any notmuch_threads_t and
1090  * notmuch_messages_t objects generated by this query, (and in
1091  * turn any notmuch_thread_t and notmuch_message_t objects generated
1092  * from those results, etc.), if such objects haven't already been
1093  * destroyed.
1094  */
1095 void
1096 notmuch_query_destroy (notmuch_query_t *query);
1097
1098 /**
1099  * Is the given 'threads' iterator pointing at a valid thread.
1100  *
1101  * When this function returns TRUE, notmuch_threads_get will return a
1102  * valid object. Whereas when this function returns FALSE,
1103  * notmuch_threads_get will return NULL.
1104  *
1105  * If passed a NULL pointer, this function returns FALSE
1106  *
1107  * See the documentation of notmuch_query_search_threads for example
1108  * code showing how to iterate over a notmuch_threads_t object.
1109  */
1110 notmuch_bool_t
1111 notmuch_threads_valid (notmuch_threads_t *threads);
1112
1113 /**
1114  * Get the current thread from 'threads' as a notmuch_thread_t.
1115  *
1116  * Note: The returned thread belongs to 'threads' and has a lifetime
1117  * identical to it (and the query to which it belongs).
1118  *
1119  * See the documentation of notmuch_query_search_threads for example
1120  * code showing how to iterate over a notmuch_threads_t object.
1121  *
1122  * If an out-of-memory situation occurs, this function will return
1123  * NULL.
1124  */
1125 notmuch_thread_t *
1126 notmuch_threads_get (notmuch_threads_t *threads);
1127
1128 /**
1129  * Move the 'threads' iterator to the next thread.
1130  *
1131  * If 'threads' is already pointing at the last thread then the
1132  * iterator will be moved to a point just beyond that last thread,
1133  * (where notmuch_threads_valid will return FALSE and
1134  * notmuch_threads_get will return NULL).
1135  *
1136  * See the documentation of notmuch_query_search_threads for example
1137  * code showing how to iterate over a notmuch_threads_t object.
1138  */
1139 void
1140 notmuch_threads_move_to_next (notmuch_threads_t *threads);
1141
1142 /**
1143  * Destroy a notmuch_threads_t object.
1144  *
1145  * It's not strictly necessary to call this function. All memory from
1146  * the notmuch_threads_t object will be reclaimed when the
1147  * containing query object is destroyed.
1148  */
1149 void
1150 notmuch_threads_destroy (notmuch_threads_t *threads);
1151
1152 /**
1153  * Return the number of messages matching a search.
1154  *
1155  * This function performs a search and returns the number of matching
1156  * messages.
1157  *
1158  * @returns
1159  *
1160  * NOTMUCH_STATUS_SUCCESS: query completed successfully.
1161  *
1162  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred. The
1163  *      value of *count is not defined.
1164  *
1165  * @since libnotmuch 5 (notmuch 0.25)
1166  */
1167 notmuch_status_t
1168 notmuch_query_count_messages (notmuch_query_t *query, unsigned int *count);
1169
1170 /**
1171  * Deprecated alias for notmuch_query_count_messages
1172  *
1173  *
1174  * @deprecated Deprecated since libnotmuch 5.0 (notmuch 0.25). Please
1175  * use notmuch_query_count_messages instead.
1176  */
1177 NOTMUCH_DEPRECATED (5, 0)
1178 notmuch_status_t
1179 notmuch_query_count_messages_st (notmuch_query_t *query, unsigned int *count);
1180
1181 /**
1182  * Return the number of threads matching a search.
1183  *
1184  * This function performs a search and returns the number of unique thread IDs
1185  * in the matching messages. This is the same as number of threads matching a
1186  * search.
1187  *
1188  * Note that this is a significantly heavier operation than
1189  * notmuch_query_count_messages{_st}().
1190  *
1191  * @returns
1192  *
1193  * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
1194  *      of *count is not defined
1195  *
1196  * NOTMUCH_STATUS_SUCCESS: query completed successfully.
1197  *
1198  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occurred. The
1199  *      value of *count is not defined.
1200  *
1201  * @since libnotmuch 5 (notmuch 0.25)
1202  */
1203 notmuch_status_t
1204 notmuch_query_count_threads (notmuch_query_t *query, unsigned *count);
1205
1206 /**
1207  * Deprecated alias for notmuch_query_count_threads
1208  *
1209  * @deprecated Deprecated as of libnotmuch 5.0 (notmuch 0.25). Please
1210  * use notmuch_query_count_threads_st instead.
1211  */
1212 NOTMUCH_DEPRECATED (5, 0)
1213 notmuch_status_t
1214 notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
1215
1216 /**
1217  * Get the thread ID of 'thread'.
1218  *
1219  * The returned string belongs to 'thread' and as such, should not be
1220  * modified by the caller and will only be valid for as long as the
1221  * thread is valid, (which is until notmuch_thread_destroy or until
1222  * the query from which it derived is destroyed).
1223  */
1224 const char *
1225 notmuch_thread_get_thread_id (notmuch_thread_t *thread);
1226
1227 /**
1228  * Get the total number of messages in 'thread'.
1229  *
1230  * This count consists of all messages in the database belonging to
1231  * this thread. Contrast with notmuch_thread_get_matched_messages() .
1232  */
1233 int
1234 notmuch_thread_get_total_messages (notmuch_thread_t *thread);
1235
1236 /**
1237  * Get the total number of files in 'thread'.
1238  *
1239  * This sums notmuch_message_count_files over all messages in the
1240  * thread
1241  * @returns Non-negative integer
1242  * @since libnotmuch 5.0 (notmuch 0.25)
1243  */
1244
1245 int
1246 notmuch_thread_get_total_files (notmuch_thread_t *thread);
1247
1248 /**
1249  * Get a notmuch_messages_t iterator for the top-level messages in
1250  * 'thread' in oldest-first order.
1251  *
1252  * This iterator will not necessarily iterate over all of the messages
1253  * in the thread. It will only iterate over the messages in the thread
1254  * which are not replies to other messages in the thread.
1255  *
1256  * The returned list will be destroyed when the thread is destroyed.
1257  */
1258 notmuch_messages_t *
1259 notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
1260
1261 /**
1262  * Get a notmuch_thread_t iterator for all messages in 'thread' in
1263  * oldest-first order.
1264  *
1265  * The returned list will be destroyed when the thread is destroyed.
1266  */
1267 notmuch_messages_t *
1268 notmuch_thread_get_messages (notmuch_thread_t *thread);
1269
1270 /**
1271  * Get the number of messages in 'thread' that matched the search.
1272  *
1273  * This count includes only the messages in this thread that were
1274  * matched by the search from which the thread was created and were
1275  * not excluded by any exclude tags passed in with the query (see
1276  * notmuch_query_add_tag_exclude). Contrast with
1277  * notmuch_thread_get_total_messages() .
1278  */
1279 int
1280 notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
1281
1282 /**
1283  * Get the authors of 'thread' as a UTF-8 string.
1284  *
1285  * The returned string is a comma-separated list of the names of the
1286  * authors of mail messages in the query results that belong to this
1287  * thread.
1288  *
1289  * The string contains authors of messages matching the query first, then
1290  * non-matched authors (with the two groups separated by '|'). Within
1291  * each group, authors are ordered by date.
1292  *
1293  * The returned string belongs to 'thread' and as such, should not be
1294  * modified by the caller and will only be valid for as long as the
1295  * thread is valid, (which is until notmuch_thread_destroy or until
1296  * the query from which it derived is destroyed).
1297  */
1298 const char *
1299 notmuch_thread_get_authors (notmuch_thread_t *thread);
1300
1301 /**
1302  * Get the subject of 'thread' as a UTF-8 string.
1303  *
1304  * The subject is taken from the first message (according to the query
1305  * order---see notmuch_query_set_sort) in the query results that
1306  * belongs to this thread.
1307  *
1308  * The returned string belongs to 'thread' and as such, should not be
1309  * modified by the caller and will only be valid for as long as the
1310  * thread is valid, (which is until notmuch_thread_destroy or until
1311  * the query from which it derived is destroyed).
1312  */
1313 const char *
1314 notmuch_thread_get_subject (notmuch_thread_t *thread);
1315
1316 /**
1317  * Get the date of the oldest message in 'thread' as a time_t value.
1318  */
1319 time_t
1320 notmuch_thread_get_oldest_date (notmuch_thread_t *thread);
1321
1322 /**
1323  * Get the date of the newest message in 'thread' as a time_t value.
1324  */
1325 time_t
1326 notmuch_thread_get_newest_date (notmuch_thread_t *thread);
1327
1328 /**
1329  * Get the tags for 'thread', returning a notmuch_tags_t object which
1330  * can be used to iterate over all tags.
1331  *
1332  * Note: In the Notmuch database, tags are stored on individual
1333  * messages, not on threads. So the tags returned here will be all
1334  * tags of the messages which matched the search and which belong to
1335  * this thread.
1336  *
1337  * The tags object is owned by the thread and as such, will only be
1338  * valid for as long as the thread is valid, (for example, until
1339  * notmuch_thread_destroy or until the query from which it derived is
1340  * destroyed).
1341  *
1342  * Typical usage might be:
1343  *
1344  *     notmuch_thread_t *thread;
1345  *     notmuch_tags_t *tags;
1346  *     const char *tag;
1347  *
1348  *     thread = notmuch_threads_get (threads);
1349  *
1350  *     for (tags = notmuch_thread_get_tags (thread);
1351  *          notmuch_tags_valid (tags);
1352  *          notmuch_tags_move_to_next (tags))
1353  *     {
1354  *         tag = notmuch_tags_get (tags);
1355  *         ....
1356  *     }
1357  *
1358  *     notmuch_thread_destroy (thread);
1359  *
1360  * Note that there's no explicit destructor needed for the
1361  * notmuch_tags_t object. (For consistency, we do provide a
1362  * notmuch_tags_destroy function, but there's no good reason to call
1363  * it if the message is about to be destroyed).
1364  */
1365 notmuch_tags_t *
1366 notmuch_thread_get_tags (notmuch_thread_t *thread);
1367
1368 /**
1369  * Destroy a notmuch_thread_t object.
1370  */
1371 void
1372 notmuch_thread_destroy (notmuch_thread_t *thread);
1373
1374 /**
1375  * Is the given 'messages' iterator pointing at a valid message.
1376  *
1377  * When this function returns TRUE, notmuch_messages_get will return a
1378  * valid object. Whereas when this function returns FALSE,
1379  * notmuch_messages_get will return NULL.
1380  *
1381  * See the documentation of notmuch_query_search_messages for example
1382  * code showing how to iterate over a notmuch_messages_t object.
1383  */
1384 notmuch_bool_t
1385 notmuch_messages_valid (notmuch_messages_t *messages);
1386
1387 /**
1388  * Get the current message from 'messages' as a notmuch_message_t.
1389  *
1390  * Note: The returned message belongs to 'messages' and has a lifetime
1391  * identical to it (and the query to which it belongs).
1392  *
1393  * See the documentation of notmuch_query_search_messages for example
1394  * code showing how to iterate over a notmuch_messages_t object.
1395  *
1396  * If an out-of-memory situation occurs, this function will return
1397  * NULL.
1398  */
1399 notmuch_message_t *
1400 notmuch_messages_get (notmuch_messages_t *messages);
1401
1402 /**
1403  * Move the 'messages' iterator to the next message.
1404  *
1405  * If 'messages' is already pointing at the last message then the
1406  * iterator will be moved to a point just beyond that last message,
1407  * (where notmuch_messages_valid will return FALSE and
1408  * notmuch_messages_get will return NULL).
1409  *
1410  * See the documentation of notmuch_query_search_messages for example
1411  * code showing how to iterate over a notmuch_messages_t object.
1412  */
1413 void
1414 notmuch_messages_move_to_next (notmuch_messages_t *messages);
1415
1416 /**
1417  * Destroy a notmuch_messages_t object.
1418  *
1419  * It's not strictly necessary to call this function. All memory from
1420  * the notmuch_messages_t object will be reclaimed when the containing
1421  * query object is destroyed.
1422  */
1423 void
1424 notmuch_messages_destroy (notmuch_messages_t *messages);
1425
1426 /**
1427  * Return a list of tags from all messages.
1428  *
1429  * The resulting list is guaranteed not to contain duplicated tags.
1430  *
1431  * WARNING: You can no longer iterate over messages after calling this
1432  * function, because the iterator will point at the end of the list.
1433  * We do not have a function to reset the iterator yet and the only
1434  * way how you can iterate over the list again is to recreate the
1435  * message list.
1436  *
1437  * The function returns NULL on error.
1438  */
1439 notmuch_tags_t *
1440 notmuch_messages_collect_tags (notmuch_messages_t *messages);
1441
1442 /**
1443  * Get the database associated with this message.
1444  *
1445  * @since libnotmuch 5.2 (notmuch 0.27)
1446  */
1447 notmuch_database_t *
1448 notmuch_message_get_database (const notmuch_message_t *message);
1449
1450 /**
1451  * Get the message ID of 'message'.
1452  *
1453  * The returned string belongs to 'message' and as such, should not be
1454  * modified by the caller and will only be valid for as long as the
1455  * message is valid, (which is until the query from which it derived
1456  * is destroyed).
1457  *
1458  * This function will return NULL if triggers an unhandled Xapian
1459  * exception.
1460  */
1461 const char *
1462 notmuch_message_get_message_id (notmuch_message_t *message);
1463
1464 /**
1465  * Get the thread ID of 'message'.
1466  *
1467  * The returned string belongs to 'message' and as such, should not be
1468  * modified by the caller and will only be valid for as long as the
1469  * message is valid, (for example, until the user calls
1470  * notmuch_message_destroy on 'message' or until a query from which it
1471  * derived is destroyed).
1472  *
1473  * This function will return NULL if triggers an unhandled Xapian
1474  * exception.
1475  */
1476 const char *
1477 notmuch_message_get_thread_id (notmuch_message_t *message);
1478
1479 /**
1480  * Get a notmuch_messages_t iterator for all of the replies to
1481  * 'message'.
1482  *
1483  * Note: This call only makes sense if 'message' was ultimately
1484  * obtained from a notmuch_thread_t object, (such as by coming
1485  * directly from the result of calling notmuch_thread_get_
1486  * toplevel_messages or by any number of subsequent
1487  * calls to notmuch_message_get_replies).
1488  *
1489  * If 'message' was obtained through some non-thread means, (such as
1490  * by a call to notmuch_query_search_messages), then this function
1491  * will return NULL.
1492  *
1493  * If there are no replies to 'message', this function will return
1494  * NULL. (Note that notmuch_messages_valid will accept that NULL
1495  * value as legitimate, and simply return FALSE for it.)
1496  *
1497  * This function also returns NULL if it triggers a Xapian exception.
1498  *
1499  * The returned list will be destroyed when the thread is
1500  * destroyed.
1501  */
1502 notmuch_messages_t *
1503 notmuch_message_get_replies (notmuch_message_t *message);
1504
1505 /**
1506  * Get the total number of files associated with a message.
1507  * @returns Non-negative integer for file count.
1508  * @returns Negative integer for error.
1509  * @since libnotmuch 5.0 (notmuch 0.25)
1510  */
1511 int
1512 notmuch_message_count_files (notmuch_message_t *message);
1513
1514 /**
1515  * Get a filename for the email corresponding to 'message'.
1516  *
1517  * The returned filename is an absolute filename, (the initial
1518  * component will match notmuch_database_get_path() ).
1519  *
1520  * The returned string belongs to the message so should not be
1521  * modified or freed by the caller (nor should it be referenced after
1522  * the message is destroyed).
1523  *
1524  * Note: If this message corresponds to multiple files in the mail
1525  * store, (that is, multiple files contain identical message IDs),
1526  * this function will arbitrarily return a single one of those
1527  * filenames. See notmuch_message_get_filenames for returning the
1528  * complete list of filenames.
1529  *
1530  * This function returns NULL if it triggers a Xapian exception.
1531  */
1532 const char *
1533 notmuch_message_get_filename (notmuch_message_t *message);
1534
1535 /**
1536  * Get all filenames for the email corresponding to 'message'.
1537  *
1538  * Returns a notmuch_filenames_t iterator listing all the filenames
1539  * associated with 'message'. These files may not have identical
1540  * content, but each will have the identical Message-ID.
1541  *
1542  * Each filename in the iterator is an absolute filename, (the initial
1543  * component will match notmuch_database_get_path() ).
1544  *
1545  * This function returns NULL if it triggers a Xapian exception.
1546  */
1547 notmuch_filenames_t *
1548 notmuch_message_get_filenames (notmuch_message_t *message);
1549
1550 /**
1551  * Re-index the e-mail corresponding to 'message' using the supplied index options
1552  *
1553  * Returns the status of the re-index operation.  (see the return
1554  * codes documented in notmuch_database_index_file)
1555  *
1556  * After reindexing, the user should discard the message object passed
1557  * in here by calling notmuch_message_destroy, since it refers to the
1558  * original message, not to the reindexed message.
1559  */
1560 notmuch_status_t
1561 notmuch_message_reindex (notmuch_message_t *message,
1562                          notmuch_indexopts_t *indexopts);
1563
1564 /**
1565  * Message flags.
1566  */
1567 typedef enum _notmuch_message_flag {
1568     NOTMUCH_MESSAGE_FLAG_MATCH,
1569     NOTMUCH_MESSAGE_FLAG_EXCLUDED,
1570
1571     /* This message is a "ghost message", meaning it has no filenames
1572      * or content, but we know it exists because it was referenced by
1573      * some other message.  A ghost message has only a message ID and
1574      * thread ID.
1575      */
1576     NOTMUCH_MESSAGE_FLAG_GHOST,
1577 } notmuch_message_flag_t;
1578
1579 /**
1580  * Get a value of a flag for the email corresponding to 'message'.
1581  *
1582  * returns FALSE in case of errors.
1583  *
1584  * @deprecated Deprecated as of libnotmuch 5.3 (notmuch 0.31). Please
1585  * use notmuch_message_get_flag_st instead.
1586  */
1587 NOTMUCH_DEPRECATED(5,3)
1588 notmuch_bool_t
1589 notmuch_message_get_flag (notmuch_message_t *message,
1590                           notmuch_message_flag_t flag);
1591
1592 /**
1593  * Get a value of a flag for the email corresponding to 'message'.
1594  *
1595  * @param message a message object
1596  * @param flag flag to check
1597  * @param is_set pointer to boolean to store flag value.
1598  *
1599  * @retval #NOTMUCH_STATUS_SUCCESS
1600  * @retval #NOTMUCH_STATUS_NULL_POINTER is_set is NULL
1601  * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION Accessing the database
1602  * triggered an exception.
1603  *
1604  * @since libnotmuch 5.3 (notmuch 0.31)
1605  */
1606 notmuch_status_t
1607 notmuch_message_get_flag_st (notmuch_message_t *message,
1608                              notmuch_message_flag_t flag,
1609                              notmuch_bool_t *is_set);
1610
1611 /**
1612  * Set a value of a flag for the email corresponding to 'message'.
1613  */
1614 void
1615 notmuch_message_set_flag (notmuch_message_t *message,
1616                           notmuch_message_flag_t flag, notmuch_bool_t value);
1617
1618 /**
1619  * Get the date of 'message' as a time_t value.
1620  *
1621  * For the original textual representation of the Date header from the
1622  * message call notmuch_message_get_header() with a header value of
1623  * "date".
1624  *
1625  * Returns 0 in case of error.
1626  */
1627 time_t
1628 notmuch_message_get_date (notmuch_message_t *message);
1629
1630 /**
1631  * Get the value of the specified header from 'message' as a UTF-8 string.
1632  *
1633  * Common headers are stored in the database when the message is
1634  * indexed and will be returned from the database.  Other headers will
1635  * be read from the actual message file.
1636  *
1637  * The header name is case insensitive.
1638  *
1639  * The returned string belongs to the message so should not be
1640  * modified or freed by the caller (nor should it be referenced after
1641  * the message is destroyed).
1642  *
1643  * Returns an empty string ("") if the message does not contain a
1644  * header line matching 'header'. Returns NULL if any error occurs.
1645  */
1646 const char *
1647 notmuch_message_get_header (notmuch_message_t *message, const char *header);
1648
1649 /**
1650  * Get the tags for 'message', returning a notmuch_tags_t object which
1651  * can be used to iterate over all tags.
1652  *
1653  * The tags object is owned by the message and as such, will only be
1654  * valid for as long as the message is valid, (which is until the
1655  * query from which it derived is destroyed).
1656  *
1657  * Typical usage might be:
1658  *
1659  *     notmuch_message_t *message;
1660  *     notmuch_tags_t *tags;
1661  *     const char *tag;
1662  *
1663  *     message = notmuch_database_find_message (database, message_id);
1664  *
1665  *     for (tags = notmuch_message_get_tags (message);
1666  *          notmuch_tags_valid (tags);
1667  *          notmuch_tags_move_to_next (tags))
1668  *     {
1669  *         tag = notmuch_tags_get (tags);
1670  *         ....
1671  *     }
1672  *
1673  *     notmuch_message_destroy (message);
1674  *
1675  * Note that there's no explicit destructor needed for the
1676  * notmuch_tags_t object. (For consistency, we do provide a
1677  * notmuch_tags_destroy function, but there's no good reason to call
1678  * it if the message is about to be destroyed).
1679  */
1680 notmuch_tags_t *
1681 notmuch_message_get_tags (notmuch_message_t *message);
1682
1683 /**
1684  * The longest possible tag value.
1685  */
1686 #define NOTMUCH_TAG_MAX 200
1687
1688 /**
1689  * Add a tag to the given message.
1690  *
1691  * Return value:
1692  *
1693  * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message
1694  *
1695  * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1696  *
1697  * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1698  *      (exceeds NOTMUCH_TAG_MAX)
1699  *
1700  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1701  *      mode so message cannot be modified.
1702  */
1703 notmuch_status_t
1704 notmuch_message_add_tag (notmuch_message_t *message, const char *tag);
1705
1706 /**
1707  * Remove a tag from the given message.
1708  *
1709  * Return value:
1710  *
1711  * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message
1712  *
1713  * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1714  *
1715  * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1716  *      (exceeds NOTMUCH_TAG_MAX)
1717  *
1718  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1719  *      mode so message cannot be modified.
1720  */
1721 notmuch_status_t
1722 notmuch_message_remove_tag (notmuch_message_t *message, const char *tag);
1723
1724 /**
1725  * Remove all tags from the given message.
1726  *
1727  * See notmuch_message_freeze for an example showing how to safely
1728  * replace tag values.
1729  *
1730  * @retval #NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
1731  *      read-only mode so message cannot be modified.
1732  * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION: an exception was thrown
1733  *      accessing the database.
1734  */
1735 notmuch_status_t
1736 notmuch_message_remove_all_tags (notmuch_message_t *message);
1737
1738 /**
1739  * Add/remove tags according to maildir flags in the message filename(s).
1740  *
1741  * This function examines the filenames of 'message' for maildir
1742  * flags, and adds or removes tags on 'message' as follows when these
1743  * flags are present:
1744  *
1745  *      Flag    Action if present
1746  *      ----    -----------------
1747  *      'D'     Adds the "draft" tag to the message
1748  *      'F'     Adds the "flagged" tag to the message
1749  *      'P'     Adds the "passed" tag to the message
1750  *      'R'     Adds the "replied" tag to the message
1751  *      'S'     Removes the "unread" tag from the message
1752  *
1753  * For each flag that is not present, the opposite action (add/remove)
1754  * is performed for the corresponding tags.
1755  *
1756  * Flags are identified as trailing components of the filename after a
1757  * sequence of ":2,".
1758  *
1759  * If there are multiple filenames associated with this message, the
1760  * flag is considered present if it appears in one or more
1761  * filenames. (That is, the flags from the multiple filenames are
1762  * combined with the logical OR operator.)
1763  *
1764  * A client can ensure that notmuch database tags remain synchronized
1765  * with maildir flags by calling this function after each call to
1766  * notmuch_database_index_file. See also
1767  * notmuch_message_tags_to_maildir_flags for synchronizing tag changes
1768  * back to maildir flags.
1769  */
1770 notmuch_status_t
1771 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
1772
1773 /**
1774  * return TRUE if any filename of 'message' has maildir flag 'flag',
1775  * FALSE otherwise.
1776  *
1777  * Deprecated wrapper for notmuch_message_has_maildir_flag_st
1778  *
1779  * @returns FALSE in case of error
1780  * @deprecated libnotmuch 5.3 (notmuch 0.31)
1781  */
1782 NOTMUCH_DEPRECATED(5, 3)
1783 notmuch_bool_t
1784 notmuch_message_has_maildir_flag (notmuch_message_t *message, char flag);
1785
1786 /**
1787  * check message for maildir flag
1788  *
1789  * @param [in,out]      message message to check
1790  * @param [in] flag     flag to check for
1791  * @param [out] is_set  pointer to boolean
1792  *
1793  * @retval #NOTMUCH_STATUS_SUCCESS
1794  * @retval #NOTMUCH_STATUS_NULL_POINTER is_set is NULL
1795  * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION Accessing the database
1796  * triggered an exception.
1797  */
1798 notmuch_status_t
1799 notmuch_message_has_maildir_flag_st (notmuch_message_t *message,
1800                                      char flag,
1801                                      notmuch_bool_t *is_set);
1802
1803 /**
1804  * Rename message filename(s) to encode tags as maildir flags.
1805  *
1806  * Specifically, for each filename corresponding to this message:
1807  *
1808  * If the filename is not in a maildir directory, do nothing.  (A
1809  * maildir directory is determined as a directory named "new" or
1810  * "cur".) Similarly, if the filename has invalid maildir info,
1811  * (repeated or outof-ASCII-order flag characters after ":2,"), then
1812  * do nothing.
1813  *
1814  * If the filename is in a maildir directory, rename the file so that
1815  * its filename ends with the sequence ":2," followed by zero or more
1816  * of the following single-character flags (in ASCII order):
1817  *
1818  *   * flag 'D' iff the message has the "draft" tag
1819  *   * flag 'F' iff the message has the "flagged" tag
1820  *   * flag 'P' iff the message has the "passed" tag
1821  *   * flag 'R' iff the message has the "replied" tag
1822  *   * flag 'S' iff the message does not have the "unread" tag
1823  *
1824  * Any existing flags unmentioned in the list above will be preserved
1825  * in the renaming.
1826  *
1827  * Also, if this filename is in a directory named "new", rename it to
1828  * be within the neighboring directory named "cur".
1829  *
1830  * A client can ensure that maildir filename flags remain synchronized
1831  * with notmuch database tags by calling this function after changing
1832  * tags, (after calls to notmuch_message_add_tag,
1833  * notmuch_message_remove_tag, or notmuch_message_freeze/
1834  * notmuch_message_thaw). See also notmuch_message_maildir_flags_to_tags
1835  * for synchronizing maildir flag changes back to tags.
1836  */
1837 notmuch_status_t
1838 notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
1839
1840 /**
1841  * Freeze the current state of 'message' within the database.
1842  *
1843  * This means that changes to the message state, (via
1844  * notmuch_message_add_tag, notmuch_message_remove_tag, and
1845  * notmuch_message_remove_all_tags), will not be committed to the
1846  * database until the message is thawed with notmuch_message_thaw.
1847  *
1848  * Multiple calls to freeze/thaw are valid and these calls will
1849  * "stack". That is there must be as many calls to thaw as to freeze
1850  * before a message is actually thawed.
1851  *
1852  * The ability to do freeze/thaw allows for safe transactions to
1853  * change tag values. For example, explicitly setting a message to
1854  * have a given set of tags might look like this:
1855  *
1856  *    notmuch_message_freeze (message);
1857  *
1858  *    notmuch_message_remove_all_tags (message);
1859  *
1860  *    for (i = 0; i < NUM_TAGS; i++)
1861  *        notmuch_message_add_tag (message, tags[i]);
1862  *
1863  *    notmuch_message_thaw (message);
1864  *
1865  * With freeze/thaw used like this, the message in the database is
1866  * guaranteed to have either the full set of original tag values, or
1867  * the full set of new tag values, but nothing in between.
1868  *
1869  * Imagine the example above without freeze/thaw and the operation
1870  * somehow getting interrupted. This could result in the message being
1871  * left with no tags if the interruption happened after
1872  * notmuch_message_remove_all_tags but before notmuch_message_add_tag.
1873  *
1874  * Return value:
1875  *
1876  * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.
1877  *
1878  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1879  *      mode so message cannot be modified.
1880  */
1881 notmuch_status_t
1882 notmuch_message_freeze (notmuch_message_t *message);
1883
1884 /**
1885  * Thaw the current 'message', synchronizing any changes that may have
1886  * occurred while 'message' was frozen into the notmuch database.
1887  *
1888  * See notmuch_message_freeze for an example of how to use this
1889  * function to safely provide tag changes.
1890  *
1891  * Multiple calls to freeze/thaw are valid and these calls with
1892  * "stack". That is there must be as many calls to thaw as to freeze
1893  * before a message is actually thawed.
1894  *
1895  * Return value:
1896  *
1897  * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least
1898  *      its frozen count has successfully been reduced by 1).
1899  *
1900  * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw
1901  *      an unfrozen message. That is, there have been an unbalanced
1902  *      number of calls to notmuch_message_freeze and
1903  *      notmuch_message_thaw.
1904  */
1905 notmuch_status_t
1906 notmuch_message_thaw (notmuch_message_t *message);
1907
1908 /**
1909  * Destroy a notmuch_message_t object.
1910  *
1911  * It can be useful to call this function in the case of a single
1912  * query object with many messages in the result, (such as iterating
1913  * over the entire database). Otherwise, it's fine to never call this
1914  * function and there will still be no memory leaks. (The memory from
1915  * the messages get reclaimed when the containing query is destroyed.)
1916  */
1917 void
1918 notmuch_message_destroy (notmuch_message_t *message);
1919
1920 /**
1921  * @name Message Properties
1922  *
1923  * This interface provides the ability to attach arbitrary (key,value)
1924  * string pairs to a message, to remove such pairs, and to iterate
1925  * over them.  The caller should take some care as to what keys they
1926  * add or delete values for, as other subsystems or extensions may
1927  * depend on these properties.
1928  *
1929  * Please see notmuch-properties(7) for more details about specific
1930  * properties and conventions around their use.
1931  *
1932  */
1933 /**@{*/
1934 /**
1935  * Retrieve the value for a single property key
1936  *
1937  * *value* is set to a string owned by the message or NULL if there is
1938  * no such key. In the case of multiple values for the given key, the
1939  * first one is retrieved.
1940  *
1941  * @returns
1942  * - NOTMUCH_STATUS_NULL_POINTER: *value* may not be NULL.
1943  * - NOTMUCH_STATUS_SUCCESS: No error occurred.
1944  * @since libnotmuch 4.4 (notmuch 0.23)
1945  */
1946 notmuch_status_t
1947 notmuch_message_get_property (notmuch_message_t *message, const char *key, const char **value);
1948
1949 /**
1950  * Add a (key,value) pair to a message
1951  *
1952  * @returns
1953  * - NOTMUCH_STATUS_ILLEGAL_ARGUMENT: *key* may not contain an '=' character.
1954  * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL.
1955  * - NOTMUCH_STATUS_SUCCESS: No error occurred.
1956  * @since libnotmuch 4.4 (notmuch 0.23)
1957  */
1958 notmuch_status_t
1959 notmuch_message_add_property (notmuch_message_t *message, const char *key, const char *value);
1960
1961 /**
1962  * Remove a (key,value) pair from a message.
1963  *
1964  * It is not an error to remove a non-existent (key,value) pair
1965  *
1966  * @returns
1967  * - NOTMUCH_STATUS_ILLEGAL_ARGUMENT: *key* may not contain an '=' character.
1968  * - NOTMUCH_STATUS_NULL_POINTER: Neither *key* nor *value* may be NULL.
1969  * - NOTMUCH_STATUS_SUCCESS: No error occurred.
1970  * @since libnotmuch 4.4 (notmuch 0.23)
1971  */
1972 notmuch_status_t
1973 notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
1974
1975 /**
1976  * Remove all (key,value) pairs from the given message.
1977  *
1978  * @param[in,out] message  message to operate on.
1979  * @param[in]     key      key to delete properties for. If NULL, delete
1980  *                         properties for all keys
1981  * @returns
1982  * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
1983  *   read-only mode so message cannot be modified.
1984  * - NOTMUCH_STATUS_SUCCESS: No error occurred.
1985  *
1986  * @since libnotmuch 4.4 (notmuch 0.23)
1987  */
1988 notmuch_status_t
1989 notmuch_message_remove_all_properties (notmuch_message_t *message, const char *key);
1990
1991 /**
1992  * Remove all (prefix*,value) pairs from the given message
1993  *
1994  * @param[in,out] message  message to operate on.
1995  * @param[in]     prefix   delete properties with keys that start with prefix.
1996  *                         If NULL, delete all properties
1997  * @returns
1998  * - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
1999  *   read-only mode so message cannot be modified.
2000  * - NOTMUCH_STATUS_SUCCESS: No error occurred.
2001  *
2002  * @since libnotmuch 5.1 (notmuch 0.26)
2003  */
2004 notmuch_status_t
2005 notmuch_message_remove_all_properties_with_prefix (notmuch_message_t *message, const char *prefix);
2006
2007 /**
2008  * Opaque message property iterator
2009  */
2010 typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
2011
2012 /**
2013  * Get the properties for *message*, returning a
2014  * notmuch_message_properties_t object which can be used to iterate
2015  * over all properties.
2016  *
2017  * The notmuch_message_properties_t object is owned by the message and
2018  * as such, will only be valid for as long as the message is valid,
2019  * (which is until the query from which it derived is destroyed).
2020  *
2021  * @param[in] message  The message to examine
2022  * @param[in] key      key or key prefix
2023  * @param[in] exact    if TRUE, require exact match with key. Otherwise
2024  *                     treat as prefix.
2025  *
2026  * Typical usage might be:
2027  *
2028  *     notmuch_message_properties_t *list;
2029  *
2030  *     for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
2031  *          notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
2032  *        printf("%s\n", notmuch_message_properties_value(list));
2033  *     }
2034  *
2035  *     notmuch_message_properties_destroy (list);
2036  *
2037  * Note that there's no explicit destructor needed for the
2038  * notmuch_message_properties_t object. (For consistency, we do
2039  * provide a notmuch_message_properities_destroy function, but there's
2040  * no good reason to call it if the message is about to be destroyed).
2041  *
2042  * @since libnotmuch 4.4 (notmuch 0.23)
2043  */
2044 notmuch_message_properties_t *
2045 notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
2046
2047 /**
2048  * Return the number of properties named "key" belonging to the specific message.
2049  *
2050  * @param[in] message  The message to examine
2051  * @param[in] key      key to count
2052  * @param[out] count   The number of matching properties associated with this message.
2053  *
2054  * @returns
2055  *
2056  * NOTMUCH_STATUS_SUCCESS: successful count, possibly some other error.
2057  *
2058  * @since libnotmuch 5.2 (notmuch 0.27)
2059  */
2060 notmuch_status_t
2061 notmuch_message_count_properties (notmuch_message_t *message, const char *key, unsigned int *count);
2062
2063 /**
2064  * Is the given *properties* iterator pointing at a valid (key,value)
2065  * pair.
2066  *
2067  * When this function returns TRUE,
2068  * notmuch_message_properties_{key,value} will return a valid string,
2069  * and notmuch_message_properties_move_to_next will do what it
2070  * says. Whereas when this function returns FALSE, calling any of
2071  * these functions results in undefined behaviour.
2072  *
2073  * See the documentation of notmuch_message_get_properties for example
2074  * code showing how to iterate over a notmuch_message_properties_t
2075  * object.
2076  *
2077  * @since libnotmuch 4.4 (notmuch 0.23)
2078  */
2079 notmuch_bool_t
2080 notmuch_message_properties_valid (notmuch_message_properties_t *properties);
2081
2082 /**
2083  * Move the *properties* iterator to the next (key,value) pair
2084  *
2085  * If *properties* is already pointing at the last pair then the iterator
2086  * will be moved to a point just beyond that last pair, (where
2087  * notmuch_message_properties_valid will return FALSE).
2088  *
2089  * See the documentation of notmuch_message_get_properties for example
2090  * code showing how to iterate over a notmuch_message_properties_t object.
2091  *
2092  * @since libnotmuch 4.4 (notmuch 0.23)
2093  */
2094 void
2095 notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);
2096
2097 /**
2098  * Return the key from the current (key,value) pair.
2099  *
2100  * this could be useful if iterating for a prefix
2101  *
2102  * @since libnotmuch 4.4 (notmuch 0.23)
2103  */
2104 const char *
2105 notmuch_message_properties_key (notmuch_message_properties_t *properties);
2106
2107 /**
2108  * Return the value from the current (key,value) pair.
2109  *
2110  * This could be useful if iterating for a prefix.
2111  *
2112  * @since libnotmuch 4.4 (notmuch 0.23)
2113  */
2114 const char *
2115 notmuch_message_properties_value (notmuch_message_properties_t *properties);
2116
2117
2118 /**
2119  * Destroy a notmuch_message_properties_t object.
2120  *
2121  * It's not strictly necessary to call this function. All memory from
2122  * the notmuch_message_properties_t object will be reclaimed when the
2123  * containing message object is destroyed.
2124  *
2125  * @since libnotmuch 4.4 (notmuch 0.23)
2126  */
2127 void
2128 notmuch_message_properties_destroy (notmuch_message_properties_t *properties);
2129
2130 /**@}*/
2131
2132 /**
2133  * Is the given 'tags' iterator pointing at a valid tag.
2134  *
2135  * When this function returns TRUE, notmuch_tags_get will return a
2136  * valid string. Whereas when this function returns FALSE,
2137  * notmuch_tags_get will return NULL.
2138  *
2139  * See the documentation of notmuch_message_get_tags for example code
2140  * showing how to iterate over a notmuch_tags_t object.
2141  */
2142 notmuch_bool_t
2143 notmuch_tags_valid (notmuch_tags_t *tags);
2144
2145 /**
2146  * Get the current tag from 'tags' as a string.
2147  *
2148  * Note: The returned string belongs to 'tags' and has a lifetime
2149  * identical to it (and the query to which it ultimately belongs).
2150  *
2151  * See the documentation of notmuch_message_get_tags for example code
2152  * showing how to iterate over a notmuch_tags_t object.
2153  */
2154 const char *
2155 notmuch_tags_get (notmuch_tags_t *tags);
2156
2157 /**
2158  * Move the 'tags' iterator to the next tag.
2159  *
2160  * If 'tags' is already pointing at the last tag then the iterator
2161  * will be moved to a point just beyond that last tag, (where
2162  * notmuch_tags_valid will return FALSE and notmuch_tags_get will
2163  * return NULL).
2164  *
2165  * See the documentation of notmuch_message_get_tags for example code
2166  * showing how to iterate over a notmuch_tags_t object.
2167  */
2168 void
2169 notmuch_tags_move_to_next (notmuch_tags_t *tags);
2170
2171 /**
2172  * Destroy a notmuch_tags_t object.
2173  *
2174  * It's not strictly necessary to call this function. All memory from
2175  * the notmuch_tags_t object will be reclaimed when the containing
2176  * message or query objects are destroyed.
2177  */
2178 void
2179 notmuch_tags_destroy (notmuch_tags_t *tags);
2180
2181 /**
2182  * Store an mtime within the database for 'directory'.
2183  *
2184  * The 'directory' should be an object retrieved from the database
2185  * with notmuch_database_get_directory for a particular path.
2186  *
2187  * The intention is for the caller to use the mtime to allow efficient
2188  * identification of new messages to be added to the database. The
2189  * recommended usage is as follows:
2190  *
2191  *   o Read the mtime of a directory from the filesystem
2192  *
2193  *   o Call index_file for all mail files in the directory
2194  *
2195  *   o Call notmuch_directory_set_mtime with the mtime read from the
2196  *     filesystem.
2197  *
2198  * Then, when wanting to check for updates to the directory in the
2199  * future, the client can call notmuch_directory_get_mtime and know
2200  * that it only needs to add files if the mtime of the directory and
2201  * files are newer than the stored timestamp.
2202  *
2203  * Note: The notmuch_directory_get_mtime function does not allow the
2204  * caller to distinguish a timestamp of 0 from a non-existent
2205  * timestamp. So don't store a timestamp of 0 unless you are
2206  * comfortable with that.
2207  *
2208  * Return value:
2209  *
2210  * NOTMUCH_STATUS_SUCCESS: mtime successfully stored in database.
2211  *
2212  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception
2213  *      occurred, mtime not stored.
2214  *
2215  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
2216  *      mode so directory mtime cannot be modified.
2217  */
2218 notmuch_status_t
2219 notmuch_directory_set_mtime (notmuch_directory_t *directory,
2220                              time_t mtime);
2221
2222 /**
2223  * Get the mtime of a directory, (as previously stored with
2224  * notmuch_directory_set_mtime).
2225  *
2226  * Returns 0 if no mtime has previously been stored for this
2227  * directory.
2228  */
2229 time_t
2230 notmuch_directory_get_mtime (notmuch_directory_t *directory);
2231
2232 /**
2233  * Get a notmuch_filenames_t iterator listing all the filenames of
2234  * messages in the database within the given directory.
2235  *
2236  * The returned filenames will be the basename-entries only (not
2237  * complete paths).
2238  *
2239  * Returns NULL if it triggers a Xapian exception
2240  */
2241 notmuch_filenames_t *
2242 notmuch_directory_get_child_files (notmuch_directory_t *directory);
2243
2244 /**
2245  * Get a notmuch_filenames_t iterator listing all the filenames of
2246  * sub-directories in the database within the given directory.
2247  *
2248  * The returned filenames will be the basename-entries only (not
2249  * complete paths).
2250  *
2251  * Returns NULL if it triggers a Xapian exception
2252  */
2253 notmuch_filenames_t *
2254 notmuch_directory_get_child_directories (notmuch_directory_t *directory);
2255
2256 /**
2257  * Delete directory document from the database, and destroy the
2258  * notmuch_directory_t object. Assumes any child directories and files
2259  * have been deleted by the caller.
2260  *
2261  * @since libnotmuch 4.3 (notmuch 0.21)
2262  */
2263 notmuch_status_t
2264 notmuch_directory_delete (notmuch_directory_t *directory);
2265
2266 /**
2267  * Destroy a notmuch_directory_t object.
2268  */
2269 void
2270 notmuch_directory_destroy (notmuch_directory_t *directory);
2271
2272 /**
2273  * Is the given 'filenames' iterator pointing at a valid filename.
2274  *
2275  * When this function returns TRUE, notmuch_filenames_get will return
2276  * a valid string. Whereas when this function returns FALSE,
2277  * notmuch_filenames_get will return NULL.
2278  *
2279  * It is acceptable to pass NULL for 'filenames', in which case this
2280  * function will always return FALSE.
2281  */
2282 notmuch_bool_t
2283 notmuch_filenames_valid (notmuch_filenames_t *filenames);
2284
2285 /**
2286  * Get the current filename from 'filenames' as a string.
2287  *
2288  * Note: The returned string belongs to 'filenames' and has a lifetime
2289  * identical to it (and the directory to which it ultimately belongs).
2290  *
2291  * It is acceptable to pass NULL for 'filenames', in which case this
2292  * function will always return NULL.
2293  */
2294 const char *
2295 notmuch_filenames_get (notmuch_filenames_t *filenames);
2296
2297 /**
2298  * Move the 'filenames' iterator to the next filename.
2299  *
2300  * If 'filenames' is already pointing at the last filename then the
2301  * iterator will be moved to a point just beyond that last filename,
2302  * (where notmuch_filenames_valid will return FALSE and
2303  * notmuch_filenames_get will return NULL).
2304  *
2305  * It is acceptable to pass NULL for 'filenames', in which case this
2306  * function will do nothing.
2307  */
2308 void
2309 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
2310
2311 /**
2312  * Destroy a notmuch_filenames_t object.
2313  *
2314  * It's not strictly necessary to call this function. All memory from
2315  * the notmuch_filenames_t object will be reclaimed when the
2316  * containing directory object is destroyed.
2317  *
2318  * It is acceptable to pass NULL for 'filenames', in which case this
2319  * function will do nothing.
2320  */
2321 void
2322 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
2323
2324
2325 /**
2326  * set config 'key' to 'value'
2327  *
2328  * @since libnotmuch 4.4 (notmuch 0.23)
2329  * @retval #NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in
2330  *      read-only mode so message cannot be modified.
2331  * @retval #NOTMUCH_STATUS_XAPIAN_EXCEPTION: an exception was thrown
2332  *      accessing the database.
2333  * @retval #NOTMUCH_STATUS_SUCCESS
2334  */
2335 notmuch_status_t
2336 notmuch_database_set_config (notmuch_database_t *db, const char *key, const char *value);
2337
2338 /**
2339  * retrieve config item 'key', assign to  'value'
2340  *
2341  * keys which have not been previously set with n_d_set_config will
2342  * return an empty string.
2343  *
2344  * return value is allocated by malloc and should be freed by the
2345  * caller.
2346  *
2347  * @since libnotmuch 4.4 (notmuch 0.23)
2348  *
2349  */
2350 notmuch_status_t
2351 notmuch_database_get_config (notmuch_database_t *db, const char *key, char **value);
2352
2353 /**
2354  * Create an iterator for all config items with keys matching a given prefix
2355  *
2356  * @since libnotmuch 4.4 (notmuch 0.23)
2357  */
2358 notmuch_status_t
2359 notmuch_database_get_config_list (notmuch_database_t *db, const char *prefix, notmuch_config_list_t **out);
2360
2361 /**
2362  * Is 'config_list' iterator valid (i.e. _key, _value, _move_to_next can be called).
2363  *
2364  * @since libnotmuch 4.4 (notmuch 0.23)
2365  */
2366 notmuch_bool_t
2367 notmuch_config_list_valid (notmuch_config_list_t *config_list);
2368
2369 /**
2370  * return key for current config pair
2371  *
2372  * return value is owned by the iterator, and will be destroyed by the
2373  * next call to notmuch_config_list_key or notmuch_config_list_destroy.
2374  *
2375  * @since libnotmuch 4.4 (notmuch 0.23)
2376  */
2377 const char *
2378 notmuch_config_list_key (notmuch_config_list_t *config_list);
2379
2380 /**
2381  * return 'value' for current config pair
2382  *
2383  * return value is owned by the iterator, and will be destroyed by the
2384  * next call to notmuch_config_list_value or notmuch config_list_destroy
2385  *
2386  * @since libnotmuch 4.4 (notmuch 0.23)
2387  * @retval NULL for errors
2388  */
2389 const char *
2390 notmuch_config_list_value (notmuch_config_list_t *config_list);
2391
2392
2393 /**
2394  * move 'config_list' iterator to the next pair
2395  *
2396  * @since libnotmuch 4.4 (notmuch 0.23)
2397  */
2398 void
2399 notmuch_config_list_move_to_next (notmuch_config_list_t *config_list);
2400
2401 /**
2402  * free any resources held by 'config_list'
2403  *
2404  * @since libnotmuch 4.4 (notmuch 0.23)
2405  */
2406 void
2407 notmuch_config_list_destroy (notmuch_config_list_t *config_list);
2408
2409
2410 /**
2411  * Configuration keys known to libnotmuch
2412  */
2413 typedef enum _notmuch_config_key {
2414     NOTMUCH_CONFIG_FIRST,
2415     NOTMUCH_CONFIG_DATABASE_PATH = NOTMUCH_CONFIG_FIRST,
2416     NOTMUCH_CONFIG_EXCLUDE_TAGS,
2417     NOTMUCH_CONFIG_NEW_TAGS,
2418     NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS,
2419     NOTMUCH_CONFIG_PRIMARY_EMAIL,
2420     NOTMUCH_CONFIG_OTHER_EMAIL,
2421     NOTMUCH_CONFIG_USER_NAME,
2422     NOTMUCH_CONFIG_LAST
2423 } notmuch_config_key_t;
2424
2425 /**
2426  * get a configuration value from an open database.
2427  *
2428  * This value reflects all configuration information given at the time
2429  * the database was opened.
2430  *
2431  * @param[in] notmuch database
2432  * @param[in] key configuration key
2433  *
2434  * @since libnotmuch 5.4 (notmuch 0.32)
2435  *
2436  * @retval NULL if 'key' unknown or if no value is known for
2437  *         'key'.  Otherwise returns a string owned by notmuch which should
2438  *         not be modified nor freed by the caller.
2439  */
2440 const char *
2441 notmuch_config_get (notmuch_database_t *notmuch, notmuch_config_key_t key);
2442
2443 /**
2444  * set a configuration value from in an open database.
2445  *
2446  * This value reflects all configuration information given at the time
2447  * the database was opened.
2448  *
2449  * @param[in,out] notmuch database open read/write
2450  * @param[in] key configuration key
2451  * @param[in] val configuration value
2452  *
2453  * @since libnotmuch 5.4 (notmuch 0.32)
2454  *
2455  * @retval returns any return value for notmuch_database_set_config.
2456  */
2457 notmuch_status_t
2458 notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val);
2459
2460 /**
2461  * Returns an iterator for a ';'-delimited list of configuration values
2462  *
2463  * These values reflect all configuration information given at the
2464  * time the database was opened.
2465  *
2466  * @param[in] notmuch database
2467  * @param[in] key configuration key
2468  *
2469  * @since libnotmuch 5.4 (notmuch 0.32)
2470  *
2471  * @retval NULL in case of error.
2472  */
2473 notmuch_config_values_t *
2474 notmuch_config_get_values (notmuch_database_t *notmuch, notmuch_config_key_t key);
2475
2476 /**
2477  * Is the given 'config_values' iterator pointing at a valid element.
2478  *
2479  * @param[in] values iterator
2480  *
2481  * @since libnotmuch 5.4 (notmuch 0.32)
2482  *
2483  * @retval FALSE if passed a NULL pointer, or the iterator is exhausted.
2484  *
2485  */
2486 notmuch_bool_t
2487 notmuch_config_values_valid (notmuch_config_values_t *values);
2488
2489 /**
2490  * Get the current value from the 'values' iterator
2491  *
2492  * @param[in] values iterator
2493  *
2494  * @since libnotmuch 5.4 (notmuch 0.32)
2495  *
2496  * @retval a string with the same lifetime as the iterator
2497  */
2498 const char *
2499 notmuch_config_values_get (notmuch_config_values_t *values);
2500
2501 /**
2502  * Move the 'values' iterator to the next element
2503  *
2504  * @param[in,out] values iterator
2505  *
2506  * @since libnotmuch 5.4 (notmuch 0.32)
2507  *
2508  */
2509 void
2510 notmuch_config_values_move_to_next (notmuch_config_values_t *values);
2511
2512
2513 /**
2514  * reset the 'values' iterator to the first element
2515  *
2516  * @param[in,out] values iterator. A NULL value is ignored.
2517  *
2518  * @since libnotmuch 5.4 (notmuch 0.32)
2519  *
2520  */
2521 void
2522 notmuch_config_values_start (notmuch_config_values_t *values);
2523
2524 /**
2525  * Destroy a config values iterator, along with any associated
2526  * resources.
2527  *
2528  * @param[in,out] values iterator
2529  *
2530  * @since libnotmuch 5.4 (notmuch 0.32)
2531  */
2532 void
2533 notmuch_config_values_destroy (notmuch_config_values_t *values);
2534
2535 /**
2536  * get a configuration value from an open database as Boolean
2537  *
2538  * This value reflects all configuration information given at the time
2539  * the database was opened.
2540  *
2541  * @param[in] notmuch database
2542  * @param[in] key configuration key
2543  * @param[out] val configuration value, converted to Boolean
2544  *
2545  * @since libnotmuch 5.4 (notmuch 0.32)
2546  *
2547  * @retval #NOTMUCH_STATUS_ILLEGAL_ARGUMENT if either key is unknown
2548  * or the corresponding value does not convert to Boolean.
2549  */
2550 notmuch_status_t
2551 notmuch_config_get_bool (notmuch_database_t *notmuch,
2552                          notmuch_config_key_t key,
2553                          notmuch_bool_t *val);
2554 /**
2555  * get the current default indexing options for a given database.
2556  *
2557  * This object will survive until the database itself is destroyed,
2558  * but the caller may also release it earlier with
2559  * notmuch_indexopts_destroy.
2560  *
2561  * This object represents a set of options on how a message can be
2562  * added to the index.  At the moment it is a featureless stub.
2563  *
2564  * @since libnotmuch 5.1 (notmuch 0.26)
2565  * @retval NULL in case of error
2566  */
2567 notmuch_indexopts_t *
2568 notmuch_database_get_default_indexopts (notmuch_database_t *db);
2569
2570 /**
2571  * Stating a policy about how to decrypt messages.
2572  *
2573  * See index.decrypt in notmuch-config(1) for more details.
2574  */
2575 typedef enum {
2576     NOTMUCH_DECRYPT_FALSE,
2577     NOTMUCH_DECRYPT_TRUE,
2578     NOTMUCH_DECRYPT_AUTO,
2579     NOTMUCH_DECRYPT_NOSTASH,
2580 } notmuch_decryption_policy_t;
2581
2582 /**
2583  * Specify whether to decrypt encrypted parts while indexing.
2584  *
2585  * Be aware that the index is likely sufficient to reconstruct the
2586  * cleartext of the message itself, so please ensure that the notmuch
2587  * message index is adequately protected. DO NOT SET THIS FLAG TO TRUE
2588  * without considering the security of your index.
2589  *
2590  * @since libnotmuch 5.1 (notmuch 0.26)
2591  */
2592 notmuch_status_t
2593 notmuch_indexopts_set_decrypt_policy (notmuch_indexopts_t *indexopts,
2594                                       notmuch_decryption_policy_t decrypt_policy);
2595
2596 /**
2597  * Return whether to decrypt encrypted parts while indexing.
2598  * see notmuch_indexopts_set_decrypt_policy.
2599  *
2600  * @since libnotmuch 5.1 (notmuch 0.26)
2601  */
2602 notmuch_decryption_policy_t
2603 notmuch_indexopts_get_decrypt_policy (const notmuch_indexopts_t *indexopts);
2604
2605 /**
2606  * Destroy a notmuch_indexopts_t object.
2607  *
2608  * @since libnotmuch 5.1 (notmuch 0.26)
2609  */
2610 void
2611 notmuch_indexopts_destroy (notmuch_indexopts_t *options);
2612
2613
2614 /**
2615  * interrogate the library for compile time features
2616  *
2617  * @since libnotmuch 4.4 (notmuch 0.23)
2618  */
2619 notmuch_bool_t
2620 notmuch_built_with (const char *name);
2621 /**@}*/
2622
2623 #pragma GCC visibility pop
2624
2625 NOTMUCH_END_DECLS
2626
2627 #endif