aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/search.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-08-28 06:39:07 +0200
committerDrew DeVault <sir@cmpwn.com>2019-08-29 08:44:10 +0900
commit94b9d557dee0fd13853b1883cc2730c5cbdbcd3f (patch)
tree8a0040b60df9ab4fa3d7f9d137d126a04fd5943b /worker/imap/search.go
parentac99d9ed62644cf0259bdd79481b28c3fbcef650 (diff)
downloadaerc-94b9d557dee0fd13853b1883cc2730c5cbdbcd3f.tar.gz
extract search criteria parsing into the backends
Diffstat (limited to 'worker/imap/search.go')
-rw-r--r--worker/imap/search.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/worker/imap/search.go b/worker/imap/search.go
new file mode 100644
index 00000000..4decf1b5
--- /dev/null
+++ b/worker/imap/search.go
@@ -0,0 +1,29 @@
+package imap
+
+import (
+ "git.sr.ht/~sircmpwn/getopt"
+ "github.com/emersion/go-imap"
+)
+
+func parseSearch(args []string) (*imap.SearchCriteria, error) {
+ criteria := imap.NewSearchCriteria()
+
+ opts, optind, err := getopt.Getopts(args, "ruH:")
+ if err != nil {
+ return nil, err
+ }
+ for _, opt := range opts {
+ switch opt.Option {
+ case 'r':
+ criteria.WithFlags = append(criteria.WithFlags, imap.SeenFlag)
+ case 'u':
+ criteria.WithoutFlags = append(criteria.WithoutFlags, imap.SeenFlag)
+ case 'H':
+ // TODO
+ }
+ }
+ for _, arg := range args[optind:] {
+ criteria.Header.Add("Subject", arg)
+ }
+ return criteria, nil
+}