Open a Notmuch database.
117{
118 notmuch_database_t *db = NULL;
119 int ct = 0;
120 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
121 char *msg = NULL;
122
124 mutt_debug(
LL_DEBUG1,
"nm: db open '%s' %s (timeout %d)\n", filename ? filename :
"(auto)",
125 writable ? "[WRITE]" : "[READ]", c_nm_open_timeout);
126
127 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
128 NOTMUCH_DATABASE_MODE_READ_ONLY;
129
130 do
131 {
132#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
133
134 const char *config_file = get_nm_config_file();
136
138 st = notmuch_database_open_with_config(filename, mode, config_file,
139 c_nm_config_profile, &db, &msg);
140
141
142 if ((st == NOTMUCH_STATUS_NO_CONFIG) && !
mutt_str_equal(config_file,
""))
143 {
146
148
149 st = notmuch_database_open_with_config(filename, mode, "", NULL, &db, &msg);
150 }
151 else if ((st == NOTMUCH_STATUS_NO_CONFIG) && !config_file)
152 {
154 }
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);
159#else
160 db = notmuch_database_open(filename, mode);
161#endif
162 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
163 ((ct / 2) > c_nm_open_timeout))
164 {
165 break;
166 }
167
168 if (verbose && ct && ((ct % 2) == 0))
169 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
171 ct++;
172 } while (true);
173
174 if (st != NOTMUCH_STATUS_SUCCESS)
175 {
176 db = NULL;
177 }
178
179 if (verbose)
180 {
181 if (!db)
182 {
183 if (msg)
184 {
186 }
187 else
188 {
189 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
190 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
191 }
192 }
193 else if (ct > 1)
194 {
196 }
197 }
198
200
201 return db;
202}
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.
#define mutt_debug(LEVEL,...)
@ 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.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.