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