aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/msgviewer.go5
-rw-r--r--config/filters.go16
-rw-r--r--doc/aerc-config.5.scd11
3 files changed, 31 insertions, 1 deletions
diff --git a/app/msgviewer.go b/app/msgviewer.go
index 7b24e756..a78daa3a 100644
--- a/app/msgviewer.go
+++ b/app/msgviewer.go
@@ -480,6 +480,11 @@ func NewPartViewer(
if f.Regex.Match([]byte(header)) {
filter = exec.Command("sh", "-c", f.Command)
}
+ case config.FILTER_FILENAME:
+ if f.Regex.Match([]byte(part.DispositionParams["filename"])) {
+ filter = exec.Command("sh", "-c", f.Command)
+ log.Tracef("command %v", f.Command)
+ }
}
if filter != nil {
break
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
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index b26d7695..60fc5b7f 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -906,7 +906,8 @@ filter which matches the part's MIME type will be used, so order them from most
to least specific. You can also match on non-MIME types, by prefixing with the
header to match against (non-case-sensitive) and a comma, e.g. _subject,text_
will match a subject which contains _text_. Use _header,~regex_ to match
-against a _regex_.
+against a _regex_. Using _.filename_ instead of a header will match against the
+filename of an attachment.
Note that aerc will pipe the content into the configured filter program, so
filters need to be able to read from standard input. Many programs support
@@ -1080,6 +1081,14 @@ _image/\*_
image/\*=catimg -w$(tput cols) -
```
+_.filename,~<regexp>_
+ Match <regexp> against the filename of an attachment, e.g. to split
+ csv-s into columns:
+
+ ```
+ .filename,~.*\.csv=column -t --separator=","
+ ```
+
See the wiki at https://man.sr.ht/~rjarry/aerc/ for more examples and possible
customizations of the built-in filters.