aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-07 16:33:37 +0100
committerRobin Jarry <robin@jarry.cc>2023-11-12 12:53:11 +0100
commit063187340ce257a633cc5e6b503112db306be2e6 (patch)
tree5a444320a2fe2280ab287c0a937fd351d53b4722 /worker
parent23ba54784a49fe13c665396c49a5ab3baa70ebd5 (diff)
downloadaerc-063187340ce257a633cc5e6b503112db306be2e6.tar.gz
search: add rcpts fields to header in search criteria
Add recipients fields (from, to, cc) to the header for filtering and searching for the maildir and mbox backends. Fixes: commit 8464b373 ("search: use a common api for all workers") Reported-by: Vitaly Ovchinnikov <v@ovch.ru> Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Vitaly Ovchinnikov <v@ovch.ru>
Diffstat (limited to 'worker')
-rw-r--r--worker/lib/search.go1
-rw-r--r--worker/maildir/search.go2
-rw-r--r--worker/types/search.go18
3 files changed, 20 insertions, 1 deletions
diff --git a/worker/lib/search.go b/worker/lib/search.go
index a3604430..c85b3307 100644
--- a/worker/lib/search.go
+++ b/worker/lib/search.go
@@ -14,6 +14,7 @@ import (
)
func Search(messages []rfc822.RawMessage, criteria *types.SearchCriteria) ([]uint32, error) {
+ criteria.PrepareHeader()
requiredParts := GetRequiredParts(criteria)
matchedUids := []uint32{}
diff --git a/worker/maildir/search.go b/worker/maildir/search.go
index cf954753..8a19d66d 100644
--- a/worker/maildir/search.go
+++ b/worker/maildir/search.go
@@ -11,8 +11,8 @@ import (
)
func (w *Worker) search(ctx context.Context, criteria *types.SearchCriteria) ([]uint32, error) {
+ criteria.PrepareHeader()
requiredParts := lib.GetRequiredParts(criteria)
-
w.worker.Debugf("Required parts bitmask for search: %b", requiredParts)
keys, err := w.c.UIDs(*w.selected)
diff --git a/worker/types/search.go b/worker/types/search.go
index b1960cad..93a0053d 100644
--- a/worker/types/search.go
+++ b/worker/types/search.go
@@ -22,6 +22,24 @@ type SearchCriteria struct {
Terms string
}
+func (c *SearchCriteria) PrepareHeader() {
+ if c == nil {
+ return
+ }
+ if c.Headers == nil {
+ c.Headers = make(textproto.MIMEHeader)
+ }
+ for _, from := range c.From {
+ c.Headers.Add("From", from)
+ }
+ for _, to := range c.To {
+ c.Headers.Add("To", to)
+ }
+ for _, cc := range c.Cc {
+ c.Headers.Add("Cc", cc)
+ }
+}
+
func (c *SearchCriteria) Combine(other *SearchCriteria) *SearchCriteria {
if c == nil {
return other