From 14aeb42cc29f2f1a14042eb44c20ea958395ddff Mon Sep 17 00:00:00 2001 From: Miguel Cabrerizo <30386061+doncicuto@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:33:42 +0200 Subject: [PATCH] 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 --- internal/notification/messages/email.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/notification/messages/email.go b/internal/notification/messages/email.go index 54b5aae22c..ff5931898f 100644 --- a/internal/notification/messages/email.go +++ b/internal/notification/messages/email.go @@ -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) }