From a88662bb3a50e48dae06b41705fd9ee342022a1a Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Thu, 22 Feb 2024 15:11:55 +0100 Subject: [PATCH] fix(smtp): support UTF-8 subjects (#7432) fix(smtp): support utf8 subjects --- internal/notification/messages/email.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/notification/messages/email.go b/internal/notification/messages/email.go index 0a71b691df..cd3f362f82 100644 --- a/internal/notification/messages/email.go +++ b/internal/notification/messages/email.go @@ -2,6 +2,7 @@ package messages import ( "fmt" + "mime" "regexp" "strings" "time" @@ -54,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: " + qEncodeSubject(msg.Subject) + lineBreak + subject := "Subject: " + bEncodeSubject(msg.Subject) + lineBreak message += subject + mime + lineBreak + msg.Content return message, nil @@ -68,7 +69,7 @@ func isHTML(input string) bool { return isHTMLRgx.MatchString(input) } -// returns a RFC1342 "Q" encoded string to allow non-ascii characters -func qEncodeSubject(subject string) string { - return "=?utf-8?q?" + subject + "?=" +// returns a RFC1342 "B" encoded string to allow non-ascii characters +func bEncodeSubject(subject string) string { + return mime.BEncoding.Encode("UTF-8", subject) }