aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch
diff options
context:
space:
mode:
authorJason Cox <me@jasoncarloscox.com>2024-01-25 08:23:08 -0500
committerRobin Jarry <robin@jarry.cc>2024-01-27 23:11:37 +0100
commitc48d27b07b90fab54198287c552646607f401228 (patch)
tree9c2ec59b12d871c9b47a5f3d8db07e740e01adb4 /worker/notmuch
parent1b67425c278cb9fd2d93e7d7cfed89baf3f05fa1 (diff)
downloadaerc-c48d27b07b90fab54198287c552646607f401228.tar.gz
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 <me@jasoncarloscox.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/notmuch')
-rw-r--r--worker/notmuch/lib/database.go18
-rw-r--r--worker/notmuch/worker.go21
2 files changed, 22 insertions, 17 deletions
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)
+}
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go
index 80a8d720..ddbdfc02 100644
--- a/worker/notmuch/worker.go
+++ b/worker/notmuch/worker.go
@@ -531,12 +531,7 @@ func (w *worker) handleFlagMessages(msg *types.FlagMessages) error {
}
func (w *worker) handleSearchDirectory(msg *types.SearchDirectory) error {
- s := translate(msg.Criteria)
- // we only want to search in the current query, so merge the two together
- search := w.query
- if s != "" {
- search = fmt.Sprintf("(%v) and (%v)", w.query, s)
- }
+ search := notmuch.AndQueries(w.query, translate(msg.Criteria))
log.Debugf("search query: '%s'", search)
uids, err := w.uidsFromQuery(msg.Context, search)
if err != nil {
@@ -599,11 +594,8 @@ func (w *worker) emitDirectoryContents(parent types.WorkerMessage) error {
query := w.query
ctx := context.Background()
if msg, ok := parent.(*types.FetchDirectoryContents); ok {
- s := translate(msg.Filter)
- if s != "" {
- query = fmt.Sprintf("(%v) and (%v)", query, s)
- log.Debugf("filter query: '%s'", query)
- }
+ query = notmuch.AndQueries(query, translate(msg.Filter))
+ log.Debugf("filter query: '%s'", query)
ctx = msg.Context
}
uids, err := w.uidsFromQuery(ctx, query)
@@ -627,11 +619,8 @@ func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error {
ctx := context.Background()
threadContext := false
if msg, ok := parent.(*types.FetchDirectoryThreaded); ok {
- s := translate(msg.Filter)
- if s != "" {
- query = fmt.Sprintf("(%v) and (%v)", query, s)
- log.Debugf("filter query: '%s'", query)
- }
+ query = notmuch.AndQueries(query, translate(msg.Filter))
+ log.Debugf("filter query: '%s'", query)
ctx = msg.Context
threadContext = msg.ThreadContext
}