Browse Source

mailer: make text/html as default format

Change config option from '[mailer] ENABLE_HTML_ALTERNATIVE' to '[mailer] USE_PLAIN_TEXT'
pull/4240/head
Unknwon 8 years ago
parent
commit
c7a8051a71
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 1
      .github/ISSUE_TEMPLATE.md
  2. 4
      conf/app.ini
  3. 4
      modules/bindata/bindata.go
  4. 14
      modules/mailer/mailer.go
  5. 8
      modules/setting/setting.go

1
.github/ISSUE_TEMPLATE.md

@ -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)

4
conf/app.ini

@ -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"

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

14
modules/mailer/mailer.go

@ -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,

8
modules/setting/setting.go

@ -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)

Loading…
Cancel
Save