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