From be0bfc1ae28b49be6546626ff9eaadce5464a6c8 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sun, 4 Jun 2023 14:05:22 +0200 Subject: worker: add jmap support Add support for JMAP backends. This is on par with IMAP features with some additions specific to JMAP: * tagging * sending emails This makes use of git.sr.ht/~rockorager/go-jmap for the low level interaction with the JMAP server. The transport is JSON over HTTPS. For now, only oauthbearer with token is supported. If this proves useful, we may need to file for an official three-legged oauth support at JMAP providers. I have tested most features and this seems to be reliable. There are some quirks with the use-labels option. Especially when moving and deleting messages from the "All mail" virtual folder (see aerc-jmap(5)). Overall, the user experience is nice and there are a lot less background updates issues than with IMAP (damn IDLE mode hanging after restoring from sleep). I know that not everyone has access to a JMAP provider. For those interested, there are at least these two commercial offerings: https://www.fastmail.com/ https://www.topicbox.com/ And, if you host your own mail, you can use a JMAP capable server: https://stalw.art/jmap/ https://www.cyrusimap.org/imap/download/installation/http/jmap.html Link: https://www.rfc-editor.org/rfc/rfc8620.html Link: https://www.rfc-editor.org/rfc/rfc8621.html Signed-off-by: Robin Jarry Tested-by: Tim Culverhouse --- worker/jmap/search.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 worker/jmap/search.go (limited to 'worker/jmap/search.go') diff --git a/worker/jmap/search.go b/worker/jmap/search.go new file mode 100644 index 00000000..a751b700 --- /dev/null +++ b/worker/jmap/search.go @@ -0,0 +1,63 @@ +package jmap + +import ( + "strings" + + "git.sr.ht/~rjarry/aerc/log" + "git.sr.ht/~rjarry/aerc/worker/lib" + "git.sr.ht/~rockorager/go-jmap/mail/email" + "git.sr.ht/~sircmpwn/getopt" +) + +func parseSearch(args []string) (*email.FilterCondition, error) { + f := new(email.FilterCondition) + if len(args) == 0 { + return f, nil + } + + opts, optind, err := getopt.Getopts(args, "rubax:X:t:H:f:c:d:") + if err != nil { + return nil, err + } + body := false + text := false + for _, opt := range opts { + switch opt.Option { + case 'r': + f.HasKeyword = "$seen" + case 'u': + f.NotKeyword = "$seen" + case 'f': + f.From = opt.Value + case 't': + f.To = opt.Value + case 'c': + f.Cc = opt.Value + case 'b': + 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() { + f.After = &start + } + if !end.IsZero() { + f.Before = &end + } + } + } + switch { + case text: + f.Text = strings.Join(args[optind:], " ") + case body: + f.Body = strings.Join(args[optind:], " ") + default: + f.Subject = strings.Join(args[optind:], " ") + } + return f, nil +} -- cgit