mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-07-15 15:43:50 +02:00

This patch fixes a copy/paste error in translateSearch that was leading
to the types.SearchCriteria's StartDate to be mapped to both SentSince
and SentBefore in the imap.SearchCriteria, and the actual EndDate to be
ignored.
Fixes: 8464b37385
("search: use a common api for all workers")
Signed-off-by: Simon Martin <simon@nasilyan.com>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
52 lines
1 KiB
Go
52 lines
1 KiB
Go
package imap
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/emersion/go-imap"
|
|
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
|
"git.sr.ht/~rjarry/go-opt/v2"
|
|
)
|
|
|
|
func translateSearch(c *types.SearchCriteria) *imap.SearchCriteria {
|
|
criteria := imap.NewSearchCriteria()
|
|
if c == nil {
|
|
return criteria
|
|
}
|
|
criteria.WithFlags = translateFlags(c.WithFlags)
|
|
criteria.WithoutFlags = translateFlags(c.WithoutFlags)
|
|
|
|
if !c.StartDate.IsZero() {
|
|
criteria.SentSince = c.StartDate
|
|
}
|
|
if !c.EndDate.IsZero() {
|
|
criteria.SentBefore = c.EndDate
|
|
}
|
|
for k, v := range c.Headers {
|
|
criteria.Header[k] = v
|
|
}
|
|
for _, f := range c.From {
|
|
criteria.Header.Add("From", f)
|
|
}
|
|
for _, t := range c.To {
|
|
criteria.Header.Add("To", t)
|
|
}
|
|
for _, c := range c.Cc {
|
|
criteria.Header.Add("Cc", c)
|
|
}
|
|
terms := opt.LexArgs(strings.Join(c.Terms, " "))
|
|
if terms.Count() > 0 {
|
|
switch {
|
|
case c.SearchAll:
|
|
criteria.Text = terms.Args()
|
|
case c.SearchBody:
|
|
criteria.Body = terms.Args()
|
|
default:
|
|
for _, term := range terms.Args() {
|
|
criteria.Header.Add("Subject", term)
|
|
}
|
|
}
|
|
}
|
|
return criteria
|
|
}
|