57 const char *db_filename = NULL;
61 db_filename =
mdata->db_url->path;
63 db_filename = c_nm_default_url;
66 if (!db_filename && !c_folder)
70 db_filename = c_folder;
79#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
85static const char *get_nm_config_file(
void)
87 const char *config_to_use = NULL;
91 if (!c_nm_config_file)
97 config_to_use = c_nm_config_file;
100 return config_to_use;
113 notmuch_database_t *db = NULL;
115 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
120 writable ?
"[WRITE]" :
"[READ]", c_nm_open_timeout);
122 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
123 NOTMUCH_DATABASE_MODE_READ_ONLY;
127#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
129 const char *config_file = get_nm_config_file();
132 st = notmuch_database_open_with_config(filename, mode, config_file,
133 c_nm_config_profile, &db, &msg);
136 if (st == NOTMUCH_STATUS_NO_CONFIG && !
mutt_str_equal(config_file,
""))
143 st = notmuch_database_open_with_config(filename, mode,
"", NULL, &db, &msg);
145#elif LIBNOTMUCH_CHECK_VERSION(4, 2, 0)
146 st = notmuch_database_open_verbose(filename, mode, &db, &msg);
147#elif defined(NOTMUCH_API_3)
148 st = notmuch_database_open(filename, mode, &db);
150 db = notmuch_database_open(filename, mode);
152 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
153 ((ct / 2) > c_nm_open_timeout))
158 if (
verbose && ct && ((ct % 2) == 0))
159 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
164 if (st != NOTMUCH_STATUS_SUCCESS)
179 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
180 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
233 adata->longrun =
false;
244 notmuch_database_destroy(
db);
246 notmuch_database_close(
db);
267 if (notmuch_database_begin_atomic(
adata->db))
289 adata->trans =
false;
290 if (notmuch_database_end_atomic(
adata->db))
311 struct stat st = { 0 };
319 snprintf(path,
sizeof(path),
"%s/xapian", db_filename);
320 if (stat(path, &st) == 0)
322 *mtime = st.st_mtime;
327 snprintf(path,
sizeof(path),
"%s/.notmuch/xapian", db_filename);
329 if (stat(path, &st) != 0)
332 *mtime = st.st_mtime;
347 return adata->longrun;
362 adata->longrun =
true;
376 adata->longrun =
false;
380 adata->longrun =
true;
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Structs that make up an email.
#define mutt_debug(LEVEL,...)
enum MailboxType nm_path_probe(const char *path, const struct stat *st)
Is this a Notmuch Mailbox? - Implements MxOps::path_probe() -.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
void mutt_date_sleep_ms(size_t ms)
Sleep for milliseconds.
Convenience wrapper for the library headers.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
struct NmAccountData * nm_adata_get(struct Mailbox *m)
Get the Notmuch Account data.
notmuch_database_t * nm_db_get(struct Mailbox *m, bool writable)
Get the Notmuch database.
int nm_db_trans_begin(struct Mailbox *m)
Start a Notmuch database transaction.
notmuch_database_t * nm_db_do_open(const char *filename, bool writable, bool verbose)
Open a Notmuch database.
void nm_db_longrun_done(struct Mailbox *m)
Finish a long transaction.
const char * nm_db_get_filename(struct Mailbox *m)
Get the filename of the Notmuch database.
int nm_db_get_mtime(struct Mailbox *m, time_t *mtime)
Get the database modification time.
int nm_db_release(struct Mailbox *m)
Close the Notmuch database.
bool nm_db_is_longrun(struct Mailbox *m)
Is Notmuch in the middle of a long-running transaction.
void nm_db_longrun_init(struct Mailbox *m, bool writable)
Start a long transaction.
void nm_db_debug_check(struct Mailbox *m)
Check if the database is open.
void nm_db_free(notmuch_database_t *db)
Decoupled way to close a Notmuch database.
int nm_db_trans_end(struct Mailbox *m)
End a database transaction.
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Notmuch-specific Mailbox data.
const int NmUrlProtocolLen
Length of NmUrlProtocol string.
Pop-specific Account data.
void * adata
Private data (for Mailbox backends)
void * mdata
Driver specific data.
bool verbose
Display status messages?
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Notmuch-specific Account data -.
notmuch_database_t * db
Connection to Notmuch database.
Notmuch-specific Mailbox data -.