make it harder to forget to set smtputf8 on message.Composer

we should do better: first gather all headers, and only write it when we start
on the body, and then calculate smtputf8 ourselves.
This commit is contained in:
Mechiel Lukkien
2024-03-16 20:54:10 +01:00
parent 8b2c97808d
commit cef83341e5
5 changed files with 37 additions and 34 deletions

View File

@ -620,7 +620,15 @@ Period: %s - %s UTC
}
func composeMessage(ctx context.Context, log mlog.Log, mf *os.File, policyDomain dns.Domain, confDKIM config.DKIM, fromAddr smtp.Address, recipients []message.NameAddress, subject, text, filename string, reportFile *os.File) (msgPrefix string, has8bit, smtputf8 bool, messageID string, rerr error) {
xc := message.NewComposer(mf, 100*1024*1024)
// We only use smtputf8 if we have to, with a utf-8 localpart. For IDNA, we use ASCII domains.
smtputf8 = fromAddr.Localpart.IsInternational()
for _, r := range recipients {
if smtputf8 {
smtputf8 = r.Address.Localpart.IsInternational()
break
}
}
xc := message.NewComposer(mf, 100*1024*1024, smtputf8)
defer func() {
x := recover()
if x == nil {
@ -633,14 +641,6 @@ func composeMessage(ctx context.Context, log mlog.Log, mf *os.File, policyDomain
panic(x)
}()
// We only use smtputf8 if we have to, with a utf-8 localpart. For IDNA, we use ASCII domains.
for _, a := range recipients {
if a.Address.Localpart.IsInternational() {
xc.SMTPUTF8 = true
break
}
}
xc.HeaderAddrs("From", []message.NameAddress{{Address: fromAddr}})
xc.HeaderAddrs("To", recipients)
xc.Subject(subject)