#2954 use text/plain as default email content format
This commit is contained in:
		
							parent
							
								
									d35a1c30f4
								
							
						
					
					
						commit
						8df3ba96f3
					
				
					 7 changed files with 259 additions and 251 deletions
				
			
		|  | @ -3,7 +3,7 @@ Gogs - Go Git Service [ | ||||
| 
 | ||||
| ##### Current version: 0.9.28 | ||||
| ##### Current version: 0.9.29 | ||||
| 
 | ||||
| | Web | UI  | Preview  | | ||||
| |:-------------:|:-------:|:-------:| | ||||
|  |  | |||
|  | @ -185,6 +185,8 @@ FROM = | |||
| ; Mailer user name and password | ||||
| USER = | ||||
| PASSWD = | ||||
| ; Use text/html as alternative format of content | ||||
| ENABLE_HTML_ALTERNATIVE = false | ||||
| 
 | ||||
| [cache] | ||||
| ; Either "memory", "redis", or "memcache", default is "memory" | ||||
|  |  | |||
							
								
								
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								gogs.go
									
									
									
									
									
								
							|  | @ -17,7 +17,7 @@ import ( | |||
| 	"github.com/gogits/gogs/modules/setting" | ||||
| ) | ||||
| 
 | ||||
| const APP_VER = "0.9.28.0527" | ||||
| const APP_VER = "0.9.29.0530" | ||||
| 
 | ||||
| func init() { | ||||
| 	runtime.GOMAXPROCS(runtime.NumCPU()) | ||||
|  |  | |||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -14,11 +14,11 @@ import ( | |||
| 	"strings" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/jaytaylor/html2text" | ||||
| 	"gopkg.in/gomail.v2" | ||||
| 
 | ||||
| 	"github.com/gogits/gogs/modules/log" | ||||
| 	"github.com/gogits/gogs/modules/setting" | ||||
| 	"github.com/jaytaylor/html2text" | ||||
| ) | ||||
| 
 | ||||
| type Message struct { | ||||
|  | @ -27,20 +27,24 @@ type Message struct { | |||
| } | ||||
| 
 | ||||
| // NewMessageFrom creates new mail message object with custom From header.
 | ||||
| func NewMessageFrom(to []string, from, subject, htmlbody 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()) | ||||
| 	body, err := html2text.FromString(htmlbody) | ||||
| 
 | ||||
| 	body, err := html2text.FromString(htmlBody) | ||||
| 	if err != nil { | ||||
| 		// TODO: report error ?
 | ||||
| 		msg.SetBody("text/html", htmlbody) | ||||
| 		log.Error(4, "html2text.FromString: %v", err) | ||||
| 		msg.SetBody("text/html", htmlBody) | ||||
| 		msg.AddAlternative("text/html", htmlBody) | ||||
| 	} else { | ||||
| 		msg.SetBody("text/plain", body) | ||||
| 		// TODO: avoid this (use a configuration switch?)
 | ||||
| 		msg.AddAlternative("text/html", htmlbody) | ||||
| 	} | ||||
| 
 | ||||
| 	if setting.MailService.EnableHTMLAlternative { | ||||
| 		msg.AddAlternative("text/html", htmlBody) | ||||
| 	} | ||||
| 
 | ||||
| 	return &Message{ | ||||
|  |  | |||
|  | @ -612,16 +612,17 @@ func newSessionService() { | |||
| 
 | ||||
| // Mailer represents mail service.
 | ||||
| type Mailer struct { | ||||
| 	QueueLength       int | ||||
| 	Name              string | ||||
| 	Host              string | ||||
| 	From              string | ||||
| 	User, Passwd      string | ||||
| 	DisableHelo       bool | ||||
| 	HeloHostname      string | ||||
| 	SkipVerify        bool | ||||
| 	UseCertificate    bool | ||||
| 	CertFile, KeyFile string | ||||
| 	QueueLength           int | ||||
| 	Name                  string | ||||
| 	Host                  string | ||||
| 	From                  string | ||||
| 	User, Passwd          string | ||||
| 	DisableHelo           bool | ||||
| 	HeloHostname          string | ||||
| 	SkipVerify            bool | ||||
| 	UseCertificate        bool | ||||
| 	CertFile, KeyFile     string | ||||
| 	EnableHTMLAlternative bool | ||||
| } | ||||
| 
 | ||||
| var ( | ||||
|  | @ -636,17 +637,18 @@ func newMailService() { | |||
| 	} | ||||
| 
 | ||||
| 	MailService = &Mailer{ | ||||
| 		QueueLength:    sec.Key("SEND_BUFFER_LEN").MustInt(100), | ||||
| 		Name:           sec.Key("NAME").MustString(AppName), | ||||
| 		Host:           sec.Key("HOST").String(), | ||||
| 		User:           sec.Key("USER").String(), | ||||
| 		Passwd:         sec.Key("PASSWD").String(), | ||||
| 		DisableHelo:    sec.Key("DISABLE_HELO").MustBool(), | ||||
| 		HeloHostname:   sec.Key("HELO_HOSTNAME").String(), | ||||
| 		SkipVerify:     sec.Key("SKIP_VERIFY").MustBool(), | ||||
| 		UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(), | ||||
| 		CertFile:       sec.Key("CERT_FILE").String(), | ||||
| 		KeyFile:        sec.Key("KEY_FILE").String(), | ||||
| 		QueueLength:           sec.Key("SEND_BUFFER_LEN").MustInt(100), | ||||
| 		Name:                  sec.Key("NAME").MustString(AppName), | ||||
| 		Host:                  sec.Key("HOST").String(), | ||||
| 		User:                  sec.Key("USER").String(), | ||||
| 		Passwd:                sec.Key("PASSWD").String(), | ||||
| 		DisableHelo:           sec.Key("DISABLE_HELO").MustBool(), | ||||
| 		HeloHostname:          sec.Key("HELO_HOSTNAME").String(), | ||||
| 		SkipVerify:            sec.Key("SKIP_VERIFY").MustBool(), | ||||
| 		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(), | ||||
| 	} | ||||
| 	MailService.From = sec.Key("FROM").MustString(MailService.User) | ||||
| 	log.Info("Mail Service Enabled") | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| 0.9.28.0527 | ||||
| 0.9.29.0530 | ||||
		Loading…
	
		Reference in a new issue