about summary refs log tree commit diff stats
path: root/worker
diff options
context:
space:
mode:
authorJeffas <dev@jeffas.io>2019-09-09 21:37:45 +0100
committerDrew DeVault <sir@cmpwn.com>2019-09-11 12:24:27 -0400
commit32381592fc335bc26a06cee847df926b9f6e6c06 (patch)
treea3dd53ab5ff30986ca76601c2f64fb33dfe57986 /worker
parent282dc44aa67773b608cace43587ecd2c140689a4 (diff)
downloadaerc-32381592fc335bc26a06cee847df926b9f6e6c06.tar.gz
Add new search behaviour for imap
This patch adds search behaviour to allow searching in the body of the
messages, the entire text (body + header), and searching just the from
header.
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/search.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/worker/imap/search.go b/worker/imap/search.go
index 4decf1b..939516d 100644
--- a/worker/imap/search.go
+++ b/worker/imap/search.go
@@ -1,17 +1,20 @@
 package imap
 
 import (
-	"git.sr.ht/~sircmpwn/getopt"
 	"github.com/emersion/go-imap"
+
+	"git.sr.ht/~sircmpwn/getopt"
 )
 
 func parseSearch(args []string) (*imap.SearchCriteria, error) {
 	criteria := imap.NewSearchCriteria()
 
-	opts, optind, err := getopt.Getopts(args, "ruH:")
+	opts, optind, err := getopt.Getopts(args, "rubtH:f:")
 	if err != nil {
 		return nil, err
 	}
+	body := false
+	text := false
 	for _, opt := range opts {
 		switch opt.Option {
 		case 'r':
@@ -20,10 +23,22 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) {
 			criteria.WithoutFlags = append(criteria.WithoutFlags, imap.SeenFlag)
 		case 'H':
 			// TODO
+		case 'f':
+			criteria.Header.Add("From", opt.Value)
+		case 'b':
+			body = true
+		case 't':
+			text = true
 		}
 	}
-	for _, arg := range args[optind:] {
-		criteria.Header.Add("Subject", arg)
+	if text {
+		criteria.Text = args[optind:]
+	} else if body {
+		criteria.Body = args[optind:]
+	} else {
+		for _, arg := range args[optind:] {
+			criteria.Header.Add("Subject", arg)
+		}
 	}
 	return criteria, nil
 }