aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2022-08-11 16:49:35 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-22 09:30:37 +0200
commit132b5fed9ee2ada3c4a32adc1a7484b01c7b2b05 (patch)
tree2fb12876e291ed1c52d0ab3575fb92f88afe7d4d /worker
parent117f99e187e16086c1c43a03d640da3294e9e730 (diff)
downloadaerc-132b5fed9ee2ada3c4a32adc1a7484b01c7b2b05.tar.gz
mbox: filtering for mbox accounts
Use FetchDirectoryContents for filtering instead of the SearchDirectory message. This was an omission from rebasing the mbox worker and from not realizing that c2f4404f ("threading: enable filtering of server-side threads") changed the way we filter in the message store for the server-side threading implementation. This patch enables filtering for the mbox worker. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r--worker/mbox/worker.go74
1 files changed, 44 insertions, 30 deletions
diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go
index 78a9b1b6..71da8161 100644
--- a/worker/mbox/worker.go
+++ b/worker/mbox/worker.go
@@ -110,21 +110,12 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
logging.Infof("%s opened", msg.Directory)
case *types.FetchDirectoryContents:
- var infos []*models.MessageInfo
- for _, uid := range w.folder.Uids() {
- m, err := w.folder.Message(uid)
- if err != nil {
- logging.Errorf("could not get message %w", err)
- continue
- }
- info, err := lib.MessageInfo(m)
- if err != nil {
- logging.Errorf("could not get message info %w", err)
- continue
- }
- infos = append(infos, info)
+ uids, err := filterUids(w.folder, w.folder.Uids(), msg.FilterCriteria)
+ if err != nil {
+ reterr = err
+ break
}
- uids, err := lib.Sort(infos, msg.SortCriteria)
+ uids, err = sortUids(w.folder, uids, msg.SortCriteria)
if err != nil {
reterr = err
break
@@ -306,22 +297,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
&types.Done{Message: types.RespondTo(msg)}, nil)
case *types.SearchDirectory:
- criteria, err := lib.GetSearchCriteria(msg.Argv)
- if err != nil {
- reterr = err
- break
- }
- logging.Infof("Searching with parsed criteria: %#v", criteria)
- m := make([]lib.RawMessage, 0, len(w.folder.Uids()))
- for _, uid := range w.folder.Uids() {
- msg, err := w.folder.Message(uid)
- if err != nil {
- logging.Errorf("failed to get message for uid: %d", uid)
- continue
- }
- m = append(m, msg)
- }
- uids, err := lib.Search(m, criteria)
+ uids, err := filterUids(w.folder, w.folder.Uids(), msg.Argv)
if err != nil {
reterr = err
break
@@ -378,3 +354,41 @@ func (w *mboxWorker) Run() {
}
}
}
+
+func filterUids(folder *container, uids []uint32, args []string) ([]uint32, error) {
+ criteria, err := lib.GetSearchCriteria(args)
+ if err != nil {
+ return nil, err
+ }
+ logging.Infof("Search with parsed criteria: %#v", criteria)
+ m := make([]lib.RawMessage, 0, len(uids))
+ for _, uid := range uids {
+ msg, err := folder.Message(uid)
+ if err != nil {
+ logging.Errorf("failed to get message for uid: %d", uid)
+ continue
+ }
+ m = append(m, msg)
+ }
+ return lib.Search(m, criteria)
+}
+
+func sortUids(folder *container, uids []uint32,
+ criteria []*types.SortCriterion,
+) ([]uint32, error) {
+ var infos []*models.MessageInfo
+ for _, uid := range uids {
+ m, err := folder.Message(uid)
+ if err != nil {
+ logging.Errorf("could not get message %w", err)
+ continue
+ }
+ info, err := lib.MessageInfo(m)
+ if err != nil {
+ logging.Errorf("could not get message info %w", err)
+ continue
+ }
+ infos = append(infos, info)
+ }
+ return lib.Sort(infos, criteria)
+}