60 const char *db_filename = NULL;
64 db_filename =
mdata->db_url->path;
66 db_filename = c_nm_default_url;
69 if (!db_filename && !c_folder)
73 db_filename = c_folder;
82#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
88static const char *get_nm_config_file(
void)
90 const char *config_to_use = NULL;
94 if (!c_nm_config_file)
100 config_to_use = c_nm_config_file;
103 return config_to_use;
116 notmuch_database_t *db = NULL;
118 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
123 writable ?
"[WRITE]" :
"[READ]", c_nm_open_timeout);
125 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
126 NOTMUCH_DATABASE_MODE_READ_ONLY;
130#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
132 const char *config_file = get_nm_config_file();
136 st = notmuch_database_open_with_config(filename, mode, config_file,
137 c_nm_config_profile, &db, &msg);
140 if ((st == NOTMUCH_STATUS_NO_CONFIG) && !
mutt_str_equal(config_file,
""))
147 st = notmuch_database_open_with_config(filename, mode,
"", NULL, &db, &msg);
149 else if ((st == NOTMUCH_STATUS_NO_CONFIG) && !config_file)
153#elif LIBNOTMUCH_CHECK_VERSION(4, 2, 0)
154 st = notmuch_database_open_verbose(filename, mode, &db, &msg);
155#elif defined(NOTMUCH_API_3)
156 st = notmuch_database_open(filename, mode, &db);
158 db = notmuch_database_open(filename, mode);
160 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
161 ((ct / 2) > c_nm_open_timeout))
166 if (
verbose && ct && ((ct % 2) == 0))
167 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
172 if (st != NOTMUCH_STATUS_SUCCESS)
187 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
188 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
241 adata->longrun =
false;
252 notmuch_database_destroy(
db);
254 notmuch_database_close(
db);
275 if (notmuch_database_begin_atomic(
adata->db))
297 adata->trans =
false;
298 if (notmuch_database_end_atomic(
adata->db))
319 struct stat st = { 0 };
327 snprintf(path,
sizeof(path),
"%s/xapian", db_filename);
328 if (stat(path, &st) == 0)
330 *mtime = st.st_mtime;
335 snprintf(path,
sizeof(path),
"%s/.notmuch/xapian", db_filename);
337 if (stat(path, &st) != 0)
340 *mtime = st.st_mtime;
355 return adata->longrun;
370 adata->longrun =
true;
384 adata->longrun =
false;
388 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 -.