From 96d5b4e149dccfdb75d41785e6525b647925f8ce Mon Sep 17 00:00:00 2001 From: Julian Marcos Date: Mon, 17 Apr 2023 06:22:11 +0200 Subject: search: handle headers in search/filter query Handle headers in the search and filter commands, for searching and filtering based on the Headers specified by the -H parameter, the syntax for the -H parameter should be `Header: Key`. Signed-off-by: Julian Marcos Acked-by: Robin Jarry --- CHANGELOG.md | 1 + doc/aerc-search.1.scd | 7 ++++++- worker/imap/search.go | 8 +++++++- worker/lib/search.go | 8 +++++++- worker/maildir/search.go | 8 +++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd198b2..36dc8f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to aerc will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased](https://git.sr.ht/~rjarry/aerc/log/master) +- Search/filter by flags with the `-H` flag. ### Added diff --git a/doc/aerc-search.1.scd b/doc/aerc-search.1.scd index 9b375d55..68ec685a 100644 --- a/doc/aerc-search.1.scd +++ b/doc/aerc-search.1.scd @@ -6,7 +6,7 @@ aerc-search - search and filter patterns and options for *aerc*(1) # MAILDIR & IMAP -*search* [*-ruba*] [*-x* __] [*-X* __] [*-f* __] [*-t* __] [*-c* __] [*-d* __] [__...] +*search* [*-ruba*] [*-x* __] [*-X* __] [*-H* _Header: Value_] [*-f* __] [*-t* __] [*-c* __] [*-d* __] [__...] Searches the current folder for messages matching the given set of conditions. @@ -30,6 +30,11 @@ aerc-search - search and filter patterns and options for *aerc*(1) _Flagged_ Flagged messages + *-H*: Search in the headers of the messages, for a specific header + Syntax: _Header: Value_ + If the space between _:_ and the value is ommited, aerc will not + search for the Header. + *-b*: Search in the body of the messages *-a*: Search in the entire text of the messages diff --git a/worker/imap/search.go b/worker/imap/search.go index ba7b9174..77a18990 100644 --- a/worker/imap/search.go +++ b/worker/imap/search.go @@ -38,7 +38,13 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) { criteria.WithoutFlags = append(criteria.WithoutFlags, f) } case 'H': - // TODO + if strings.Contains(opt.Value, ": ") { + HeaderValue := strings.SplitN(opt.Value, ": ", 2) + criteria.Header.Add(HeaderValue[0], HeaderValue[1]) + } else { + log.Errorf("Header is not given properly, must be given in format `Header: Value`") + continue + } case 'f': criteria.Header.Add("From", opt.Value) case 't': diff --git a/worker/lib/search.go b/worker/lib/search.go index 0a124e3c..11fc1b11 100644 --- a/worker/lib/search.go +++ b/worker/lib/search.go @@ -44,7 +44,13 @@ func GetSearchCriteria(args []string) (*searchCriteria, error) { case 'X': criteria.WithoutFlags |= getParsedFlag(opt.Value) case 'H': - // TODO + if strings.Contains(opt.Value, ": ") { + HeaderValue := strings.SplitN(opt.Value, ": ", 2) + criteria.Header.Add(HeaderValue[0], HeaderValue[1]) + } else { + log.Errorf("Header is not given properly, must be given in format `Header: Value`") + continue + } case 'f': criteria.Header.Add("From", opt.Value) case 't': diff --git a/worker/maildir/search.go b/worker/maildir/search.go index c667d48f..49cb1c6e 100644 --- a/worker/maildir/search.go +++ b/worker/maildir/search.go @@ -50,7 +50,13 @@ func parseSearch(args []string) (*searchCriteria, error) { case 'X': criteria.WithoutFlags = append(criteria.WithoutFlags, getParsedFlag(opt.Value)) case 'H': - // TODO + if strings.Contains(opt.Value, ": ") { + HeaderValue := strings.SplitN(opt.Value, ": ", 2) + criteria.Header.Add(HeaderValue[0], HeaderValue[1]) + } else { + log.Errorf("Header is not given properly, must be given in format `Header: Value`") + continue + } case 'f': criteria.Header.Add("From", opt.Value) case 't': -- cgit