66 const char *db_filename = NULL;
70 db_filename =
mdata->db_url->path;
72 db_filename = c_nm_default_url;
84#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
90static const char *get_nm_config_file(
void)
92 const char *config_to_use = NULL;
96 if (!c_nm_config_file)
102 config_to_use = c_nm_config_file;
105 return config_to_use;
118 notmuch_database_t *db = NULL;
120 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
124 mutt_debug(
LL_DEBUG1,
"nm: db open '%s' %s (timeout %d)\n", filename ? filename :
"(auto)",
125 writable ?
"[WRITE]" :
"[READ]", c_nm_open_timeout);
127 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
128 NOTMUCH_DATABASE_MODE_READ_ONLY;
132#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
134 const char *config_file = get_nm_config_file();
138 st = notmuch_database_open_with_config(filename, mode, config_file,
139 c_nm_config_profile, &db, &msg);
142 if ((st == NOTMUCH_STATUS_NO_CONFIG) && !
mutt_str_equal(config_file,
""))
149 st = notmuch_database_open_with_config(filename, mode,
"", NULL, &db, &msg);
151 else if ((st == NOTMUCH_STATUS_NO_CONFIG) && !config_file)
155#elif LIBNOTMUCH_CHECK_VERSION(4, 2, 0)
156 st = notmuch_database_open_verbose(filename, mode, &db, &msg);
157#elif defined(NOTMUCH_API_3)
158 st = notmuch_database_open(filename, mode, &db);
160 db = notmuch_database_open(filename, mode);
162 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
163 ((ct / 2) > c_nm_open_timeout))
168 if (
verbose && ct && ((ct % 2) == 0))
169 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
174 if (st != NOTMUCH_STATUS_SUCCESS)
189 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
190 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
222#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
230 db_filename = c_folder;
254 adata->longrun =
false;
265 notmuch_database_destroy(
db);
267 notmuch_database_close(
db);
288 if (notmuch_database_begin_atomic(
adata->db))
310 adata->trans =
false;
311 if (notmuch_database_end_atomic(
adata->db))
332 struct stat st = { 0 };
342 snprintf(path,
sizeof(path),
"%s/xapian", db_filename);
343 if (stat(path, &st) == 0)
345 *mtime = st.st_mtime;
350 snprintf(path,
sizeof(path),
"%s/.notmuch/xapian", db_filename);
352 if (stat(path, &st) != 0)
355 *mtime = st.st_mtime;
370 return adata->longrun;
385 adata->longrun =
true;
399 adata->longrun =
false;
403 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.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
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?
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
#define FREE(x)
Free memory and set the pointer to NULL.
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-specific 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.
Notmuch virtual mailbox type.
struct NmMboxData * nm_mdata_get(struct Mailbox *m)
Get the Notmuch Mailbox data.
Notmuch-specific Mailbox data.
const int NmUrlProtocolLen
Length of NmUrlProtocol string.
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 -.