From: Florian Klink Date: Thu, 31 Aug 2017 02:21:26 +0000 (+0200) Subject: mutt_notmuch: fix setting custom query_type in notmuch query X-Git-Tag: neomutt-20170907~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f61124a1aa25a9d5bf1e0dbad2be2a4869776e6b;p=neomutt mutt_notmuch: fix setting custom query_type in notmuch query nm_normalize_uri re-builds notmuch queries, but nm_uri_from_query doesn't set query_type back again, so fix that. Also, use the NmQueryType enum where possible instead of int. Fixes #484. --- diff --git a/mutt_notmuch.c b/mutt_notmuch.c index daacfa33c..a72bd72d3 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -142,10 +142,10 @@ struct NmCtxData { notmuch_database_t *db; - char *db_filename; /**< Filename of the NotMuch database */ - char *db_query; /**< Previous query */ - int db_limit; /**< Maximum number of results to return */ - int query_type; /**< Messages or Threads */ + char *db_filename; /**< Filename of the NotMuch database */ + char *db_query; /**< Previous query */ + int db_limit; /**< Maximum number of results to return */ + enum NmQueryType query_type; /**< Messages or Threads */ struct UriTag *query_items; @@ -450,22 +450,25 @@ static struct NmCtxData *get_ctxdata(struct Context *ctx) return NULL; } -static int string_to_query_type(const char *str) +static enum NmQueryType string_to_query_type(const char *str) { - if (!str) - str = NmQueryType; /* user's default */ - if (!str) - return NM_QUERY_TYPE_MESGS; /* hardcoded default */ - - if (strcmp(str, "threads") == 0) + if (mutt_strcmp(str, "threads") == 0) return NM_QUERY_TYPE_THREADS; - else if (strcmp(str, "messages") == 0) + else if (mutt_strcmp(str, "messages") == 0) return NM_QUERY_TYPE_MESGS; mutt_error(_("failed to parse notmuch query type: %s"), str); return NM_QUERY_TYPE_MESGS; } +static char *query_type_to_string(enum NmQueryType query_type) +{ + if (query_type == NM_QUERY_TYPE_THREADS) + return "threads"; + else + return "messages"; +} + /** * query_window_check_timebase - Checks if a given timebase string is valid * @param[in] timebase: string containing a time base @@ -604,6 +607,8 @@ static char *get_query_string(struct NmCtxData *data, int window) if (data->db_query) return data->db_query; + data->query_type = string_to_query_type(NmQueryType); /* user's default */ + for (item = data->query_items; item; item = item->next) { if (!item->value || !item->name) @@ -624,9 +629,6 @@ static char *get_query_string(struct NmCtxData *data, int window) if (!data->db_query) return NULL; - if (!data->query_type) - data->query_type = string_to_query_type(NULL); - if (window) { char buf[LONG_STRING]; @@ -653,11 +655,6 @@ static int get_limit(struct NmCtxData *data) return data ? data->db_limit : 0; } -static int get_query_type(struct NmCtxData *data) -{ - return (data && data->query_type) ? data->query_type : string_to_query_type(NULL); -} - static const char *get_db_filename(struct NmCtxData *data) { char *db_filename = NULL; @@ -1844,11 +1841,15 @@ char *nm_uri_from_query(struct Context *ctx, char *buf, size_t bufsz) int added; if (data) - added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", get_db_filename(data)); + added = snprintf(uri, sizeof(uri), + "notmuch://%s?type=%s&query=", get_db_filename(data), + query_type_to_string(data->query_type)); else if (NmDefaultUri) - added = snprintf(uri, sizeof(uri), "%s?query=", NmDefaultUri); + added = snprintf(uri, sizeof(uri), "%s?type=%s&query=", NmDefaultUri, + query_type_to_string(data->query_type)); else if (Folder) - added = snprintf(uri, sizeof(uri), "notmuch://%s?query=", Folder); + added = snprintf(uri, sizeof(uri), "notmuch://%s?type=%s&query=", Folder, + query_type_to_string(data->query_type)); else return NULL; @@ -2012,7 +2013,7 @@ bool nm_message_is_still_queried(struct Context *ctx, struct Header *hdr) q = notmuch_query_create(db, new_str); - switch (get_query_type(data)) + switch (data->query_type) { case NM_QUERY_TYPE_MESGS: { @@ -2306,7 +2307,7 @@ static int nm_open_mailbox(struct Context *ctx) if (q) { rc = 0; - switch (get_query_type(data)) + switch (data->query_type) { case NM_QUERY_TYPE_MESGS: if (!read_mesgs_query(ctx, q, 0))