From c48d27b07b90fab54198287c552646607f401228 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Thu, 25 Jan 2024 08:23:08 -0500 Subject: notmuch: correctly run queries in `*` folder A folder may be defined based on the notmuch query `*`, which matches all messages. This query is a special case (see notmuch-search-terms(7)) and cannot be combined with other queries. When adding to a `*` query, such as when searching, simply replace `*` with the more specific query rather than combining the two. Changelog-fixed: Notmuch folders defined by the query `*` handle search, filter, and unread counts correctly. Signed-off-by: Jason Cox Tested-by: Inwit Acked-by: Robin Jarry --- worker/notmuch/lib/database.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'worker/notmuch/lib') diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index f6e49ae1..be30cbc0 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -170,7 +170,7 @@ func (db *DB) QueryCountMessages(q string) (MessageCount, error) { return count, err } - unreadQuery, err := db.newQuery(fmt.Sprintf("(%v) and (tag:unread)", q)) + unreadQuery, err := db.newQuery(AndQueries(q, "tag:unread")) if err != nil { return count, err } @@ -352,3 +352,19 @@ func (db *DB) makeThread(parent *types.Thread, msgs *notmuch.Messages, threadCon } return siblings } + +func AndQueries(q1, q2 string) string { + if q1 == "" { + return q2 + } + if q2 == "" { + return q1 + } + if q1 == "*" { + return q2 + } + if q2 == "*" { + return q1 + } + return fmt.Sprintf("(%s) and (%s)", q1, q2) +} -- cgit