diff options
author | Koni Marti <koni.marti@gmail.com> | 2024-07-04 22:41:36 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-08-04 18:26:47 +0200 |
commit | 2cd0cec19d6146d6e9681b648d978f463b107008 (patch) | |
tree | f1863cb7783e2895ea9bd494e6bc1f55db1e220b /commands | |
parent | f913070600236e9298eb5703794665562a348987 (diff) | |
download | aerc-2cd0cec19d6146d6e9681b648d978f463b107008.tar.gz |
search,filter: add flag to use custom extensions
Add an extension flag to the search/filter command which will provide
different completion strategies for the search terms and instruct the
backend to use custom extensions (such as X-GM-EXT-1) if available.
The following examples are based on the Gmail extension (note that this
should be enabled in your accounts.conf with 'use-gmail-ext=true'):
:filter -e filename:pdf from:bob
:filter -e has:attachment newer_than:2d
:search -e is:read is:starred
:search -e list:~rjarry/aerc-devel@lists.sr.ht
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/account/search.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/commands/account/search.go b/commands/account/search.go index 59b2fadb..d9dfc684 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -14,6 +14,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/state" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/models" + "git.sr.ht/~rjarry/aerc/worker/imap/extensions/xgmext" "git.sr.ht/~rjarry/aerc/worker/types" ) @@ -22,6 +23,7 @@ type SearchFilter struct { Unread bool `opt:"-u" action:"ParseUnread"` Body bool `opt:"-b"` All bool `opt:"-a"` + UseExtension bool `opt:"-e"` Headers textproto.MIMEHeader `opt:"-H" action:"ParseHeader" metavar:"<header>:<value>"` WithFlags models.Flags `opt:"-x" action:"ParseFlag" complete:"CompleteFlag"` WithoutFlags models.Flags `opt:"-X" action:"ParseNotFlag" complete:"CompleteFlag"` @@ -30,7 +32,7 @@ type SearchFilter struct { Cc []string `opt:"-c" action:"ParseCc" complete:"CompleteAddress"` StartDate time.Time `opt:"-d" action:"ParseDate" complete:"CompleteDate"` EndDate time.Time - Terms string `opt:"..." required:"false" complete:"CompleteNotmuch"` + Terms string `opt:"..." required:"false" complete:"CompleteTerms"` } func init() { @@ -57,15 +59,19 @@ func (*SearchFilter) CompleteDate(arg string) []string { return commands.FilterList(commands.GetDateList(), arg, commands.QuoteSpace) } -func (*SearchFilter) CompleteNotmuch(arg string) []string { +func (s *SearchFilter) CompleteTerms(arg string) []string { acct := app.SelectedAccount() if acct == nil { return nil } - if acct.AccountConfig().Backend != "notmuch" { - return nil + if acct.AccountConfig().Backend == "notmuch" { + return handleNotmuchComplete(arg) + } + caps := acct.Worker().Backend.Capabilities() + if caps != nil && caps.Has("X-GM-EXT-1") && s.UseExtension { + return handleXGMEXTComplete(arg) } - return handleNotmuchComplete(arg) + return nil } func (s *SearchFilter) ParseRead(arg string) error { @@ -166,6 +172,7 @@ func (s SearchFilter) Execute(args []string) error { SearchBody: s.Body, SearchAll: s.All, Terms: []string{s.Terms}, + UseExtension: s.UseExtension, } if args[0] == "filter" { @@ -194,3 +201,18 @@ func (s SearchFilter) Execute(args []string) error { } return nil } + +func handleXGMEXTComplete(arg string) []string { + prefixes := []string{"from:", "to:", "deliveredto:", "cc:", "bcc:"} + for _, prefix := range prefixes { + if strings.HasPrefix(arg, prefix) { + arg = strings.TrimPrefix(arg, prefix) + return commands.FilterList( + commands.GetAddress(arg), arg, + func(v string) string { return prefix + v }, + ) + } + } + + return commands.FilterList(xgmext.Terms, arg, nil) +} |