1 /* notmuch - Not much of an email library, (just index and search)
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
25 # define NOTMUCH_BEGIN_DECLS extern "C" {
26 # define NOTMUCH_END_DECLS }
28 # define NOTMUCH_BEGIN_DECLS
29 # define NOTMUCH_END_DECLS
34 /* Status codes used for the return values of most functions.
36 * A zero value (NOTMUCH_STATUS_SUCCESS) indicates that the function
37 * completed without error. Any other value indicates an error as
40 * NOTMUCH_STATUS_SUCCESS: No error occurred.
42 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred
44 * NOTMUCH_STATUS_FILE_NOT_EMAIL: A file was presented that doesn't
45 * appear to be an email message.
47 typedef enum _notmuch_status {
48 NOTMUCH_STATUS_SUCCESS = 0,
49 NOTMUCH_STATUS_XAPIAN_EXCEPTION,
50 NOTMUCH_STATUS_FILE_NOT_EMAIL
53 /* An opaque data structure representing a notmuch database. See
54 * notmuch_database_open and other notmuch_database functions
56 typedef struct _notmuch_database notmuch_database_t;
58 /* Create a new, empty notmuch database located at 'path'.
60 * The path should be a top-level directory to a collection of
61 * plain-text email messages (one message per file). This call will
62 * create a new ".notmuch" directory within 'path' where notmuch will
65 * Passing a value of NULL for 'path' will cause notmuch to open the
66 * default database. The default database path can be specified by the
67 * NOTMUCH_BASE environment variable, and is equivalent to
68 * ${HOME}/mail if NOTMUCH_BASE is not set.
70 * After a successful call to notmuch_database_create, the returned
71 * database will be open so the caller should call
72 * notmuch_database_close when finished with it.
74 * The database will not yet have any data in it
75 * (notmuch_database_create itself is a very cheap function). Messages
76 * contained within 'path' can be added to the database by calling
77 * notmuch_database_add_message.
79 * In case of any failure, this function returns NULL, (after printing
80 * an error message on stderr).
83 notmuch_database_create (const char *path);
85 /* Open a an existing notmuch database located at 'path'.
87 * The database should have been created at some time in the past,
88 * (not necessarily by this process), by calling
89 * notmuch_database_create with 'path'.
91 * An existing notmuch database can be identified by the presence of a
92 * directory named ".notmuch" below 'path'.
94 * Passing a value of NULL for 'path' will cause notmuch to open the
95 * default database. The default database path can be specified by the
96 * NOTMUCH_BASE environment variable, and is equivalent to
97 * ${HOME}/mail if NOTMUCH_BASE is not set.
99 * The caller should call notmuch_database_close when finished with
102 * In case of any failure, this function returns NULL, (after printing
103 * an error message on stderr).
106 notmuch_database_open (const char *path);
108 /* Close the given notmuch database, freeing all associated
109 * resources. See notmuch_database_open. */
111 notmuch_database_close (notmuch_database_t *database);
113 /* Lookup the default database path.
115 * This is the path that will be used by notmuch_database_create and
116 * notmuch_database_open if given a NULL path. Specifically it will be
117 * the value of the NOTMUCH_BASE environment variable if set,
118 * otherwise ${HOME}/mail
120 * Returns a newly allocated string which the caller should free()
121 * when finished with it.
124 notmuch_database_default_path (void);
126 /* Return the database path of the given database.
128 * The return value is a string owned by notmuch so should not be
129 * modified nor freed by the caller. */
131 notmuch_database_get_path (notmuch_database_t *database);
133 /* Add a new message to the given notmuch database.
135 * Here,'filename' should be a path relative to the the path of
136 * 'database' (see notmuch_database_get_path). The file should be a
137 * single mail message (not a multi-message mbox) that is expected to
138 * remain at its current location, (since the notmuch database will
139 * reference the filename, and will not copy the entire contents of
144 * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
146 * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
147 * like an email message. Nothing added to the database.
150 notmuch_database_add_message (notmuch_database_t *database,
151 const char *filename);