diff options
author | Moritz Poldrack <git@moritz.sh> | 2022-02-28 18:02:28 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-03-03 21:31:26 +0100 |
commit | 2f575c00ec5fa2fc8f6d4d65c26557ad7ccab9a3 (patch) | |
tree | d7e64ff155dd94a0e48221f13f45e6cb0cbe7c27 /commands | |
parent | 515a8b56f6e9b4e6efaf6a6a29c851dadf4b4a56 (diff) | |
download | aerc-2f575c00ec5fa2fc8f6d4d65c26557ad7ccab9a3.tar.gz |
reply: add automatic replacement of localized Re:
Some MUAs (namely Outlook) use localized prefixes for replied-to and
forwarded mail. With this patch aerc replaces known localized prefixes
and repetitions with the common Re: prefix.
Link: https://office-watch.com/2014/outlook-reply-forward-prefixes/
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/msg/reply.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go index dac9f7a6..c3ab202c 100644 --- a/commands/msg/reply.go +++ b/commands/msg/reply.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "regexp" "strings" "git.sr.ht/~sircmpwn/getopt" @@ -154,12 +155,7 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error { recSet.AddList(cc) } - var subject string - if !strings.HasPrefix(strings.ToLower(msg.Envelope.Subject), "re: ") { - subject = "Re: " + msg.Envelope.Subject - } else { - subject = msg.Envelope.Subject - } + subject := "Re: " + trimLocalizedRe(msg.Envelope.Subject) h := &mail.Header{} h.SetAddressList("to", to) @@ -298,3 +294,11 @@ func addMimeType(msg *models.MessageInfo, part []int, orig.MIMEType = fmt.Sprintf("%s/%s", bs.MIMEType, bs.MIMESubType) return nil } + +// trimLocalizedRe removes known localizations of Re: commonly used by Outlook. +func trimLocalizedRe(subject string) string { + return strings.TrimPrefix(subject, localizedRe.FindString(subject)) +} + +// localizedRe contains a list of known translations for the common Re: +var localizedRe = regexp.MustCompile(`(?i)^((AW|RE|SV|VS|ODP|R): ?)+`) |