From ce7fbd27ee8f41adfa8e33002ccf965c6a917e5a Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 15 Nov 2022 21:24:51 +0100 Subject: imap: filter and search with a date range Filter and search with a date range in the imap backend. Signed-off-by: Koni Marti Acked-by: Robin Jarry --- worker/imap/search.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'worker/imap/search.go') diff --git a/worker/imap/search.go b/worker/imap/search.go index adbc6b90..ba7b9174 100644 --- a/worker/imap/search.go +++ b/worker/imap/search.go @@ -6,6 +6,8 @@ import ( "github.com/emersion/go-imap" + "git.sr.ht/~rjarry/aerc/log" + "git.sr.ht/~rjarry/aerc/worker/lib" "git.sr.ht/~sircmpwn/getopt" ) @@ -15,7 +17,7 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) { return criteria, nil } - opts, optind, err := getopt.Getopts(args, "rubax:X:t:H:f:c:") + opts, optind, err := getopt.Getopts(args, "rubax:X:t:H:f:c:d:") if err != nil { return nil, err } @@ -47,6 +49,18 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) { body = true case 'a': text = true + case 'd': + start, end, err := lib.ParseDateRange(opt.Value) + if err != nil { + log.Errorf("failed to parse start date: %v", err) + continue + } + if !start.IsZero() { + criteria.SentSince = start + } + if !end.IsZero() { + criteria.SentBefore = end + } } } switch { -- cgit