diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/aerc.conf | 9 | ||||
-rw-r--r-- | config/config.go | 2 | ||||
-rw-r--r-- | config/hooks.go | 62 | ||||
-rw-r--r-- | config/triggers.go | 61 |
4 files changed, 66 insertions, 68 deletions
diff --git a/config/aerc.conf b/config/aerc.conf index 02ea96fe..5ff252f5 100644 --- a/config/aerc.conf +++ b/config/aerc.conf @@ -506,16 +506,13 @@ message/rfc822=colorize # text/plain=gvim {} +125 # message/rfc822=thunderbird -[triggers] +[hooks] # -# Triggers specify commands to execute when certain events occur. -# -# Example: -# new-email=exec notify-send "New email from %n" "%s" +# Hooks are triggered whenever the associated event occurs. # # Executed when a new email arrives in the selected folder -#new-email= +#mail-received=notify-send "New mail from $AERC_FROM_NAME" "$AERC_SUBJECT" [templates] # Templates are used to populate email bodies automatically. diff --git a/config/config.go b/config/config.go index de8cd0d0..d70bcfe0 100644 --- a/config/config.go +++ b/config/config.go @@ -132,7 +132,7 @@ func LoadConfigFromFile(root *string, accts []string) error { if err := parseOpeners(file); err != nil { return err } - if err := parseTriggers(file); err != nil { + if err := parseHooks(file); err != nil { return err } if err := parseUi(file); err != nil { diff --git a/config/hooks.go b/config/hooks.go new file mode 100644 index 00000000..9bbd9031 --- /dev/null +++ b/config/hooks.go @@ -0,0 +1,62 @@ +package config + +import ( + "strings" + + "git.sr.ht/~rjarry/aerc/log" + "github.com/go-ini/ini" +) + +type HooksConfig struct { + MailReceived string `ini:"mail-received"` +} + +var Hooks HooksConfig + +func parseHooks(file *ini.File) error { + err := MapToStruct(file.Section("hooks"), &Hooks, true) + if err != nil { + return err + } + + newEmail := file.Section("triggers").Key("new-email").String() + if Hooks.MailReceived == "" && newEmail != "" { + Hooks.MailReceived = convertNewEmailTrigger(newEmail) + Warnings = append(Warnings, Warning{ + Title: "DEPRECATION NOTICE: [triggers].new-email", + Body: ` +The new-email trigger has been replaced by [hooks].email-received. + +Your configuration in this instance was automatically converted to: + +[hooks] +mail-received = ` + Hooks.MailReceived + ` + +Please verify the accuracy of the above translation. + +Your configuration file was not changed. To make this change permanent and to +dismiss this deprecation warning on launch, copy the above lines into aerc.conf +and remove new-email from it. See aerc-config(5) for more details. +`, + }) + } + + log.Debugf("aerc.conf: [hooks] %#v", Hooks) + return nil +} + +func convertNewEmailTrigger(old string) string { + translations := map[string]string{ + "%a": "$AERC_FROM_ADDRESS", + "%n": "$AERC_FROM_NAME", + "%s": "$AERC_SUBJECT", + "%f": "$AERC_FROM_NAME <$AERC_FROM_ADDRESS>", + "%u": `$(echo "$AERC_FROM_ADDRESS" | cut -d@ -f1)`, + "%v": `$(echo "$AERC_FROM_NAME" | cut -d' ' -f1)`, + } + for replace, with := range translations { + old = strings.ReplaceAll(old, replace, with) + } + old = strings.TrimPrefix(old, "exec ") + return strings.ReplaceAll(old, "%%", "%") +} diff --git a/config/triggers.go b/config/triggers.go deleted file mode 100644 index 82750c2d..00000000 --- a/config/triggers.go +++ /dev/null @@ -1,61 +0,0 @@ -package config - -import ( - "github.com/go-ini/ini" - "github.com/google/shlex" - - "git.sr.ht/~rjarry/aerc/lib/format" - "git.sr.ht/~rjarry/aerc/log" -) - -type TriggersConfig struct { - NewEmail []string `ini:"new-email" parse:"ParseNewEmail"` -} - -var Triggers = new(TriggersConfig) - -func parseTriggers(file *ini.File) error { - if err := MapToStruct(file.Section("triggers"), Triggers, true); err != nil { - return err - } - log.Debugf("aerc.conf: [triggers] %#v", Triggers) - return nil -} - -func (t *TriggersConfig) ParseNewEmail(_ *ini.Section, key *ini.Key) ([]string, error) { - cmd := indexFmtRegexp.ReplaceAllStringFunc( - key.String(), - func(s string) string { - runes := []rune(s) - t, _ := indexVerbToTemplate(runes[len(runes)-1]) - return t - }, - ) - args, err := shlex.Split(cmd) - if err != nil { - return nil, err - } - if cmd != key.String() { - log.Warnf("%s %s", - "The new-email trigger now uses templates instead of %-based placeholders.", - "Backward compatibility will be removed in aerc 0.17.") - Warnings = append(Warnings, Warning{ - Title: "FORMAT CHANGED: [triggers].new-email", - Body: ` -The new-email trigger now uses templates instead of %-based placeholders. - -Your configuration in this instance was automatically converted to: - -[triggers] -new-email = ` + format.ShellQuote(args) + ` - -Your configuration file was not changed. To make this change permanent and to -dismiss this warning on launch, replace the above line into aerc.conf. See -aerc-config(5) for more details. - -The automatic conversion of new-email will be removed in aerc 0.17. -`, - }) - } - return args, nil -} |