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>
This commit is contained in:
Moritz Poldrack 2022-02-28 18:02:28 +01:00 committed by Robin Jarry
parent 515a8b56f6
commit 2f575c00ec
1 changed files with 10 additions and 6 deletions

View File

@ -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): ?)+`)