* Fix sending mail with a non-latin display name. #2102 Signed-off-by: Rémi Saurel <contact@remi-saurel.com> * Take into account the possibility that setting.MailService.From is in `name <email@address>` format. #2102 Signed-off-by: Rémi Saurel <contact@remi-saurel.com>tags/v1.21.12.1
| @@ -167,7 +167,7 @@ func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplN | |||||
| log.Error(3, "Template: %v", err) | 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) | msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info) | ||||
| return msg | return msg | ||||
| } | } | ||||
| @@ -31,11 +31,11 @@ type Message struct { | |||||
| } | } | ||||
| // NewMessageFrom creates new mail message object with custom From header. | // 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) | log.Trace("NewMessageFrom (body):\n%s", body) | ||||
| msg := gomail.NewMessage() | msg := gomail.NewMessage() | ||||
| msg.SetHeader("From", from) | |||||
| msg.SetAddressHeader("From", fromAddress, fromDisplayName) | |||||
| msg.SetHeader("To", to...) | msg.SetHeader("To", to...) | ||||
| msg.SetHeader("Subject", subject) | msg.SetHeader("Subject", subject) | ||||
| msg.SetDateHeader("Date", time.Now()) | 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. | // NewMessage creates new mail message object with default From header. | ||||
| func NewMessage(to []string, subject, body string) *Message { | 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 { | type loginAuth struct { | ||||
| @@ -1287,6 +1287,7 @@ type Mailer struct { | |||||
| QueueLength int | QueueLength int | ||||
| Name string | Name string | ||||
| From string | From string | ||||
| FromName string | |||||
| FromEmail string | FromEmail string | ||||
| SendAsPlainText bool | SendAsPlainText bool | ||||
| @@ -1345,6 +1346,7 @@ func newMailService() { | |||||
| if err != nil { | if err != nil { | ||||
| log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err) | log.Fatal(4, "Invalid mailer.FROM (%s): %v", MailService.From, err) | ||||
| } | } | ||||
| MailService.FromName = parsed.Name | |||||
| MailService.FromEmail = parsed.Address | MailService.FromEmail = parsed.Address | ||||
| log.Info("Mail Service Enabled") | log.Info("Mail Service Enabled") | ||||