mailer: make text/html as default format

Change config option from '[mailer] ENABLE_HTML_ALTERNATIVE' to '[mailer] USE_PLAIN_TEXT'
master
Unknwon 2017-02-23 12:16:10 -05:00
parent a47553b7aa
commit c7a8051a71
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
5 changed files with 39 additions and 36 deletions

View File

@ -13,6 +13,7 @@ The issue will be closed without any reasons if it does not satisfy any of follo
- Database (use `[x]`):
- [ ] PostgreSQL
- [ ] MySQL
- [ ] MSSQL
- [ ] SQLite
- Can you reproduce the bug at https://try.gogs.io:
- [ ] Yes (provide example URL)

View File

@ -218,8 +218,8 @@ FROM =
; Mailer user name and password
USER =
PASSWD =
; Use text/html as alternative format of content
ENABLE_HTML_ALTERNATIVE = false
; Use text/plain as format of content
USE_PLAIN_TEXT = false
[cache]
; Either "memory", "redis", or "memcache", default is "memory"

File diff suppressed because one or more lines are too long

View File

@ -36,16 +36,18 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message {
msg.SetHeader("Subject", subject)
msg.SetDateHeader("Date", time.Now())
body, err := html2text.FromString(htmlBody)
contentType := "text/html"
body := htmlBody
if setting.MailService.UsePlainText {
plainBody, err := html2text.FromString(htmlBody)
if err != nil {
log.Error(4, "html2text.FromString: %v", err)
msg.SetBody("text/html", htmlBody)
log.Error(2, "html2text.FromString: %v", err)
} else {
msg.SetBody("text/plain", body)
if setting.MailService.EnableHTMLAlternative {
msg.AddAlternative("text/html", htmlBody)
contentType = "text/plain"
body = plainBody
}
}
msg.SetBody(contentType, body)
return &Message{
Message: msg,

View File

@ -752,7 +752,7 @@ func newSessionService() {
// Mailer represents mail service.
type Mailer struct {
QueueLength int
Name string
Subject string
Host string
From string
FromEmail string
@ -762,7 +762,7 @@ type Mailer struct {
SkipVerify bool
UseCertificate bool
CertFile, KeyFile string
EnableHTMLAlternative bool
UsePlainText bool
}
var (
@ -778,7 +778,7 @@ func newMailService() {
MailService = &Mailer{
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
Name: sec.Key("NAME").MustString(AppName),
Subject: sec.Key("SUBJECT").MustString(AppName),
Host: sec.Key("HOST").String(),
User: sec.Key("USER").String(),
Passwd: sec.Key("PASSWD").String(),
@ -788,7 +788,7 @@ func newMailService() {
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
CertFile: sec.Key("CERT_FILE").String(),
KeyFile: sec.Key("KEY_FILE").String(),
EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
UsePlainText: sec.Key("USE_PLAIN_TEXT").MustBool(),
}
MailService.From = sec.Key("FROM").MustString(MailService.User)