*/
#endif
#ifdef USE_NOTMUCH
- { "notmuch_default_uri", DT_STR, R_NONE, UL &NotmuchDefaultUri, 0 },
+ { "nm_default_uri", DT_STR, R_NONE, UL &NotmuchDefaultUri, 0 },
/*
** .pp
** This variable specifies the default Notmuch database in format
** notmuch://<absolute path>.
*/
- { "notmuch_hidden_tags", DT_STR, R_NONE, UL &NotmuchHiddenTags, UL "unread,draft,flagged,passed,replied,attachment" },
+ { "nm_hidden_tags", DT_STR, R_NONE, UL &NotmuchHiddenTags, UL "unread,draft,flagged,passed,replied,attachment" },
/*
** .pp
** This variable specifies private notmuch tags which should not be printed
** on screen.
*/
- { "notmuch_unread_tag", DT_STR, R_NONE, UL &NotmuchUnreadTag, UL "tag:unread" },
+ { "nm_unread_tag", DT_STR, R_NONE, UL &NotmuchUnreadTag, UL "tag:unread" },
/*
** .pp
** This variable specifies notmuch tag which is used for unread messages. The
e = strchr(p, '?');
- *filename = e ? strndup(p, e - p) : safe_strdup(p);
- if (!*filename)
- return -1;
-
+ *filename = e ? e == p ? NULL : strndup(p, e - p) : safe_strdup(p);
if (!e)
return 0;
- if (url_pct_decode(*filename) < 0)
+ if (*filename && url_pct_decode(*filename) < 0)
goto err;
if (!e)
return 0; /* only filename */
return data->db_limit;
}
+static const char *get_db_filename(CONTEXT *ctx)
+{
+ struct nm_data *data = get_data(ctx);
+
+ if (data) {
+ char *db_filename = data->db_filename ? data->db_filename : NotmuchDefaultUri;
+
+ if (!db_filename)
+ return NULL;
+ if (strncmp(db_filename, "notmuch://", 10) == 0)
+ db_filename += 10;
+
+ return db_filename;
+ }
+ return NULL;
+}
+
static notmuch_database_t *get_db(CONTEXT *ctx, int writable)
{
struct nm_data *data = get_data(ctx);
if (!data)
return NULL;
if (!data->db) {
- data->db = notmuch_database_open(data->db_filename,
+ const char *db_filename = get_db_filename(ctx);
+
+ if (!db_filename)
+ return NULL;
+
+ data->db = notmuch_database_open(db_filename,
writable ? NOTMUCH_DATABASE_MODE_READ_WRITE :
NOTMUCH_DATABASE_MODE_READ_ONLY);
if (!data->db)
mutt_error (_("Cannot open notmuch database: %s"),
- data->db_filename);
+ db_filename);
}
return data->db;
if (!data)
return -1;
- snprintf(path, sizeof(path), "%s/.notmuch/xapian", data->db_filename);
+ snprintf(path, sizeof(path), "%s/.notmuch/xapian", get_db_filename(ctx));
if (stat(path, &st))
return -1;
char uri[_POSIX_PATH_MAX];
if (ctx && ctx->magic == M_NOTMUCH && (data = get_data(ctx)))
- snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", data->db_filename, buf);
+ snprintf(uri, sizeof(uri), "notmuch://%s?query=%s", get_db_filename(ctx), buf);
else if (NotmuchDefaultUri)
snprintf(uri, sizeof(uri), "%s?query=%s", NotmuchDefaultUri, buf);
else
if (h->deleted || strcmp(old, new) != 0) {
/* email renamed or deleted -- update DB */
- if (!db)
+ if (!db) {
db = get_db(ctx, TRUE);
-
+ if (!db)
+ break;
+ }
if (h->deleted) {
notmuch_database_remove_message(db, old);
changed = 1;
struct uri_tag *query_items = NULL, *item;
char *db_filename = NULL, *db_query = NULL;
notmuch_database_t *db = NULL;
-
- int rc = -1;
+ int rc = -1, dflt = 0;
if (url_parse_query(path, &db_filename, &query_items)) {
mutt_error(_("failed to parse notmuch uri: %s"), path);
goto done;
}
- if (!db_filename || !query_items)
+ if (!query_items)
goto done;
for (item = query_items; item; item = item->next) {
if (!db_query)
goto done;
+ if (!db_filename && NotmuchDefaultUri) {
+ if (strncmp(NotmuchDefaultUri, "notmuch://", 10) == 0)
+ db_filename = NotmuchDefaultUri + 10;
+ else
+ db_filename = NotmuchDefaultUri;
+ dflt = 1;
+ }
db = notmuch_database_open(db_filename, NOTMUCH_DATABASE_MODE_READ_ONLY);
if (!db) {
done:
if (db)
notmuch_database_close(db);
- FREE(&db_filename);
+ if (!dflt)
+ FREE(&db_filename);
url_free_tags(query_items);
return rc;
}