From: Austin Ray Date: Tue, 30 Oct 2018 16:06:33 +0000 (-0400) Subject: notmuch: respect limits when counting messages X-Git-Tag: 2019-10-25~579 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a466efcc78b98cd4f620239cbe15977f9d7eca8c;p=neomutt notmuch: respect limits when counting messages When NeoMutt counts the number of returned messages for a notmuch query, it does not consider user specified limits. This affects both `limit=` and `nm_db_limit` specifications. This commit modifies `nm_nonctx_get_count(...)` to return the query's limit if `get_count(...)` exceeds the limit. The check ensures that the limit is non-zero so we don't return empty mailboxes. Fixes #1375 --- diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index c7797b7c6..91457b89a 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1906,6 +1906,7 @@ int nm_nonctx_get_count(char *path, int *all, int *new) char *db_filename = NULL, *db_query = NULL; notmuch_database_t *db = NULL; int rc = -1; + int limit = NmDbLimit; mutt_debug(1, "nm: count\n"); if (url_parse(&url, url_holder) < 0) @@ -1917,10 +1918,9 @@ int nm_nonctx_get_count(char *path, int *all, int *new) STAILQ_FOREACH(item, &url.query_strings, entries) { if (item->value && (strcmp(item->name, "query") == 0)) - { db_query = item->value; - break; - } + else if (item->value && (strcmp(item->name, "limit") == 0)) + mutt_str_atoi(item->value, &limit); // Try to parse the limit } if (!db_query) @@ -1948,8 +1948,14 @@ int nm_nonctx_get_count(char *path, int *all, int *new) /* all emails */ if (all) + { *all = count_query(db, db_query); + // If we have a non-zero limit, we shouldn't exceed it. + if (limit > 0 && *all > limit) + *all = limit; + } + /* new messages */ if (new) {