61 const char *db_filename = NULL;
65 db_filename =
mdata->db_url->path;
67 db_filename = c_nm_default_url;
70 if (!db_filename && !c_folder)
74 db_filename = c_folder;
83#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
89static const char *get_nm_config_file(
void)
91 const char *config_to_use = NULL;
95 if (!c_nm_config_file)
101 config_to_use = c_nm_config_file;
104 return config_to_use;
117 notmuch_database_t *db = NULL;
119 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
124 writable ?
"[WRITE]" :
"[READ]", c_nm_open_timeout);
126 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
127 NOTMUCH_DATABASE_MODE_READ_ONLY;
131#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
133 const char *config_file = get_nm_config_file();
137 st = notmuch_database_open_with_config(filename, mode, config_file,
138 c_nm_config_profile, &db, &msg);
141 if ((st == NOTMUCH_STATUS_NO_CONFIG) && !
mutt_str_equal(config_file,
""))
148 st = notmuch_database_open_with_config(filename, mode,
"", NULL, &db, &msg);
150 else if ((st == NOTMUCH_STATUS_NO_CONFIG) && !config_file)
154#elif LIBNOTMUCH_CHECK_VERSION(4, 2, 0)
155 st = notmuch_database_open_verbose(filename, mode, &db, &msg);
156#elif defined(NOTMUCH_API_3)
157 st = notmuch_database_open(filename, mode, &db);
159 db = notmuch_database_open(filename, mode);
161 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
162 ((ct / 2) > c_nm_open_timeout))
167 if (
verbose && ct && ((ct % 2) == 0))
168 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
173 if (st != NOTMUCH_STATUS_SUCCESS)
188 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
189 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
242 adata->longrun =
false;
253 notmuch_database_destroy(
db);
255 notmuch_database_close(
db);
276 if (notmuch_database_begin_atomic(
adata->db))
298 adata->trans =
false;
299 if (notmuch_database_end_atomic(
adata->db))
320 struct stat st = { 0 };
328 snprintf(path,
sizeof(path),
"%s/xapian", db_filename);
329 if (stat(path, &st) == 0)
331 *mtime = st.st_mtime;
336 snprintf(path,
sizeof(path),
"%s/.notmuch/xapian", db_filename);
338 if (stat(path, &st) != 0)
341 *mtime = st.st_mtime;
356 return adata->longrun;
371 adata->longrun =
true;
385 adata->longrun =
false;
389 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? - Implements MxOps::path_probe() -.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
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 -.