diff options
author | Bence Ferdinandy <bence@ferdinandy.com> | 2024-03-13 13:48:38 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2024-03-25 23:11:22 +0100 |
commit | 6ffc0ed5991bef69a50cbc22647af0a6a0e0a895 (patch) | |
tree | 268c12d3a9104ae5b5580eda15488914a8abcd6b /config | |
parent | 523ca15a3b4882a4e49eb4736cc2d5d11b8df9a7 (diff) | |
download | aerc-6ffc0ed5991bef69a50cbc22647af0a6a0e0a895.tar.gz |
filters: add matching against attachment filename
The mimetype of attachments are set by the sender, which can results in
attachments getting not so useful mimetypes (e.g.
application/octet-stream for a csv). Allow matching filter against
filenames directly, by adding the `.filename,` and `.filename,~` syntax,
similarly to headers.
Changelog-added: Match filters on filename via `.filename,~<regexp> =`.
Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'config')
-rw-r--r-- | config/filters.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/config/filters.go b/config/filters.go index 1bbeaa30..e843c5fa 100644 --- a/config/filters.go +++ b/config/filters.go @@ -14,6 +14,7 @@ const ( FILTER_MIMETYPE FilterType = iota FILTER_HEADER FILTER_HEADERS + FILTER_FILENAME ) type FilterConfig struct { @@ -37,7 +38,22 @@ func parseFilters(file *ini.File) error { Command: key.Value(), Filter: key.Name(), } + switch { + case strings.HasPrefix(filter.Filter, ".filename,~"): + filter.Type = FILTER_FILENAME + regex := filter.Filter[strings.Index(filter.Filter, "~")+1:] + filter.Regex, err = regexp.Compile(regex) + if err != nil { + return err + } + case strings.HasPrefix(filter.Filter, ".filename,"): + filter.Type = FILTER_FILENAME + value := filter.Filter[strings.Index(filter.Filter, ",")+1:] + filter.Regex, err = regexp.Compile(regexp.QuoteMeta(value)) + if err != nil { + return err + } case strings.Contains(filter.Filter, ",~"): filter.Type = FILTER_HEADER //nolint:gocritic // guarded by strings.Contains |