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 <kirill@shutemov.name>
/* 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;