aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--config/aerc.conf6
-rw-r--r--doc/aerc-config.5.scd7
-rw-r--r--widgets/msgviewer.go7
4 files changed, 21 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fed1e0f..107f8dfc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
handler (i.e. `:open gimp` to open attachment in GIMP).
- Restored XOAUTH2 support for IMAP and SMTP.
- Support for attaching files with `mailto:`-links
+- Filter commands now have the `AERC_MIME_TYPE` and `AERC_FILENAME` variables
+ defined in their environment.
### Changed
diff --git a/config/aerc.conf b/config/aerc.conf
index 66aae825..a980c70e 100644
--- a/config/aerc.conf
+++ b/config/aerc.conf
@@ -310,6 +310,11 @@ reply-to-self=true
# $PREFIX/share/aerc/filters
# /usr/share/aerc/filters
#
+# The following variables are defined in the filter command environment:
+#
+# AERC_MIME_TYPE the part MIME type/subtype
+# AERC_FILENAME the attachment filename (if any)
+#
# The first filter which matches the email's mimetype will be used, so order
# them from most to least specific.
#
@@ -323,6 +328,7 @@ message/delivery-status=colorize
message/rfc822=colorize
#text/html=pandoc -f html -t plain | colorize
#text/html=html | colorize
+#text/*=bat -fP --file-name="$AERC_FILENAME"
#application/x-sh=bat -fP -l sh
#image/*=catimg -w $(tput cols) -
#subject,~Git(hub|lab)=lolcat -f
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 9be0cb27..2c5f809d 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -520,6 +520,13 @@ $PREFIX/share/aerc/filters
/usr/share/aerc/filters
```
+The following variables are defined in the filter command environment:
+
+_AERC_MIME_TYPE_
+ the part MIME type/subtype
+_AERC_FILENAME_
+ the attachment filename (if any)
+
Note that said email body is converted into UTF-8 before being passed to
filters.
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index 70c079a3..a32e0399 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -541,8 +541,9 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
pager = exec.Command(cmd[0], cmd[1:]...)
info := msg.MessageInfo()
+ mime := part.FullMIMEType()
+
for _, f := range conf.Filters {
- mime := part.FullMIMEType()
switch f.FilterType {
case config.FILTER_MIMETYPE:
if fnmatch.Match(f.Filter, mime, 0) {
@@ -577,6 +578,10 @@ func NewPartViewer(acct *AccountView, conf *config.AercConfig,
}
filter.Env = os.Environ()
filter.Env = append(filter.Env, fmt.Sprintf("PATH=%s", path))
+ filter.Env = append(filter.Env,
+ fmt.Sprintf("AERC_MIME_TYPE=%s", mime))
+ filter.Env = append(filter.Env,
+ fmt.Sprintf("AERC_FILENAME=%s", part.FileName()))
if pipe, err = filter.StdinPipe(); err != nil {
return nil, err
}