about summary refs log tree commit diff stats
path: root/worker/imap/list.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/list.go
parentac99d9ed62644cf0259bdd79481b28c3fbcef650 (diff)
downloadaerc-94b9d557dee0fd13853b1883cc2730c5cbdbcd3f.tar.gz
extract search criteria parsing into the backends
Diffstat (limited to 'worker/imap/list.go')
-rw-r--r--worker/imap/list.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/worker/imap/list.go b/worker/imap/list.go
index 42be50e..e69fc07 100644
--- a/worker/imap/list.go
+++ b/worker/imap/list.go
@@ -52,17 +52,29 @@ func canOpen(mbox *imap.MailboxInfo) bool {
 }
 
 func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) {
-	imapw.worker.Logger.Println("Executing search")
-
-	if uids, err := imapw.client.UidSearch(msg.Criteria); err != nil {
+	emitError := func(err error) {
 		imapw.worker.PostMessage(&types.Error{
 			Message: types.RespondTo(msg),
 			Error:   err,
 		}, nil)
-	} else {
-		imapw.worker.PostMessage(&types.SearchResults{
-			Message: types.RespondTo(msg),
-			Uids:    uids,
-		}, nil)
 	}
+
+	imapw.worker.Logger.Println("Executing search")
+	criteria, err := parseSearch(msg.Argv)
+	if err != nil {
+		emitError(err)
+		return
+	}
+
+	uids, err := imapw.client.UidSearch(criteria)
+	if err != nil {
+		emitError(err)
+		return
+	}
+
+	imapw.worker.PostMessage(&types.SearchResults{
+		Message: types.RespondTo(msg),
+		Uids:    uids,
+	}, nil)
+
 }