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/mbox/worker.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'worker/mbox/worker.go') diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go index 160dfa55..5de3e30d 100644 --- a/worker/mbox/worker.go +++ b/worker/mbox/worker.go @@ -119,7 +119,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { w.worker.Debugf("%s opened", msg.Directory) case *types.FetchDirectoryContents: - uids, err := filterUids(w.folder, w.folder.Uids(), msg.FilterCriteria) + uids, err := filterUids(w.folder, w.folder.Uids(), msg.Filter) if err != nil { reterr = err break @@ -339,7 +339,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { &types.Done{Message: types.RespondTo(msg)}, nil) case *types.SearchDirectory: - uids, err := filterUids(w.folder, w.folder.Uids(), msg.Argv) + uids, err := filterUids(w.folder, w.folder.Uids(), msg.Criteria) if err != nil { reterr = err break @@ -405,11 +405,7 @@ func (w *mboxWorker) PathSeparator() string { return "/" } -func filterUids(folder *container, uids []uint32, args []string) ([]uint32, error) { - criteria, err := lib.GetSearchCriteria(args) - if err != nil { - return nil, err - } +func filterUids(folder *container, uids []uint32, criteria *types.SearchCriteria) ([]uint32, error) { log.Debugf("Search with parsed criteria: %#v", criteria) m := make([]rfc822.RawMessage, 0, len(uids)) for _, uid := range uids { -- cgit