~sircmpwn/aerc

Mailing list for aerc development.

1

[PATCH] Add new search behaviour for imap

Details
Message ID
<20190909203745.31945-1-dev@jeffas.io>
DKIM signature
missing
Download raw message
Patch: +27 -6
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.
---
 doc/aerc-search.1.scd | 10 ++++++++--
 worker/imap/search.go | 23 +++++++++++++++++++----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/doc/aerc-search.1.scd b/doc/aerc-search.1.scd
index c86ed6a..def9d3d 100644
--- a/doc/aerc-search.1.scd
+++ b/doc/aerc-search.1.scd
@@ -2,14 +2,20 @@ aerc-search(1)

 # IMAP

-*search* [-ru] <terms...>
+*search* [-rubt] [-f <from>] <terms...>
 	Searches the current folder for <terms>. Each separate term is searched
-	case-insensitively among subject lines.
+	case-insensitively among subject lines if *-b* or *-t* are not provided.

 	*-r*: Search for read messages

 	*-u*: Search for unread messages

+	*-b*: Search in the body of the messages
+
+	*-t*: Search in the entire text of the messages
+
+	*-f <from>*: Search for messages from <from>
+
 # NOTMUCH

 *search* <query...>
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
 }
--
2.23.0
Details
Message ID
<BWXBA3OYRDFU.3MSDW7EUC2GC3@homura>
In-Reply-To
<20190909203745.31945-1-dev@jeffas.io> (view parent)
DKIM signature
pass
Download raw message
Thanks!

To git.sr.ht:~sircmpwn/aerc
   282dc44..572d9ff  master -> master