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