From 40cc540357d92aee07fba2819801e168d3bf0f33 Mon Sep 17 00:00:00 2001 From: jp39 Date: Thu, 10 Nov 2022 19:39:19 +0100 Subject: reply: allow to override localized Re regexp in configuration My corporate email server annoyingly adds an "[External] " prefix when delivering emails from outside my organization. I'd like to be able to automatically strip it from the subject line when replying to external emails. With this patch, I can achieve it by setting this line in my account configuration: subject-re-pattern = ^(\[External\] : )?((?i)((AW|RE|SV|VS|ODP|R): ?)+) Signed-off-by: jp39 Acked-by: Moritz Poldrack --- config/config.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'config/config.go') diff --git a/config/config.go b/config/config.go index 2da4559f..7d84476e 100644 --- a/config/config.go +++ b/config/config.go @@ -175,6 +175,7 @@ type AccountConfig struct { FoldersSort []string `ini:"folders-sort" delim:","` AddressBookCmd string `ini:"address-book-cmd"` SendAsUTC bool `ini:"send-as-utc"` + LocalizedRe *regexp.Regexp // CheckMail CheckMail time.Duration `ini:"check-mail"` @@ -313,6 +314,8 @@ func loadAccountConfig(path string, accts []string) ([]AccountConfig, error) { Params: make(map[string]string), EnableFoldersSort: true, CheckMailTimeout: 10 * time.Second, + // localizedRe contains a list of known translations for the common Re: + LocalizedRe: regexp.MustCompile(`(?i)^((AW|RE|SV|VS|ODP|R): ?)+`), } if err = sec.MapTo(&account); err != nil { return nil, err @@ -360,6 +363,13 @@ func loadAccountConfig(path string, accts []string) ([]AccountConfig, error) { account.PgpOpportunisticEncrypt, _ = strconv.ParseBool(val) case "address-book-cmd": account.AddressBookCmd = val + case "subject-re-pattern": + re, err := regexp.Compile(val) + if err != nil { + return nil, fmt.Errorf( + "%s=%s %w", key, val, err) + } + account.LocalizedRe = re default: if key != "name" { account.Params[key] = val -- cgit