diff options
author | ᴜɴᴋɴᴡᴏɴ <u@gogs.io> | 2020-02-22 09:05:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-22 09:05:26 +0800 |
commit | 648d9e253c1924b832248f26fee42b2fb64dc3bc (patch) | |
tree | 51649fad974cd7284a47d30e412c90e7ab72cd2c /internal/mailer | |
parent | 5b14cc6f0b7b661beb2640a94bd15660cdb48587 (diff) |
conf: overhaul server settings (#5928)
* conf: rename package
* Requires Go 1.12
* Fix lint
* Fix lint
* Overhaul
* db: fix tests
* Save my work
* Fix tests
* Server.UnixSocketPermission
* Server.LocalRootURL
* SSH settings
* Server.OfflineMode
* Save my work
* App.Version
* Remove [server] STATIC_ROOT_PATH
* Server.LandingURL
Diffstat (limited to 'internal/mailer')
-rw-r--r-- | internal/mailer/mail.go | 22 | ||||
-rw-r--r-- | internal/mailer/mailer.go | 18 |
2 files changed, 20 insertions, 20 deletions
diff --git a/internal/mailer/mail.go b/internal/mailer/mail.go index f4bf9414..835f1905 100644 --- a/internal/mailer/mail.go +++ b/internal/mailer/mail.go @@ -7,7 +7,7 @@ package mailer import ( "fmt" "html/template" - "path" + "path/filepath" "sync" "time" @@ -16,8 +16,8 @@ import ( log "unknwon.dev/clog/v2" "gogs.io/gogs/internal/assets/templates" + "gogs.io/gogs/internal/conf" "gogs.io/gogs/internal/markup" - "gogs.io/gogs/internal/setting" ) const ( @@ -41,15 +41,15 @@ var ( func render(tpl string, data map[string]interface{}) (string, error) { tplRenderOnce.Do(func() { opt := &macaron.RenderOptions{ - Directory: path.Join(setting.StaticRootPath, "templates/mail"), - AppendDirectories: []string{path.Join(setting.CustomPath, "templates/mail")}, + Directory: filepath.Join(conf.WorkDir(), "templates", "mail"), + AppendDirectories: []string{filepath.Join(conf.CustomDir(), "templates", "mail")}, Extensions: []string{".tmpl", ".html"}, Funcs: []template.FuncMap{map[string]interface{}{ "AppName": func() string { - return setting.AppName + return conf.App.BrandName }, "AppURL": func() string { - return setting.AppURL + return conf.Server.ExternalURL }, "Year": func() int { return time.Now().Year() @@ -59,7 +59,7 @@ func render(tpl string, data map[string]interface{}) (string, error) { }, }}, } - if !setting.LoadAssetsFromDisk { + if !conf.Server.LoadAssetsFromDisk { opt.TemplateFileSystem = templates.NewTemplateFileSystem("mail", opt.AppendDirectories[0]) } @@ -105,8 +105,8 @@ type Issue interface { func SendUserMail(c *macaron.Context, u User, tpl, code, subject, info string) { data := map[string]interface{}{ "Username": u.DisplayName(), - "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, - "ResetPwdCodeLives": setting.Service.ResetPwdCodeLives / 60, + "ActiveCodeLives": conf.Service.ActiveCodeLives / 60, + "ResetPwdCodeLives": conf.Service.ResetPwdCodeLives / 60, "Code": code, } body, err := render(tpl, data) @@ -133,7 +133,7 @@ func SendResetPasswordMail(c *macaron.Context, u User) { func SendActivateEmailMail(c *macaron.Context, u User, email string) { data := map[string]interface{}{ "Username": u.DisplayName(), - "ActiveCodeLives": setting.Service.ActiveCodeLives / 60, + "ActiveCodeLives": conf.Service.ActiveCodeLives / 60, "Code": u.GenerateEmailActivateCode(email), "Email": email, } @@ -204,7 +204,7 @@ func composeIssueMessage(issue Issue, repo Repository, doer User, tplName string if err != nil { log.Error("HTMLString (%s): %v", tplName, err) } - from := gomail.NewMessage().FormatAddress(setting.MailService.FromEmail, doer.DisplayName()) + from := gomail.NewMessage().FormatAddress(conf.MailService.FromEmail, doer.DisplayName()) msg := NewMessageFrom(tos, from, subject, content) msg.Info = fmt.Sprintf("Subject: %s, %s", subject, info) return msg diff --git a/internal/mailer/mailer.go b/internal/mailer/mailer.go index 40b2b5a8..8a54bd41 100644 --- a/internal/mailer/mailer.go +++ b/internal/mailer/mailer.go @@ -18,7 +18,7 @@ import ( "gopkg.in/gomail.v2" log "unknwon.dev/clog/v2" - "gogs.io/gogs/internal/setting" + "gogs.io/gogs/internal/conf" ) type Message struct { @@ -34,13 +34,13 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message { msg := gomail.NewMessage() msg.SetHeader("From", from) msg.SetHeader("To", to...) - msg.SetHeader("Subject", setting.MailService.SubjectPrefix+subject) + msg.SetHeader("Subject", conf.MailService.SubjectPrefix+subject) msg.SetDateHeader("Date", time.Now()) contentType := "text/html" body := htmlBody switchedToPlaintext := false - if setting.MailService.UsePlainText || setting.MailService.AddPlainTextAlt { + if conf.MailService.UsePlainText || conf.MailService.AddPlainTextAlt { plainBody, err := html2text.FromString(htmlBody) if err != nil { log.Error("html2text.FromString: %v", err) @@ -51,7 +51,7 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message { } } msg.SetBody(contentType, body) - if switchedToPlaintext && setting.MailService.AddPlainTextAlt && !setting.MailService.UsePlainText { + if switchedToPlaintext && conf.MailService.AddPlainTextAlt && !conf.MailService.UsePlainText { // The AddAlternative method name is confusing - adding html as an "alternative" will actually cause mail // clients to show it as first priority, and the text "main body" is the 2nd priority fallback. // See: https://godoc.org/gopkg.in/gomail.v2#Message.AddAlternative @@ -65,7 +65,7 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message { // NewMessage creates new mail message object with default From header. func NewMessage(to []string, subject, body string) *Message { - return NewMessageFrom(to, setting.MailService.From, subject, body) + return NewMessageFrom(to, conf.MailService.From, subject, body) } type loginAuth struct { @@ -99,7 +99,7 @@ type Sender struct { } func (s *Sender) Send(from string, to []string, msg io.WriterTo) error { - opts := setting.MailService + opts := conf.MailService host, port, err := net.SplitHostPort(opts.Host) if err != nil { @@ -225,11 +225,11 @@ func NewContext() { // Need to check if mailQueue is nil because in during reinstall (user had installed // before but swithed install lock off), this function will be called again // while mail queue is already processing tasks, and produces a race condition. - if setting.MailService == nil || mailQueue != nil { + if conf.MailService == nil || mailQueue != nil { return } - mailQueue = make(chan *Message, setting.MailService.QueueLength) + mailQueue = make(chan *Message, conf.MailService.QueueLength) go processMailQueue() } @@ -239,7 +239,7 @@ func NewContext() { func Send(msg *Message) { mailQueue <- msg - if setting.HookMode { + if conf.HookMode { <-msg.confirmChan return } |