]> git.notmuchmail.org Git - notmuch/blob - lib/notmuch.h
44b0c4608c39302a3d79666a7b3180eed683cae7
[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 http://www.gnu.org/licenses/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #ifndef NOTMUCH_H
22 #define NOTMUCH_H
23
24 #ifdef  __cplusplus
25 # define NOTMUCH_BEGIN_DECLS  extern "C" {
26 # define NOTMUCH_END_DECLS    }
27 #else
28 # define NOTMUCH_BEGIN_DECLS
29 # define NOTMUCH_END_DECLS
30 #endif
31
32 NOTMUCH_BEGIN_DECLS
33
34 #include <time.h>
35
36 #ifndef FALSE
37 #define FALSE 0
38 #endif
39
40 #ifndef TRUE
41 #define TRUE 1
42 #endif
43
44 typedef int notmuch_bool_t;
45
46 /* Status codes used for the return values of most functions.
47  *
48  * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
49  * completed without error. Any other value indicates an error as
50  * follows:
51  *
52  * NOTMUCH_STATUS_SUCCESS: No error occurred.
53  *
54  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory
55  *
56  * XXX: We don't really want to expose this lame XAPIAN_EXCEPTION
57  * value. Instead we should map to things like DATABASE_LOCKED or
58  * whatever.
59  *
60  * NOTMUCH_STATUS_READ_ONLY_DATABASE: An attempt was made to write to
61  *      a database opened in read-only mode.
62  *
63  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
64  *
65  * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to read or
66  *      write to a file (this could be file not found, permission
67  *      denied, etc.)
68  *
69  * NOTMUCH_STATUS_FILE_NOT_EMAIL: A file was presented that doesn't
70  *      appear to be an email message.
71  *
72  * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: A file contains a message ID
73  *      that is identical to a message already in the database.
74  *
75  * NOTMUCH_STATUS_NULL_POINTER: The user erroneously passed a NULL
76  *      pointer to a notmuch function.
77  *
78  * NOTMUCH_STATUS_TAG_TOO_LONG: A tag value is too long (exceeds
79  *      NOTMUCH_TAG_MAX)
80  *
81  * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: The notmuch_message_thaw
82  *      function has been called more times than notmuch_message_freeze.
83  *
84  * NOTMUCH_STATUS_UNBALANCED_ATOMIC: notmuch_database_end_atomic has
85  *      been called more times than notmuch_database_begin_atomic.
86  *
87  * And finally:
88  *
89  * NOTMUCH_STATUS_LAST_STATUS: Not an actual status value. Just a way
90  *      to find out how many valid status values there are.
91  */
92 typedef enum _notmuch_status {
93     NOTMUCH_STATUS_SUCCESS = 0,
94     NOTMUCH_STATUS_OUT_OF_MEMORY,
95     NOTMUCH_STATUS_READ_ONLY_DATABASE,
96     NOTMUCH_STATUS_XAPIAN_EXCEPTION,
97     NOTMUCH_STATUS_FILE_ERROR,
98     NOTMUCH_STATUS_FILE_NOT_EMAIL,
99     NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID,
100     NOTMUCH_STATUS_NULL_POINTER,
101     NOTMUCH_STATUS_TAG_TOO_LONG,
102     NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW,
103     NOTMUCH_STATUS_UNBALANCED_ATOMIC,
104
105     NOTMUCH_STATUS_LAST_STATUS
106 } notmuch_status_t;
107
108 /* Get a string representation of a notmuch_status_t value.
109  *
110  * The result is read-only.
111  */
112 const char *
113 notmuch_status_to_string (notmuch_status_t status);
114
115 /* Various opaque data types. For each notmuch_<foo>_t see the various
116  * notmuch_<foo> functions below. */
117 typedef struct _notmuch_database notmuch_database_t;
118 typedef struct _notmuch_query notmuch_query_t;
119 typedef struct _notmuch_threads notmuch_threads_t;
120 typedef struct _notmuch_thread notmuch_thread_t;
121 typedef struct _notmuch_messages notmuch_messages_t;
122 typedef struct _notmuch_message notmuch_message_t;
123 typedef struct _notmuch_tags notmuch_tags_t;
124 typedef struct _notmuch_directory notmuch_directory_t;
125 typedef struct _notmuch_filenames notmuch_filenames_t;
126
127 /* Create a new, empty notmuch database located at 'path'.
128  *
129  * The path should be a top-level directory to a collection of
130  * plain-text email messages (one message per file). This call will
131  * create a new ".notmuch" directory within 'path' where notmuch will
132  * store its data.
133  *
134  * After a successful call to notmuch_database_create, the returned
135  * database will be open so the caller should call
136  * notmuch_database_destroy when finished with it.
137  *
138  * The database will not yet have any data in it
139  * (notmuch_database_create itself is a very cheap function). Messages
140  * contained within 'path' can be added to the database by calling
141  * notmuch_database_add_message.
142  *
143  * In case of any failure, this function returns NULL, (after printing
144  * an error message on stderr).
145  */
146 notmuch_database_t *
147 notmuch_database_create (const char *path);
148
149 typedef enum {
150     NOTMUCH_DATABASE_MODE_READ_ONLY = 0,
151     NOTMUCH_DATABASE_MODE_READ_WRITE
152 } notmuch_database_mode_t;
153
154 /* Open an existing notmuch database located at 'path'.
155  *
156  * The database should have been created at some time in the past,
157  * (not necessarily by this process), by calling
158  * notmuch_database_create with 'path'. By default the database should be
159  * opened for reading only. In order to write to the database you need to
160  * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode.
161  *
162  * An existing notmuch database can be identified by the presence of a
163  * directory named ".notmuch" below 'path'.
164  *
165  * The caller should call notmuch_database_destroy when finished with
166  * this database.
167  *
168  * In case of any failure, this function returns an error status and
169  * sets *database to NULL (after printing an error message on stderr).
170  *
171  * Return value:
172  *
173  * NOTMUCH_STATUS_SUCCESS: Successfully opened the database.
174  *
175  * NOTMUCH_STATUS_NULL_POINTER: The given 'path' argument is NULL.
176  *
177  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory.
178  *
179  * NOTMUCH_STATUS_FILE_ERROR: An error occurred trying to open the
180  *      database file (such as permission denied, or file not found,
181  *      etc.), or the database version is unknown.
182  *
183  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred.
184  */
185 notmuch_status_t
186 notmuch_database_open (const char *path,
187                        notmuch_database_mode_t mode,
188                        notmuch_database_t **database);
189
190 /* Close the given notmuch database.
191  *
192  * After notmuch_database_close has been called, calls to other
193  * functions on objects derived from this database may either behave
194  * as if the database had not been closed (e.g., if the required data
195  * has been cached) or may fail with a
196  * NOTMUCH_STATUS_XAPIAN_EXCEPTION.
197  *
198  * notmuch_database_close can be called multiple times.  Later calls
199  * have no effect.
200  */
201 void
202 notmuch_database_close (notmuch_database_t *database);
203
204 /* Destroy the notmuch database, closing it if necessary and freeing
205 * all associated resources. */
206 void
207 notmuch_database_destroy (notmuch_database_t *database);
208
209 /* Return the database path of the given database.
210  *
211  * The return value is a string owned by notmuch so should not be
212  * modified nor freed by the caller. */
213 const char *
214 notmuch_database_get_path (notmuch_database_t *database);
215
216 /* Return the database format version of the given database. */
217 unsigned int
218 notmuch_database_get_version (notmuch_database_t *database);
219
220 /* Does this database need to be upgraded before writing to it?
221  *
222  * If this function returns TRUE then no functions that modify the
223  * database (notmuch_database_add_message, notmuch_message_add_tag,
224  * notmuch_directory_set_mtime, etc.) will work unless the function
225  * notmuch_database_upgrade is called successfully first. */
226 notmuch_bool_t
227 notmuch_database_needs_upgrade (notmuch_database_t *database);
228
229 /* Upgrade the current database.
230  *
231  * After opening a database in read-write mode, the client should
232  * check if an upgrade is needed (notmuch_database_needs_upgrade) and
233  * if so, upgrade with this function before making any modifications.
234  *
235  * The optional progress_notify callback can be used by the caller to
236  * provide progress indication to the user. If non-NULL it will be
237  * called periodically with 'progress' as a floating-point value in
238  * the range of [0.0 .. 1.0] indicating the progress made so far in
239  * the upgrade process.
240  */
241 notmuch_status_t
242 notmuch_database_upgrade (notmuch_database_t *database,
243                           void (*progress_notify) (void *closure,
244                                                    double progress),
245                           void *closure);
246
247 /* Begin an atomic database operation.
248  *
249  * Any modifications performed between a successful begin and a
250  * notmuch_database_end_atomic will be applied to the database
251  * atomically.  Note that, unlike a typical database transaction, this
252  * only ensures atomicity, not durability; neither begin nor end
253  * necessarily flush modifications to disk.
254  *
255  * Atomic sections may be nested.  begin_atomic and end_atomic must
256  * always be called in pairs.
257  *
258  * Return value:
259  *
260  * NOTMUCH_STATUS_SUCCESS: Successfully entered atomic section.
261  *
262  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
263  *      atomic section not entered.
264  */
265 notmuch_status_t
266 notmuch_database_begin_atomic (notmuch_database_t *notmuch);
267
268 /* Indicate the end of an atomic database operation.
269  *
270  * Return value:
271  *
272  * NOTMUCH_STATUS_SUCCESS: Successfully completed atomic section.
273  *
274  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
275  *      atomic section not ended.
276  *
277  * NOTMUCH_STATUS_UNBALANCED_ATOMIC: The database is not currently in
278  *      an atomic section.
279  */
280 notmuch_status_t
281 notmuch_database_end_atomic (notmuch_database_t *notmuch);
282
283 /* Retrieve a directory object from the database for 'path'.
284  *
285  * Here, 'path' should be a path relative to the path of 'database'
286  * (see notmuch_database_get_path), or else should be an absolute path
287  * with initial components that match the path of 'database'.
288  *
289  * Can return NULL if a Xapian exception occurs.
290  */
291 notmuch_directory_t *
292 notmuch_database_get_directory (notmuch_database_t *database,
293                                 const char *path);
294
295 /* Add a new message to the given notmuch database or associate an
296  * additional filename with an existing message.
297  *
298  * Here, 'filename' should be a path relative to the path of
299  * 'database' (see notmuch_database_get_path), or else should be an
300  * absolute filename with initial components that match the path of
301  * 'database'.
302  *
303  * The file should be a single mail message (not a multi-message mbox)
304  * that is expected to remain at its current location, (since the
305  * notmuch database will reference the filename, and will not copy the
306  * entire contents of the file.
307  *
308  * If another message with the same message ID already exists in the
309  * database, rather than creating a new message, this adds 'filename'
310  * to the list of the filenames for the existing message.
311  *
312  * If 'message' is not NULL, then, on successful return
313  * (NOTMUCH_STATUS_SUCCESS or NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) '*message'
314  * will be initialized to a message object that can be used for things
315  * such as adding tags to the just-added message. The user should call
316  * notmuch_message_destroy when done with the message. On any failure
317  * '*message' will be set to NULL.
318  *
319  * Return value:
320  *
321  * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
322  *
323  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
324  *      message not added.
325  *
326  * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
327  *      ID as another message already in the database. The new
328  *      filename was successfully added to the message in the database
329  *      (if not already present) and the existing message is returned.
330  *
331  * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the
332  *      file, (such as permission denied, or file not found,
333  *      etc.). Nothing added to the database.
334  *
335  * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
336  *      like an email message. Nothing added to the database.
337  *
338  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
339  *      mode so no message can be added.
340  */
341 notmuch_status_t
342 notmuch_database_add_message (notmuch_database_t *database,
343                               const char *filename,
344                               notmuch_message_t **message);
345
346 /* Remove a message filename from the given notmuch database. If the
347  * message has no more filenames, remove the message.
348  *
349  * If the same message (as determined by the message ID) is still
350  * available via other filenames, then the message will persist in the
351  * database for those filenames. When the last filename is removed for
352  * a particular message, the database content for that message will be
353  * entirely removed.
354  *
355  * Return value:
356  *
357  * NOTMUCH_STATUS_SUCCESS: The last filename was removed and the
358  *      message was removed from the database.
359  *
360  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
361  *      message not removed.
362  *
363  * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: This filename was removed but
364  *      the message persists in the database with at least one other
365  *      filename.
366  *
367  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
368  *      mode so no message can be removed.
369  */
370 notmuch_status_t
371 notmuch_database_remove_message (notmuch_database_t *database,
372                                  const char *filename);
373
374 /* Find a message with the given message_id.
375  *
376  * If a message with the given message_id is found then, on successful return
377  * (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to a message
378  * object.  The caller should call notmuch_message_destroy when done with the
379  * message.
380  *
381  * On any failure or when the message is not found, this function initializes
382  * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
383  * caller is supposed to check '*message' for NULL to find out whether the
384  * message with the given message_id was found.
385  *
386  * Return value:
387  *
388  * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'.
389  *
390  * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
391  *
392  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating message object
393  *
394  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
395  */
396 notmuch_status_t
397 notmuch_database_find_message (notmuch_database_t *database,
398                                const char *message_id,
399                                notmuch_message_t **message);
400
401 /* Find a message with the given filename.
402  *
403  * If the database contains a message with the given filename then, on
404  * successful return (NOTMUCH_STATUS_SUCCESS) '*message' will be initialized to
405  * a message object. The caller should call notmuch_message_destroy when done
406  * with the message.
407  *
408  * On any failure or when the message is not found, this function initializes
409  * '*message' to NULL. This means, when NOTMUCH_STATUS_SUCCESS is returned, the
410  * caller is supposed to check '*message' for NULL to find out whether the
411  * message with the given filename is found.
412  *
413  * Return value:
414  *
415  * NOTMUCH_STATUS_SUCCESS: Successful return, check '*message'
416  *
417  * NOTMUCH_STATUS_NULL_POINTER: The given 'message' argument is NULL
418  *
419  * NOTMUCH_STATUS_OUT_OF_MEMORY: Out of memory, creating the message object
420  *
421  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
422  */
423 notmuch_status_t
424 notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
425                                            const char *filename,
426                                            notmuch_message_t **message);
427
428 /* Return a list of all tags found in the database.
429  *
430  * This function creates a list of all tags found in the database. The
431  * resulting list contains all tags from all messages found in the database.
432  *
433  * On error this function returns NULL.
434  */
435 notmuch_tags_t *
436 notmuch_database_get_all_tags (notmuch_database_t *db);
437
438 /* Create a new query for 'database'.
439  *
440  * Here, 'database' should be an open database, (see
441  * notmuch_database_open and notmuch_database_create).
442  *
443  * For the query string, we'll document the syntax here more
444  * completely in the future, but it's likely to be a specialized
445  * version of the general Xapian query syntax:
446  *
447  * http://xapian.org/docs/queryparser.html
448  *
449  * As a special case, passing either a length-zero string, (that is ""),
450  * or a string consisting of a single asterisk (that is "*"), will
451  * result in a query that returns all messages in the database.
452  *
453  * See notmuch_query_set_sort for controlling the order of results.
454  * See notmuch_query_search_messages and notmuch_query_search_threads
455  * to actually execute the query.
456  *
457  * User should call notmuch_query_destroy when finished with this
458  * query.
459  *
460  * Will return NULL if insufficient memory is available.
461  */
462 notmuch_query_t *
463 notmuch_query_create (notmuch_database_t *database,
464                       const char *query_string);
465
466 /* Sort values for notmuch_query_set_sort */
467 typedef enum {
468     NOTMUCH_SORT_OLDEST_FIRST,
469     NOTMUCH_SORT_NEWEST_FIRST,
470     NOTMUCH_SORT_MESSAGE_ID,
471     NOTMUCH_SORT_UNSORTED
472 } notmuch_sort_t;
473
474 /* Return the query_string of this query. See notmuch_query_create. */
475 const char *
476 notmuch_query_get_query_string (notmuch_query_t *query);
477
478 /* Specify whether to omit excluded results or simply flag them.  By
479  * default, this is set to TRUE.
480  *
481  * If this is TRUE, notmuch_query_search_messages will omit excluded
482  * messages from the results.  notmuch_query_search_threads will omit
483  * threads that match only in excluded messages, but will include all
484  * messages in threads that match in at least one non-excluded
485  * message.
486  *
487  * The performance difference when calling
488  * notmuch_query_search_messages should be relatively small (and both
489  * should be very fast).  However, in some cases,
490  * notmuch_query_search_threads is very much faster when omitting
491  * excluded messages as it does not need to construct the threads that
492  * only match in excluded messages.
493  */
494
495 void
496 notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded);
497
498 /* Specify the sorting desired for this query. */
499 void
500 notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);
501
502 /* Return the sort specified for this query. See notmuch_query_set_sort. */
503 notmuch_sort_t
504 notmuch_query_get_sort (notmuch_query_t *query);
505
506 /* Add a tag that will be excluded from the query results by default.
507  * This exclusion will be overridden if this tag appears explicitly in
508  * the query. */
509 void
510 notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
511
512 /* Execute a query for threads, returning a notmuch_threads_t object
513  * which can be used to iterate over the results. The returned threads
514  * object is owned by the query and as such, will only be valid until
515  * notmuch_query_destroy.
516  *
517  * Typical usage might be:
518  *
519  *     notmuch_query_t *query;
520  *     notmuch_threads_t *threads;
521  *     notmuch_thread_t *thread;
522  *
523  *     query = notmuch_query_create (database, query_string);
524  *
525  *     for (threads = notmuch_query_search_threads (query);
526  *          notmuch_threads_valid (threads);
527  *          notmuch_threads_move_to_next (threads))
528  *     {
529  *         thread = notmuch_threads_get (threads);
530  *         ....
531  *         notmuch_thread_destroy (thread);
532  *     }
533  *
534  *     notmuch_query_destroy (query);
535  *
536  * Note: If you are finished with a thread before its containing
537  * query, you can call notmuch_thread_destroy to clean up some memory
538  * sooner (as in the above example). Otherwise, if your thread objects
539  * are long-lived, then you don't need to call notmuch_thread_destroy
540  * and all the memory will still be reclaimed when the query is
541  * destroyed.
542  *
543  * Note that there's no explicit destructor needed for the
544  * notmuch_threads_t object. (For consistency, we do provide a
545  * notmuch_threads_destroy function, but there's no good reason
546  * to call it if the query is about to be destroyed).
547  *
548  * If a Xapian exception occurs this function will return NULL.
549  */
550 notmuch_threads_t *
551 notmuch_query_search_threads (notmuch_query_t *query);
552
553 /* Execute a query for messages, returning a notmuch_messages_t object
554  * which can be used to iterate over the results. The returned
555  * messages object is owned by the query and as such, will only be
556  * valid until notmuch_query_destroy.
557  *
558  * Typical usage might be:
559  *
560  *     notmuch_query_t *query;
561  *     notmuch_messages_t *messages;
562  *     notmuch_message_t *message;
563  *
564  *     query = notmuch_query_create (database, query_string);
565  *
566  *     for (messages = notmuch_query_search_messages (query);
567  *          notmuch_messages_valid (messages);
568  *          notmuch_messages_move_to_next (messages))
569  *     {
570  *         message = notmuch_messages_get (messages);
571  *         ....
572  *         notmuch_message_destroy (message);
573  *     }
574  *
575  *     notmuch_query_destroy (query);
576  *
577  * Note: If you are finished with a message before its containing
578  * query, you can call notmuch_message_destroy to clean up some memory
579  * sooner (as in the above example). Otherwise, if your message
580  * objects are long-lived, then you don't need to call
581  * notmuch_message_destroy and all the memory will still be reclaimed
582  * when the query is destroyed.
583  *
584  * Note that there's no explicit destructor needed for the
585  * notmuch_messages_t object. (For consistency, we do provide a
586  * notmuch_messages_destroy function, but there's no good
587  * reason to call it if the query is about to be destroyed).
588  *
589  * If a Xapian exception occurs this function will return NULL.
590  */
591 notmuch_messages_t *
592 notmuch_query_search_messages (notmuch_query_t *query);
593
594 /* Destroy a notmuch_query_t along with any associated resources.
595  *
596  * This will in turn destroy any notmuch_threads_t and
597  * notmuch_messages_t objects generated by this query, (and in
598  * turn any notmuch_thread_t and notmuch_message_t objects generated
599  * from those results, etc.), if such objects haven't already been
600  * destroyed.
601  */
602 void
603 notmuch_query_destroy (notmuch_query_t *query);
604
605 /* Is the given 'threads' iterator pointing at a valid thread.
606  *
607  * When this function returns TRUE, notmuch_threads_get will return a
608  * valid object. Whereas when this function returns FALSE,
609  * notmuch_threads_get will return NULL.
610  *
611  * See the documentation of notmuch_query_search_threads for example
612  * code showing how to iterate over a notmuch_threads_t object.
613  */
614 notmuch_bool_t
615 notmuch_threads_valid (notmuch_threads_t *threads);
616
617 /* Get the current thread from 'threads' as a notmuch_thread_t.
618  *
619  * Note: The returned thread belongs to 'threads' and has a lifetime
620  * identical to it (and the query to which it belongs).
621  *
622  * See the documentation of notmuch_query_search_threads for example
623  * code showing how to iterate over a notmuch_threads_t object.
624  *
625  * If an out-of-memory situation occurs, this function will return
626  * NULL.
627  */
628 notmuch_thread_t *
629 notmuch_threads_get (notmuch_threads_t *threads);
630
631 /* Move the 'threads' iterator to the next thread.
632  *
633  * If 'threads' is already pointing at the last thread then the
634  * iterator will be moved to a point just beyond that last thread,
635  * (where notmuch_threads_valid will return FALSE and
636  * notmuch_threads_get will return NULL).
637  *
638  * See the documentation of notmuch_query_search_threads for example
639  * code showing how to iterate over a notmuch_threads_t object.
640  */
641 void
642 notmuch_threads_move_to_next (notmuch_threads_t *threads);
643
644 /* Destroy a notmuch_threads_t object.
645  *
646  * It's not strictly necessary to call this function. All memory from
647  * the notmuch_threads_t object will be reclaimed when the
648  * containing query object is destroyed.
649  */
650 void
651 notmuch_threads_destroy (notmuch_threads_t *threads);
652
653 /* Return an estimate of the number of messages matching a search
654  *
655  * This function performs a search and returns Xapian's best
656  * guess as to number of matching messages.
657  *
658  * If a Xapian exception occurs, this function may return 0 (after
659  * printing a message).
660  */
661 unsigned
662 notmuch_query_count_messages (notmuch_query_t *query);
663  
664 /* Return the number of threads matching a search.
665  *
666  * This function performs a search and returns the number of unique thread IDs
667  * in the matching messages. This is the same as number of threads matching a
668  * search.
669  *
670  * Note that this is a significantly heavier operation than
671  * notmuch_query_count_messages().
672  *
673  * If an error occurs, this function may return 0.
674  */
675 unsigned
676 notmuch_query_count_threads (notmuch_query_t *query);
677
678 /* Get the thread ID of 'thread'.
679  *
680  * The returned string belongs to 'thread' and as such, should not be
681  * modified by the caller and will only be valid for as long as the
682  * thread is valid, (which is until notmuch_thread_destroy or until
683  * the query from which it derived is destroyed).
684  */
685 const char *
686 notmuch_thread_get_thread_id (notmuch_thread_t *thread);
687
688 /* Get the total number of messages in 'thread'.
689  *
690  * This count consists of all messages in the database belonging to
691  * this thread. Contrast with notmuch_thread_get_matched_messages() .
692  */
693 int
694 notmuch_thread_get_total_messages (notmuch_thread_t *thread);
695
696 /* Get a notmuch_messages_t iterator for the top-level messages in
697  * 'thread'.
698  *
699  * This iterator will not necessarily iterate over all of the messages
700  * in the thread. It will only iterate over the messages in the thread
701  * which are not replies to other messages in the thread.
702  *
703  * To iterate over all messages in the thread, the caller will need to
704  * iterate over the result of notmuch_message_get_replies for each
705  * top-level message (and do that recursively for the resulting
706  * messages, etc.).
707  */
708 notmuch_messages_t *
709 notmuch_thread_get_toplevel_messages (notmuch_thread_t *thread);
710
711 /* Get the number of messages in 'thread' that matched the search.
712  *
713  * This count includes only the messages in this thread that were
714  * matched by the search from which the thread was created and were
715  * not excluded by any exclude tags passed in with the query (see
716  * notmuch_query_add_tag_exclude). Contrast with
717  * notmuch_thread_get_total_messages() .
718  */
719 int
720 notmuch_thread_get_matched_messages (notmuch_thread_t *thread);
721
722 /* Get the authors of 'thread'
723  *
724  * The returned string is a comma-separated list of the names of the
725  * authors of mail messages in the query results that belong to this
726  * thread.
727  *
728  * The returned string belongs to 'thread' and as such, should not be
729  * modified by the caller and will only be valid for as long as the
730  * thread is valid, (which is until notmuch_thread_destroy or until
731  * the query from which it derived is destroyed).
732  */
733 const char *
734 notmuch_thread_get_authors (notmuch_thread_t *thread);
735
736 /* Get the subject of 'thread'
737  *
738  * The subject is taken from the first message (according to the query
739  * order---see notmuch_query_set_sort) in the query results that
740  * belongs to this thread.
741  *
742  * The returned string belongs to 'thread' and as such, should not be
743  * modified by the caller and will only be valid for as long as the
744  * thread is valid, (which is until notmuch_thread_destroy or until
745  * the query from which it derived is destroyed).
746  */
747 const char *
748 notmuch_thread_get_subject (notmuch_thread_t *thread);
749
750 /* Get the date of the oldest message in 'thread' as a time_t value.
751  */
752 time_t
753 notmuch_thread_get_oldest_date (notmuch_thread_t *thread);
754
755 /* Get the date of the newest message in 'thread' as a time_t value.
756  */
757 time_t
758 notmuch_thread_get_newest_date (notmuch_thread_t *thread);
759
760 /* Get the tags for 'thread', returning a notmuch_tags_t object which
761  * can be used to iterate over all tags.
762  *
763  * Note: In the Notmuch database, tags are stored on individual
764  * messages, not on threads. So the tags returned here will be all
765  * tags of the messages which matched the search and which belong to
766  * this thread.
767  *
768  * The tags object is owned by the thread and as such, will only be
769  * valid for as long as the thread is valid, (for example, until
770  * notmuch_thread_destroy or until the query from which it derived is
771  * destroyed).
772  *
773  * Typical usage might be:
774  *
775  *     notmuch_thread_t *thread;
776  *     notmuch_tags_t *tags;
777  *     const char *tag;
778  *
779  *     thread = notmuch_threads_get (threads);
780  *
781  *     for (tags = notmuch_thread_get_tags (thread);
782  *          notmuch_tags_valid (tags);
783  *          notmuch_result_move_to_next (tags))
784  *     {
785  *         tag = notmuch_tags_get (tags);
786  *         ....
787  *     }
788  *
789  *     notmuch_thread_destroy (thread);
790  *
791  * Note that there's no explicit destructor needed for the
792  * notmuch_tags_t object. (For consistency, we do provide a
793  * notmuch_tags_destroy function, but there's no good reason to call
794  * it if the message is about to be destroyed).
795  */
796 notmuch_tags_t *
797 notmuch_thread_get_tags (notmuch_thread_t *thread);
798
799 /* Destroy a notmuch_thread_t object. */
800 void
801 notmuch_thread_destroy (notmuch_thread_t *thread);
802
803 /* Is the given 'messages' iterator pointing at a valid message.
804  *
805  * When this function returns TRUE, notmuch_messages_get will return a
806  * valid object. Whereas when this function returns FALSE,
807  * notmuch_messages_get will return NULL.
808  *
809  * See the documentation of notmuch_query_search_messages for example
810  * code showing how to iterate over a notmuch_messages_t object.
811  */
812 notmuch_bool_t
813 notmuch_messages_valid (notmuch_messages_t *messages);
814
815 /* Get the current message from 'messages' as a notmuch_message_t.
816  *
817  * Note: The returned message belongs to 'messages' and has a lifetime
818  * identical to it (and the query to which it belongs).
819  *
820  * See the documentation of notmuch_query_search_messages for example
821  * code showing how to iterate over a notmuch_messages_t object.
822  *
823  * If an out-of-memory situation occurs, this function will return
824  * NULL.
825  */
826 notmuch_message_t *
827 notmuch_messages_get (notmuch_messages_t *messages);
828
829 /* Move the 'messages' iterator to the next message.
830  *
831  * If 'messages' is already pointing at the last message then the
832  * iterator will be moved to a point just beyond that last message,
833  * (where notmuch_messages_valid will return FALSE and
834  * notmuch_messages_get will return NULL).
835  *
836  * See the documentation of notmuch_query_search_messages for example
837  * code showing how to iterate over a notmuch_messages_t object.
838  */
839 void
840 notmuch_messages_move_to_next (notmuch_messages_t *messages);
841
842 /* Destroy a notmuch_messages_t object.
843  *
844  * It's not strictly necessary to call this function. All memory from
845  * the notmuch_messages_t object will be reclaimed when the containing
846  * query object is destroyed.
847  */
848 void
849 notmuch_messages_destroy (notmuch_messages_t *messages);
850
851 /* Return a list of tags from all messages.
852  *
853  * The resulting list is guaranteed not to contain duplicated tags.
854  *
855  * WARNING: You can no longer iterate over messages after calling this
856  * function, because the iterator will point at the end of the list.
857  * We do not have a function to reset the iterator yet and the only
858  * way how you can iterate over the list again is to recreate the
859  * message list.
860  *
861  * The function returns NULL on error.
862  */
863 notmuch_tags_t *
864 notmuch_messages_collect_tags (notmuch_messages_t *messages);
865
866 /* Get the message ID of 'message'.
867  *
868  * The returned string belongs to 'message' and as such, should not be
869  * modified by the caller and will only be valid for as long as the
870  * message is valid, (which is until the query from which it derived
871  * is destroyed).
872  *
873  * This function will not return NULL since Notmuch ensures that every
874  * message has a unique message ID, (Notmuch will generate an ID for a
875  * message if the original file does not contain one).
876  */
877 const char *
878 notmuch_message_get_message_id (notmuch_message_t *message);
879
880 /* Get the thread ID of 'message'.
881  *
882  * The returned string belongs to 'message' and as such, should not be
883  * modified by the caller and will only be valid for as long as the
884  * message is valid, (for example, until the user calls
885  * notmuch_message_destroy on 'message' or until a query from which it
886  * derived is destroyed).
887  *
888  * This function will not return NULL since Notmuch ensures that every
889  * message belongs to a single thread.
890  */
891 const char *
892 notmuch_message_get_thread_id (notmuch_message_t *message);
893
894 /* Get a notmuch_messages_t iterator for all of the replies to
895  * 'message'.
896  *
897  * Note: This call only makes sense if 'message' was ultimately
898  * obtained from a notmuch_thread_t object, (such as by coming
899  * directly from the result of calling notmuch_thread_get_
900  * toplevel_messages or by any number of subsequent
901  * calls to notmuch_message_get_replies).
902  *
903  * If 'message' was obtained through some non-thread means, (such as
904  * by a call to notmuch_query_search_messages), then this function
905  * will return NULL.
906  *
907  * If there are no replies to 'message', this function will return
908  * NULL. (Note that notmuch_messages_valid will accept that NULL
909  * value as legitimate, and simply return FALSE for it.)
910  */
911 notmuch_messages_t *
912 notmuch_message_get_replies (notmuch_message_t *message);
913
914 /* Get a filename for the email corresponding to 'message'.
915  *
916  * The returned filename is an absolute filename, (the initial
917  * component will match notmuch_database_get_path() ).
918  *
919  * The returned string belongs to the message so should not be
920  * modified or freed by the caller (nor should it be referenced after
921  * the message is destroyed).
922  *
923  * Note: If this message corresponds to multiple files in the mail
924  * store, (that is, multiple files contain identical message IDs),
925  * this function will arbitrarily return a single one of those
926  * filenames. See notmuch_message_get_filenames for returning the
927  * complete list of filenames.
928  */
929 const char *
930 notmuch_message_get_filename (notmuch_message_t *message);
931
932 /* Get all filenames for the email corresponding to 'message'.
933  *
934  * Returns a notmuch_filenames_t iterator listing all the filenames
935  * associated with 'message'. These files may not have identical
936  * content, but each will have the identical Message-ID.
937  *
938  * Each filename in the iterator is an absolute filename, (the initial
939  * component will match notmuch_database_get_path() ).
940  */
941 notmuch_filenames_t *
942 notmuch_message_get_filenames (notmuch_message_t *message);
943
944 /* Message flags */
945 typedef enum _notmuch_message_flag {
946     NOTMUCH_MESSAGE_FLAG_MATCH,
947     NOTMUCH_MESSAGE_FLAG_EXCLUDED
948 } notmuch_message_flag_t;
949
950 /* Get a value of a flag for the email corresponding to 'message'. */
951 notmuch_bool_t
952 notmuch_message_get_flag (notmuch_message_t *message,
953                           notmuch_message_flag_t flag);
954
955 /* Set a value of a flag for the email corresponding to 'message'. */
956 void
957 notmuch_message_set_flag (notmuch_message_t *message,
958                           notmuch_message_flag_t flag, notmuch_bool_t value);
959
960 /* Get the date of 'message' as a time_t value.
961  *
962  * For the original textual representation of the Date header from the
963  * message call notmuch_message_get_header() with a header value of
964  * "date". */
965 time_t
966 notmuch_message_get_date  (notmuch_message_t *message);
967
968 /* Get the value of the specified header from 'message'.
969  *
970  * The value will be read from the actual message file, not from the
971  * notmuch database. The header name is case insensitive.
972  *
973  * The returned string belongs to the message so should not be
974  * modified or freed by the caller (nor should it be referenced after
975  * the message is destroyed).
976  *
977  * Returns an empty string ("") if the message does not contain a
978  * header line matching 'header'. Returns NULL if any error occurs.
979  */
980 const char *
981 notmuch_message_get_header (notmuch_message_t *message, const char *header);
982
983 /* Get the tags for 'message', returning a notmuch_tags_t object which
984  * can be used to iterate over all tags.
985  *
986  * The tags object is owned by the message and as such, will only be
987  * valid for as long as the message is valid, (which is until the
988  * query from which it derived is destroyed).
989  *
990  * Typical usage might be:
991  *
992  *     notmuch_message_t *message;
993  *     notmuch_tags_t *tags;
994  *     const char *tag;
995  *
996  *     message = notmuch_database_find_message (database, message_id);
997  *
998  *     for (tags = notmuch_message_get_tags (message);
999  *          notmuch_tags_valid (tags);
1000  *          notmuch_result_move_to_next (tags))
1001  *     {
1002  *         tag = notmuch_tags_get (tags);
1003  *         ....
1004  *     }
1005  *
1006  *     notmuch_message_destroy (message);
1007  *
1008  * Note that there's no explicit destructor needed for the
1009  * notmuch_tags_t object. (For consistency, we do provide a
1010  * notmuch_tags_destroy function, but there's no good reason to call
1011  * it if the message is about to be destroyed).
1012  */
1013 notmuch_tags_t *
1014 notmuch_message_get_tags (notmuch_message_t *message);
1015
1016 /* The longest possible tag value. */
1017 #define NOTMUCH_TAG_MAX 200
1018
1019 /* Add a tag to the given message.
1020  *
1021  * Return value:
1022  *
1023  * NOTMUCH_STATUS_SUCCESS: Tag successfully added to message
1024  *
1025  * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1026  *
1027  * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1028  *      (exceeds NOTMUCH_TAG_MAX)
1029  *
1030  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1031  *      mode so message cannot be modified.
1032  */
1033 notmuch_status_t
1034 notmuch_message_add_tag (notmuch_message_t *message, const char *tag);
1035
1036 /* Remove a tag from the given message.
1037  *
1038  * Return value:
1039  *
1040  * NOTMUCH_STATUS_SUCCESS: Tag successfully removed from message
1041  *
1042  * NOTMUCH_STATUS_NULL_POINTER: The 'tag' argument is NULL
1043  *
1044  * NOTMUCH_STATUS_TAG_TOO_LONG: The length of 'tag' is too long
1045  *      (exceeds NOTMUCH_TAG_MAX)
1046  *
1047  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1048  *      mode so message cannot be modified.
1049  */
1050 notmuch_status_t
1051 notmuch_message_remove_tag (notmuch_message_t *message, const char *tag);
1052
1053 /* Remove all tags from the given message.
1054  *
1055  * See notmuch_message_freeze for an example showing how to safely
1056  * replace tag values.
1057  *
1058  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1059  *      mode so message cannot be modified.
1060  */
1061 notmuch_status_t
1062 notmuch_message_remove_all_tags (notmuch_message_t *message);
1063
1064 /* Add/remove tags according to maildir flags in the message filename(s)
1065  *
1066  * This function examines the filenames of 'message' for maildir
1067  * flags, and adds or removes tags on 'message' as follows when these
1068  * flags are present:
1069  *
1070  *      Flag    Action if present
1071  *      ----    -----------------
1072  *      'D'     Adds the "draft" tag to the message
1073  *      'F'     Adds the "flagged" tag to the message
1074  *      'P'     Adds the "passed" tag to the message
1075  *      'R'     Adds the "replied" tag to the message
1076  *      'S'     Removes the "unread" tag from the message
1077  *
1078  * For each flag that is not present, the opposite action (add/remove)
1079  * is performed for the corresponding tags.
1080  *
1081  * Flags are identified as trailing components of the filename after a
1082  * sequence of ":2,".
1083  *
1084  * If there are multiple filenames associated with this message, the
1085  * flag is considered present if it appears in one or more
1086  * filenames. (That is, the flags from the multiple filenames are
1087  * combined with the logical OR operator.)
1088  *
1089  * A client can ensure that notmuch database tags remain synchronized
1090  * with maildir flags by calling this function after each call to
1091  * notmuch_database_add_message. See also
1092  * notmuch_message_tags_to_maildir_flags for synchronizing tag changes
1093  * back to maildir flags.
1094  */
1095 notmuch_status_t
1096 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
1097
1098 /* Rename message filename(s) to encode tags as maildir flags
1099  *
1100  * Specifically, for each filename corresponding to this message:
1101  *
1102  * If the filename is not in a maildir directory, do nothing.  (A
1103  * maildir directory is determined as a directory named "new" or
1104  * "cur".) Similarly, if the filename has invalid maildir info,
1105  * (repeated or outof-ASCII-order flag characters after ":2,"), then
1106  * do nothing.
1107  *
1108  * If the filename is in a maildir directory, rename the file so that
1109  * its filename ends with the sequence ":2," followed by zero or more
1110  * of the following single-character flags (in ASCII order):
1111  *
1112  *   'D' iff the message has the "draft" tag
1113  *   'F' iff the message has the "flagged" tag
1114  *   'P' iff the message has the "passed" tag
1115  *   'R' iff the message has the "replied" tag
1116  *   'S' iff the message does not have the "unread" tag
1117  *
1118  * Any existing flags unmentioned in the list above will be preserved
1119  * in the renaming.
1120  *
1121  * Also, if this filename is in a directory named "new", rename it to
1122  * be within the neighboring directory named "cur".
1123  *
1124  * A client can ensure that maildir filename flags remain synchronized
1125  * with notmuch database tags by calling this function after changing
1126  * tags, (after calls to notmuch_message_add_tag,
1127  * notmuch_message_remove_tag, or notmuch_message_freeze/
1128  * notmuch_message_thaw). See also notmuch_message_maildir_flags_to_tags
1129  * for synchronizing maildir flag changes back to tags.
1130  */
1131 notmuch_status_t
1132 notmuch_message_tags_to_maildir_flags (notmuch_message_t *message);
1133
1134 /* Freeze the current state of 'message' within the database.
1135  *
1136  * This means that changes to the message state, (via
1137  * notmuch_message_add_tag, notmuch_message_remove_tag, and
1138  * notmuch_message_remove_all_tags), will not be committed to the
1139  * database until the message is thawed with notmuch_message_thaw.
1140  *
1141  * Multiple calls to freeze/thaw are valid and these calls will
1142  * "stack". That is there must be as many calls to thaw as to freeze
1143  * before a message is actually thawed.
1144  *
1145  * The ability to do freeze/thaw allows for safe transactions to
1146  * change tag values. For example, explicitly setting a message to
1147  * have a given set of tags might look like this:
1148  *
1149  *    notmuch_message_freeze (message);
1150  *
1151  *    notmuch_message_remove_all_tags (message);
1152  *
1153  *    for (i = 0; i < NUM_TAGS; i++)
1154  *        notmuch_message_add_tag (message, tags[i]);
1155  *
1156  *    notmuch_message_thaw (message);
1157  *
1158  * With freeze/thaw used like this, the message in the database is
1159  * guaranteed to have either the full set of original tag values, or
1160  * the full set of new tag values, but nothing in between.
1161  *
1162  * Imagine the example above without freeze/thaw and the operation
1163  * somehow getting interrupted. This could result in the message being
1164  * left with no tags if the interruption happened after
1165  * notmuch_message_remove_all_tags but before notmuch_message_add_tag.
1166  *
1167  * Return value:
1168  *
1169  * NOTMUCH_STATUS_SUCCESS: Message successfully frozen.
1170  *
1171  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1172  *      mode so message cannot be modified.
1173  */
1174 notmuch_status_t
1175 notmuch_message_freeze (notmuch_message_t *message);
1176
1177 /* Thaw the current 'message', synchronizing any changes that may have
1178  * occurred while 'message' was frozen into the notmuch database.
1179  *
1180  * See notmuch_message_freeze for an example of how to use this
1181  * function to safely provide tag changes.
1182  *
1183  * Multiple calls to freeze/thaw are valid and these calls with
1184  * "stack". That is there must be as many calls to thaw as to freeze
1185  * before a message is actually thawed.
1186  *
1187  * Return value:
1188  *
1189  * NOTMUCH_STATUS_SUCCESS: Message successfully thawed, (or at least
1190  *      its frozen count has successfully been reduced by 1).
1191  *
1192  * NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW: An attempt was made to thaw
1193  *      an unfrozen message. That is, there have been an unbalanced
1194  *      number of calls to notmuch_message_freeze and
1195  *      notmuch_message_thaw.
1196  */
1197 notmuch_status_t
1198 notmuch_message_thaw (notmuch_message_t *message);
1199
1200 /* Destroy a notmuch_message_t object.
1201  *
1202  * It can be useful to call this function in the case of a single
1203  * query object with many messages in the result, (such as iterating
1204  * over the entire database). Otherwise, it's fine to never call this
1205  * function and there will still be no memory leaks. (The memory from
1206  * the messages get reclaimed when the containing query is destroyed.)
1207  */
1208 void
1209 notmuch_message_destroy (notmuch_message_t *message);
1210
1211 /* Is the given 'tags' iterator pointing at a valid tag.
1212  *
1213  * When this function returns TRUE, notmuch_tags_get will return a
1214  * valid string. Whereas when this function returns FALSE,
1215  * notmuch_tags_get will return NULL.
1216  *
1217  * See the documentation of notmuch_message_get_tags for example code
1218  * showing how to iterate over a notmuch_tags_t object.
1219  */
1220 notmuch_bool_t
1221 notmuch_tags_valid (notmuch_tags_t *tags);
1222
1223 /* Get the current tag from 'tags' as a string.
1224  *
1225  * Note: The returned string belongs to 'tags' and has a lifetime
1226  * identical to it (and the query to which it ultimately belongs).
1227  *
1228  * See the documentation of notmuch_message_get_tags for example code
1229  * showing how to iterate over a notmuch_tags_t object.
1230  */
1231 const char *
1232 notmuch_tags_get (notmuch_tags_t *tags);
1233
1234 /* Move the 'tags' iterator to the next tag.
1235  *
1236  * If 'tags' is already pointing at the last tag then the iterator
1237  * will be moved to a point just beyond that last tag, (where
1238  * notmuch_tags_valid will return FALSE and notmuch_tags_get will
1239  * return NULL).
1240  *
1241  * See the documentation of notmuch_message_get_tags for example code
1242  * showing how to iterate over a notmuch_tags_t object.
1243  */
1244 void
1245 notmuch_tags_move_to_next (notmuch_tags_t *tags);
1246
1247 /* Destroy a notmuch_tags_t object.
1248  *
1249  * It's not strictly necessary to call this function. All memory from
1250  * the notmuch_tags_t object will be reclaimed when the containing
1251  * message or query objects are destroyed.
1252  */
1253 void
1254 notmuch_tags_destroy (notmuch_tags_t *tags);
1255
1256 /* Store an mtime within the database for 'directory'.
1257  *
1258  * The 'directory' should be an object retrieved from the database
1259  * with notmuch_database_get_directory for a particular path.
1260  *
1261  * The intention is for the caller to use the mtime to allow efficient
1262  * identification of new messages to be added to the database. The
1263  * recommended usage is as follows:
1264  *
1265  *   o Read the mtime of a directory from the filesystem
1266  *
1267  *   o Call add_message for all mail files in the directory
1268  *
1269  *   o Call notmuch_directory_set_mtime with the mtime read from the
1270  *     filesystem.
1271  *
1272  * Then, when wanting to check for updates to the directory in the
1273  * future, the client can call notmuch_directory_get_mtime and know
1274  * that it only needs to add files if the mtime of the directory and
1275  * files are newer than the stored timestamp.
1276  *
1277  * Note: The notmuch_directory_get_mtime function does not allow the
1278  * caller to distinguish a timestamp of 0 from a non-existent
1279  * timestamp. So don't store a timestamp of 0 unless you are
1280  * comfortable with that.
1281  *
1282  * Return value:
1283  *
1284  * NOTMUCH_STATUS_SUCCESS: mtime successfully stored in database.
1285  *
1286  * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception
1287  *      occurred, mtime not stored.
1288  *
1289  * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
1290  *      mode so directory mtime cannot be modified.
1291  */
1292 notmuch_status_t
1293 notmuch_directory_set_mtime (notmuch_directory_t *directory,
1294                              time_t mtime);
1295
1296 /* Get the mtime of a directory, (as previously stored with
1297  * notmuch_directory_set_mtime).
1298  *
1299  * Returns 0 if no mtime has previously been stored for this
1300  * directory.*/
1301 time_t
1302 notmuch_directory_get_mtime (notmuch_directory_t *directory);
1303
1304 /* Get a notmuch_filenames_t iterator listing all the filenames of
1305  * messages in the database within the given directory.
1306  *
1307  * The returned filenames will be the basename-entries only (not
1308  * complete paths). */
1309 notmuch_filenames_t *
1310 notmuch_directory_get_child_files (notmuch_directory_t *directory);
1311
1312 /* Get a notmuch_filenams_t iterator listing all the filenames of
1313  * sub-directories in the database within the given directory.
1314  *
1315  * The returned filenames will be the basename-entries only (not
1316  * complete paths). */
1317 notmuch_filenames_t *
1318 notmuch_directory_get_child_directories (notmuch_directory_t *directory);
1319
1320 /* Destroy a notmuch_directory_t object. */
1321 void
1322 notmuch_directory_destroy (notmuch_directory_t *directory);
1323
1324 /* Is the given 'filenames' iterator pointing at a valid filename.
1325  *
1326  * When this function returns TRUE, notmuch_filenames_get will return
1327  * a valid string. Whereas when this function returns FALSE,
1328  * notmuch_filenames_get will return NULL.
1329  *
1330  * It is acceptable to pass NULL for 'filenames', in which case this
1331  * function will always return FALSE.
1332  */
1333 notmuch_bool_t
1334 notmuch_filenames_valid (notmuch_filenames_t *filenames);
1335
1336 /* Get the current filename from 'filenames' as a string.
1337  *
1338  * Note: The returned string belongs to 'filenames' and has a lifetime
1339  * identical to it (and the directory to which it ultimately belongs).
1340  *
1341  * It is acceptable to pass NULL for 'filenames', in which case this
1342  * function will always return NULL.
1343  */
1344 const char *
1345 notmuch_filenames_get (notmuch_filenames_t *filenames);
1346
1347 /* Move the 'filenames' iterator to the next filename.
1348  *
1349  * If 'filenames' is already pointing at the last filename then the
1350  * iterator will be moved to a point just beyond that last filename,
1351  * (where notmuch_filenames_valid will return FALSE and
1352  * notmuch_filenames_get will return NULL).
1353  *
1354  * It is acceptable to pass NULL for 'filenames', in which case this
1355  * function will do nothing.
1356  */
1357 void
1358 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
1359
1360 /* Destroy a notmuch_filenames_t object.
1361  *
1362  * It's not strictly necessary to call this function. All memory from
1363  * the notmuch_filenames_t object will be reclaimed when the
1364  * containing directory object is destroyed.
1365  *
1366  * It is acceptable to pass NULL for 'filenames', in which case this
1367  * function will do nothing.
1368  */
1369 void
1370 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
1371
1372 NOTMUCH_END_DECLS
1373
1374 #endif