fix: RFC1342 encode sender name that goes in from header (#8193)

# Which Problems Are Solved

- Some smtp server/client combination may have problems with non-ASCII
sender names for example using an umlaut

# How the Problems Are Solved

- The same RFC1342 mechanism that was added in
#https://github.com/zitadel/zitadel/pull/6637 and later improved by
@eliobischof with BEncoding has been added to the sender name that goes
in the From header

# Additional Context

- Closes #7976
This commit is contained in:
Miguel Cabrerizo 2024-06-28 10:33:42 +02:00 committed by GitHub
parent da592ccf57
commit 14aeb42cc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,7 +34,7 @@ func (msg *Email) GetContent() (string, error) {
headers := make(map[string]string)
from := msg.SenderEmail
if msg.SenderName != "" {
from = fmt.Sprintf("%s <%s>", msg.SenderName, msg.SenderEmail)
from = fmt.Sprintf("%s <%s>", bEncodeWord(msg.SenderName), msg.SenderEmail)
}
headers["From"] = from
if msg.ReplyToAddress != "" {
@ -55,7 +55,7 @@ func (msg *Email) GetContent() (string, error) {
if !isHTML(msg.Content) {
mime = "MIME-Version: 1.0" + lineBreak + "Content-Type: text/plain; charset=\"UTF-8\"" + lineBreak + lineBreak
}
subject := "Subject: " + bEncodeSubject(msg.Subject) + lineBreak
subject := "Subject: " + bEncodeWord(msg.Subject) + lineBreak
message += subject + mime + lineBreak + msg.Content
return message, nil
@ -70,6 +70,6 @@ func isHTML(input string) bool {
}
// returns a RFC1342 "B" encoded string to allow non-ascii characters
func bEncodeSubject(subject string) string {
return mime.BEncoding.Encode("UTF-8", subject)
func bEncodeWord(word string) string {
return mime.BEncoding.Encode("UTF-8", word)
}