From: Kirill A. Shutemov Date: Fri, 11 Oct 2013 18:34:57 +0000 (-0700) Subject: fix getting count of new messages for non-trivial query X-Git-Tag: neomutt-20160404~13^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a68e6e6dfc0572b91cf5932dbc8cb818dbd48468;p=neomutt fix getting count of new messages for non-trivial query Currtly, we ask for count of new messages by appending tag:unread (or whatever NotmuchUnreadTag has) to db query. It works if your query is very simple: no 'OR', 'NOT', etc. If you will ask new messages for query like "to:foo@example.com or to:bar@example.net" mutt will query db for count of "to:foo@example.com or to:bar@example.net tag:unread" and notmuch will understand it as "to:foo@example.com or (to:bar@example.net tag:unread)" which, obviously, is not what you wanted. Optimizations like if (strstr(db_query, NotmuchUnreadTag)) *new = all ? *all : count_query(db, db_query); doesn't work for the same reason. Let's fix all this by construct query with proper parenthesis: "(to:foo@example.com or to:bar@example.net) tag:unread" Signed-off-by: Kirill A. Shutemov --- diff --git a/mutt_notmuch.c b/mutt_notmuch.c index bca3f3967..40192d550 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1623,21 +1623,12 @@ int nm_nonctx_get_count(char *path, int *all, int *new) /* new messages */ if (new) { - if (strstr(db_query, NotmuchUnreadTag)) - *new = all ? *all : count_query(db, db_query); - else { - size_t qsz = strlen(db_query) - + sizeof(" and tag:") - + strlen(NotmuchUnreadTag); - char *qstr = safe_malloc(qsz); - - if (!qstr) - goto done; + char *qstr; - snprintf(qstr, qsz, "%s and tag:%s", db_query, NotmuchUnreadTag); - *new = count_query(db, qstr); - FREE(&qstr); - } + safe_asprintf(&qstr, "( %s ) tag:%s", + db_query, NotmuchUnreadTag); + *new = count_query(db, qstr); + FREE(&qstr); } rc = 0;