aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/directories.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-17 15:31:09 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:59 +0200
commit8464b373851142b0becaaa10db34df3559b2b62e (patch)
treedd785d6c717f1e620c63252348d8add991587a57 /worker/jmap/directories.go
parent57088312fdd8e602a084bd5736a0e22a34be9ec0 (diff)
downloadaerc-8464b373851142b0becaaa10db34df3559b2b62e.tar.gz
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 <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'worker/jmap/directories.go')
-rw-r--r--worker/jmap/directories.go39
1 files changed, 6 insertions, 33 deletions
diff --git a/worker/jmap/directories.go b/worker/jmap/directories.go
index 0fa3d898..bc47e691 100644
--- a/worker/jmap/directories.go
+++ b/worker/jmap/directories.go
@@ -126,25 +126,16 @@ func (w *JMAPWorker) handleFetchDirectoryContents(msg *types.FetchDirectoryConte
if err != nil {
contents = &cache.FolderContents{
MailboxID: w.selectedMbox,
- Filter: &email.FilterCondition{},
}
}
- filter, err := parseSearch(msg.FilterCriteria)
- if err != nil {
- return err
- }
- filter.InMailbox = w.selectedMbox
-
- sort := translateSort(msg.SortCriteria)
-
- if contents.NeedsRefresh(filter, sort) {
+ if contents.NeedsRefresh(msg.Filter, msg.SortCriteria) {
var req jmap.Request
req.Invoke(&email.Query{
Account: w.accountId,
- Filter: filter,
- Sort: sort,
+ Filter: w.translateSearch(w.selectedMbox, msg.Filter),
+ Sort: translateSort(msg.SortCriteria),
})
resp, err := w.Do(&req)
if err != nil {
@@ -154,8 +145,8 @@ func (w *JMAPWorker) handleFetchDirectoryContents(msg *types.FetchDirectoryConte
for _, inv := range resp.Responses {
switch r := inv.Args.(type) {
case *email.QueryResponse:
- contents.Sort = sort
- contents.Filter = filter
+ contents.Sort = msg.SortCriteria
+ contents.Filter = msg.Filter
contents.QueryState = r.QueryState
contents.MessageIDs = r.IDs
canCalculateChanges = r.CanCalculateChanges
@@ -193,27 +184,9 @@ func (w *JMAPWorker) handleFetchDirectoryContents(msg *types.FetchDirectoryConte
func (w *JMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) error {
var req jmap.Request
- filter, err := parseSearch(msg.Argv)
- if err != nil {
- return err
- }
- if w.selectedMbox == "" {
- // all mail virtual folder: display all but trash and spam
- var mboxes []jmap.ID
- if id, ok := w.roles[mailbox.RoleJunk]; ok {
- mboxes = append(mboxes, id)
- }
- if id, ok := w.roles[mailbox.RoleTrash]; ok {
- mboxes = append(mboxes, id)
- }
- filter.InMailboxOtherThan = mboxes
- } else {
- filter.InMailbox = w.selectedMbox
- }
-
req.Invoke(&email.Query{
Account: w.accountId,
- Filter: filter,
+ Filter: w.translateSearch(w.selectedMbox, msg.Criteria),
})
resp, err := w.Do(&req)