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>
This commit is contained in:
parent
117f99e187
commit
132b5fed9e
1 changed files with 44 additions and 30 deletions
|
@ -110,21 +110,12 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
logging.Infof("%s opened", msg.Directory)
|
logging.Infof("%s opened", msg.Directory)
|
||||||
|
|
||||||
case *types.FetchDirectoryContents:
|
case *types.FetchDirectoryContents:
|
||||||
var infos []*models.MessageInfo
|
uids, err := filterUids(w.folder, w.folder.Uids(), msg.FilterCriteria)
|
||||||
for _, uid := range w.folder.Uids() {
|
if err != nil {
|
||||||
m, err := w.folder.Message(uid)
|
reterr = err
|
||||||
if err != nil {
|
break
|
||||||
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 := lib.Sort(infos, msg.SortCriteria)
|
uids, err = sortUids(w.folder, uids, msg.SortCriteria)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reterr = err
|
reterr = err
|
||||||
break
|
break
|
||||||
|
@ -306,22 +297,7 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error {
|
||||||
&types.Done{Message: types.RespondTo(msg)}, nil)
|
&types.Done{Message: types.RespondTo(msg)}, nil)
|
||||||
|
|
||||||
case *types.SearchDirectory:
|
case *types.SearchDirectory:
|
||||||
criteria, err := lib.GetSearchCriteria(msg.Argv)
|
uids, err := filterUids(w.folder, w.folder.Uids(), 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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
reterr = err
|
reterr = err
|
||||||
break
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue