Open a Notmuch database.
112{
113 notmuch_database_t *db = NULL;
114 int ct = 0;
115 notmuch_status_t st = NOTMUCH_STATUS_SUCCESS;
116 char *msg = NULL;
117
120 writable ? "[WRITE]" : "[READ]", c_nm_open_timeout);
121
122 const notmuch_database_mode_t mode = writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
123 NOTMUCH_DATABASE_MODE_READ_ONLY;
124
125 do
126 {
127#if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
128
129 const char *config_file = get_nm_config_file();
131
132 st = notmuch_database_open_with_config(filename, mode, config_file,
133 c_nm_config_profile, &db, &msg);
134
135
136 if (st == NOTMUCH_STATUS_NO_CONFIG && !
mutt_str_equal(config_file,
""))
137 {
140
142
143 st = notmuch_database_open_with_config(filename, mode, "", NULL, &db, &msg);
144 }
145#elif LIBNOTMUCH_CHECK_VERSION(4, 2, 0)
146 st = notmuch_database_open_verbose(filename, mode, &db, &msg);
147#elif defined(NOTMUCH_API_3)
148 st = notmuch_database_open(filename, mode, &db);
149#else
150 db = notmuch_database_open(filename, mode);
151#endif
152 if ((st == NOTMUCH_STATUS_FILE_ERROR) || db || !c_nm_open_timeout ||
153 ((ct / 2) > c_nm_open_timeout))
154 {
155 break;
156 }
157
158 if (verbose && ct && ((ct % 2) == 0))
159 mutt_error(
_(
"Waiting for notmuch DB... (%d sec)"), ct / 2);
161 ct++;
162 } while (true);
163
164 if (st != NOTMUCH_STATUS_SUCCESS)
165 {
166 db = NULL;
167 }
168
169 if (verbose)
170 {
171 if (!db)
172 {
173 if (msg)
174 {
176 }
177 else
178 {
179 mutt_error(
_(
"Can't open notmuch database: %s: %s"), filename,
180 st ? notmuch_status_to_string(st) :
_(
"unknown reason"));
181 }
182 }
183 else if (ct > 1)
184 {
186 }
187 }
188
190
191 return db;
192}
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)