diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-31 14:24:53 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-31 14:24:53 -0400 |
commit | bbdf9df75e8597e38cf1d90145f22aab9bd95178 (patch) | |
tree | e721502779327758956694edffbd6e01762801e9 /config | |
parent | 711d22891bd50646d1cf925fbf0b8a760c638fd0 (diff) | |
download | aerc-bbdf9df75e8597e38cf1d90145f22aab9bd95178.tar.gz |
Add basic filter implementation
Diffstat (limited to 'config')
-rw-r--r-- | config/aerc.conf | 45 | ||||
-rw-r--r-- | config/config.go | 47 |
2 files changed, 67 insertions, 25 deletions
diff --git a/config/aerc.conf b/config/aerc.conf index 5a4317f..3a89151 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -54,32 +54,12 @@ empty-message=(no messages) [viewer] # -# We can use different programs to display various kinds of email attachments. -# These programs will have the mail piped into them and are expected to output -# it ready to display on a terminal (you can include terminal control -# characters if you like, for colors and such). Emails will be stripped of -# non-printable characters before being piped into these commands, and will be -# encoded with UTF-8. These commands are invoked with sh and run -# non-interactively, and their output is piped into your pager command -# (interactively). The following environment variables will be set: +# Specifies the pager to use when displaying emails. Note that some filters +# may add ANSI codes to add color to rendered emails, so you may want to use a +# pager which supports ANSI codes. # -# $WIDTH: the width of the terminal window -# $HEIGHT: the height of the terminal window -# $MIMETYPE: the email's mimetype -# -# You can use * as a wildcard for any subtype of a given mimetype. When -# displaying a text/* message and no command matches, the message will just be -# piped directly into your pager (after being stripped of non-printable -# characters). - -# Examples: -# -#text/html=w3m -T text/html -cols $WIDTH -dump -o display_image=false -o display_link_number=true -text/*=fold -sw $WIDTH - -# -# Default: less -r -pager=less -r +# Default: less -R +pager=less -R # # If an email offers several versions (multipart), you can configure which @@ -89,6 +69,21 @@ pager=less -r # Default: text/plain,text/html alternatives=text/plain,text/html +[filters] +# +# Filters allow you to pipe an email body through a shell command to render +# certain emails differently, e.g. highlighting them with ANSI escape codes. +# +# The first filter which matches the email's mimetype will be used, so order +# them from most to least specific. +# +# You can also match on non-mimetypes, by prefixing with the header to match +# against (non-case-sensitive) and a colon, e.g. subject:text will match a +# subject which contains "text". Use header~:regex to match against a regex. +subject~:PATCH=contrib/hldiff.py +text/html=w3m -T text/html -cols $(tput cols) -dump -o display_image=false -o display_link_number=true +text/*=contrib/plaintext.py + [lbinds] # # Binds are of the form <input keys> = <output keys> diff --git a/config/config.go b/config/config.go index e5e332e..8d460ca 100644 --- a/config/config.go +++ b/config/config.go @@ -22,6 +22,12 @@ type UIConfig struct { EmptyMessage string `ini:"empty-message"` } +const ( + FILTER_MIMETYPE = iota + FILTER_HEADER + FILTER_HEADER_REGEX +) + type AccountConfig struct { Default string Name string @@ -38,10 +44,23 @@ type BindingConfig struct { Terminal *KeyBindings } +type FilterConfig struct { + FilterType int + Filter string + Command string +} + +type ViewerConfig struct { + Pager string + Alternatives []string +} + type AercConfig struct { Bindings BindingConfig Ini *ini.File `ini:"-"` Accounts []AccountConfig `ini:"-"` + Filters []FilterConfig `ini:"-"` + Viewer ViewerConfig `ini:"-"` Ui UIConfig } @@ -135,6 +154,34 @@ func LoadConfig(root *string) (*AercConfig, error) { EmptyMessage: "(no messages)", }, } + if filters, err := file.GetSection("filters"); err == nil { + // TODO: Parse the filter more finely, e.g. parse the regex + for match, cmd := range filters.KeysHash() { + filter := FilterConfig{ + Command: cmd, + Filter: match, + } + if strings.Contains(match, "~:") { + filter.FilterType = FILTER_HEADER_REGEX + } else if strings.ContainsRune(match, ':') { + filter.FilterType = FILTER_HEADER + } else { + filter.FilterType = FILTER_MIMETYPE + } + config.Filters = append(config.Filters, filter) + } + } + if viewer, err := file.GetSection("viewer"); err == nil { + if err := viewer.MapTo(&config.Viewer); err != nil { + return nil, err + } + for key, val := range viewer.KeysHash() { + switch key { + case "alternatives": + config.Viewer.Alternatives = strings.Split(val, ",") + } + } + } if ui, err := file.GetSection("ui"); err == nil { if err := ui.MapTo(&config.Ui); err != nil { return nil, err |