From 33e164168fbecf86c74d730f68b8a3389716f378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20T=C3=B6tterman?= Date: Thu, 26 Oct 2017 10:44:20 +0300 Subject: [PATCH] Fix sending mail with a non-latin display name. #2102 (#2559) (#2783) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix sending mail with a non-latin display name. #2102 Signed-off-by: Rémi Saurel * Take into account the possibility that setting.MailService.From is in `name ` format. #2102 Signed-off-by: Rémi Saurel --- models/mail.go | 2 +- modules/mailer/mailer.go | 6 +++--- modules/setting/setting.go | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/models/mail.go b/models/mail.go index 41fddad2b49a9..37e2ac65d1152 100644 --- a/models/mail.go +++ b/models/mail.go @@ -166,7 +166,7 @@ func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplN log.Error(3, "Template: %v", err) } - msg := mailer.NewMessageFrom(tos, fmt.Sprintf(`"%s" <%s>`, doer.DisplayName(), setting.MailService.FromEmail), subject, content.String()) + msg := mailer.NewMessageFrom(tos, doer.DisplayName(), setting.MailService.FromEmail, subject, content.String()) msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info) return msg } diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 5b28f92c475d1..0bb78de92afbf 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -31,11 +31,11 @@ type Message struct { } // NewMessageFrom creates new mail message object with custom From header. -func NewMessageFrom(to []string, from, subject, body string) *Message { +func NewMessageFrom(to []string, fromDisplayName, fromAddress, subject, body string) *Message { log.Trace("NewMessageFrom (body):\n%s", body) msg := gomail.NewMessage() - msg.SetHeader("From", from) + msg.SetAddressHeader("From", fromAddress, fromDisplayName) msg.SetHeader("To", to...) msg.SetHeader("Subject", subject) msg.SetDateHeader("Date", time.Now()) @@ -58,7 +58,7 @@ func NewMessageFrom(to []string, from, subject, body string) *Message { // NewMessage creates new mail message object with default From header. func NewMessage(to []string, subject, body string) *Message { - return NewMessageFrom(to, setting.MailService.From, subject, body) + return NewMessageFrom(to, setting.MailService.FromName, setting.MailService.FromEmail, subject, body) } type loginAuth struct { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cbbeeb5a09bce..702120dd3c17e 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -1281,6 +1281,7 @@ type Mailer struct { QueueLength int Name string From string + FromName string FromEmail string SendAsPlainText bool @@ -1339,6 +1340,7 @@ func newMailService() { if err != nil { log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err) } + MailService.FromName = parsed.Name MailService.FromEmail = parsed.Address log.Info("Mail Service Enabled")