summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorSandro Santilli <strk@kbt.io>2016-05-30 10:18:49 +0200
committerUnknwon <u@gogs.io>2016-05-30 01:18:49 -0700
commitd35a1c30f45d11d2e38ac848eb70c89f9a3cc524 (patch)
treed005835070743745e0c5d005b68452a9e601b5c4 /modules
parente9ae926e040c94ce66666ae6c330c93918fa321c (diff)
downloadgitea-d35a1c30f45d11d2e38ac848eb70c89f9a3cc524.tar.gz
gitea-d35a1c30f45d11d2e38ac848eb70c89f9a3cc524.zip
Do not write HTML in text/plain mail part (#2954)
* Do not write HTML in text/plain mail part Fixes #2928 * Pass text/plain first, text/html second * Do not send plain/text email if html2text failed (untested)
Diffstat (limited to 'modules')
-rw-r--r--modules/mailer/mailer.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go
index e1c453a22e..b43df4de47 100644
--- a/modules/mailer/mailer.go
+++ b/modules/mailer/mailer.go
@@ -18,6 +18,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/setting"
+ "github.com/jaytaylor/html2text"
)
type Message struct {
@@ -26,14 +27,21 @@ 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, from, subject, htmlbody string) *Message {
msg := gomail.NewMessage()
msg.SetHeader("From", from)
msg.SetHeader("To", to...)
msg.SetHeader("Subject", subject)
msg.SetDateHeader("Date", time.Now())
- msg.SetBody("text/plain", body)
- msg.AddAlternative("text/html", body)
+ body, err := html2text.FromString(htmlbody)
+ if err != nil {
+ // TODO: report error ?
+ msg.SetBody("text/html", htmlbody)
+ } else {
+ msg.SetBody("text/plain", body)
+ // TODO: avoid this (use a configuration switch?)
+ msg.AddAlternative("text/html", htmlbody)
+ }
return &Message{
Message: msg,