From 8464b373851142b0becaaa10db34df3559b2b62e Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 17 Oct 2023 15:31:09 +0200 Subject: search: use a common api for all workers Define a SearchCriteria structure. Update the FetchDirectoryContents, FetchDirectoryThreaded and SearchDirectory worker messages to include this SearchCriteria structure instead of a []string slice. Parse the search arguments in a single place into a SearchCriteria structure and use it to search/filter via the message store. Update all workers to use that new API. Clarify the man page indicating that notmuch supports searching with aerc's syntax and also with notmuch specific syntax. getopt is no longer needed, remove it from go.mod. NB: to support more complex search filters in JMAP, we need to use an email.Filter interface. Since GOB does not support encoding/decoding interfaces, store the raw SearchCriteria and []SortCriterion values in the cached FolderContents. Translate them to JMAP API objects when sending an email.Query request to the server. Signed-off-by: Robin Jarry Reviewed-by: Koni Marti Tested-by: Moritz Poldrack Tested-by: Inwit --- worker/jmap/cache/cache.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'worker/jmap/cache/cache.go') diff --git a/worker/jmap/cache/cache.go b/worker/jmap/cache/cache.go index 249ed0e9..6d815177 100644 --- a/worker/jmap/cache/cache.go +++ b/worker/jmap/cache/cache.go @@ -4,10 +4,12 @@ import ( "errors" "os" "path" + "strings" "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" "github.com/syndtr/goleveldb/leveldb" + "github.com/syndtr/goleveldb/leveldb/util" ) type JMAPCache struct { @@ -74,3 +76,34 @@ func (c *JMAPCache) delete(key string) error { } panic("jmap cache with no backend") } + +func (c *JMAPCache) purge(prefix string) error { + switch { + case c.file != nil: + txn, err := c.file.OpenTransaction() + if err != nil { + return err + } + iter := txn.NewIterator(util.BytesPrefix([]byte(prefix)), nil) + for iter.Next() { + err = txn.Delete(iter.Key(), nil) + if err != nil { + break + } + } + iter.Release() + if err != nil { + txn.Discard() + return err + } + return txn.Commit() + case c.mem != nil: + for key := range c.mem { + if strings.HasPrefix(key, prefix) { + delete(c.mem, key) + } + } + return nil + } + panic("jmap cache with no backend") +} -- cgit