Open a Notmuch database.
115{
116 notmuch_database_t *db = NULL;
117 int ct = 0;
118 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
119 char *msg = NULL;
120
123 writable ? "[WRITE]" : "[READ]", c_nm_open_timeout);
124
125 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
126 NOTMUCH_DATABASE_MODE_READ_ONLY;
127
128 do
129 {
130#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
131
132 const char *config_file = get_nm_config_file();
134
136 st = notmuch_database_open_with_config(filename, mode, config_file,
137 c_nm_config_profile, &db, &msg);
138
139
140 if ((st == NOTMUCH_STATUS_NO_CONFIG) && !
mutt_str_equal(config_file,
""))
141 {
144
146
147 st = notmuch_database_open_with_config(filename, mode, "", NULL, &db, &msg);
148 }
149 else if ((st == NOTMUCH_STATUS_NO_CONFIG) && !config_file)
150 {
152 }
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);
157#else
158 db = notmuch_database_open(filename, mode);
159#endif
160 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
161 ((ct / 2) > c_nm_open_timeout))
162 {
163 break;
164 }
165
166 if (verbose && ct && ((ct % 2) == 0))
167 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
169 ct++;
170 } while (true);
171
172 if (st != NOTMUCH_STATUS_SUCCESS)
173 {
174 db = NULL;
175 }
176
177 if (verbose)
178 {
179 if (!db)
180 {
181 if (msg)
182 {
184 }
185 else
186 {
187 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
188 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
189 }
190 }
191 else if (ct > 1)
192 {
194 }
195 }
196
198
199 return db;
200}
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.
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.