Skip to content

Commit

Permalink
Add support for extra sendmail arguments (#2731)
Browse files Browse the repository at this point in the history
* Add support for extra sendmail arguments

* Sendmail args to exec.command should be a list

* Add go-shellquote package

* Use go-shellquote lib for parsing Sendmail args

* Only parse if sendmail is configured
  • Loading branch information
cez81 authored and lafriks committed Oct 25, 2017
1 parent 3af5b67 commit e86a0bf
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ SEND_AS_PLAIN_TEXT = false
USE_SENDMAIL = false
; Specify an alternative sendmail binary
SENDMAIL_PATH = sendmail
; Specify any extra sendmail arguments
SENDMAIL_ARGS =

[cache]
; Either "memory", "redis", or "memcache", default is "memory"
Expand Down
1 change: 1 addition & 0 deletions modules/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
var waitError error

args := []string{"-F", from, "-i"}
args = append(args, setting.MailService.SendmailArgs...)
args = append(args, to...)
log.Trace("Sending with: %s %v", setting.MailService.SendmailPath, args)
cmd := exec.Command(setting.MailService.SendmailPath, args...)
Expand Down
9 changes: 9 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/go-macaron/session"
_ "github.com/go-macaron/session/redis" // redis plugin for store session
"github.com/go-xorm/core"
"github.com/kballard/go-shellquote"
"gopkg.in/ini.v1"
"strk.kbt.io/projects/go/libravatar"
)
Expand Down Expand Up @@ -1326,6 +1327,7 @@ type Mailer struct {
// Sendmail sender
UseSendmail bool
SendmailPath string
SendmailArgs []string
}

var (
Expand Down Expand Up @@ -1372,6 +1374,13 @@ func newMailService() {
MailService.FromName = parsed.Name
MailService.FromEmail = parsed.Address

if MailService.UseSendmail {
MailService.SendmailArgs, err = shellquote.Split(sec.Key("SENDMAIL_ARGS").String())
if err != nil {
log.Error(4, "Failed to parse Sendmail args: %v", CustomConf, err)
}
}

log.Info("Mail Service Enabled")
}

Expand Down
19 changes: 19 additions & 0 deletions vendor/github.com/kballard/go-shellquote/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/kballard/go-shellquote/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/kballard/go-shellquote/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions vendor/github.com/kballard/go-shellquote/quote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

144 changes: 144 additions & 0 deletions vendor/github.com/kballard/go-shellquote/unquote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,12 @@
"revision": "b2c7a7da5b2995941048f60146e67702a292e468",
"revisionTime": "2016-02-12T04:00:40Z"
},
{
"checksumSHA1": "+IzngblnBQNh+GmsS2O7jqmzSVQ=",
"path": "github.com/kballard/go-shellquote",
"revision": "cd60e84ee657ff3dc51de0b4f55dd299a3e136f2",
"revisionTime": "2017-06-19T18:30:22Z"
},
{
"checksumSHA1": "VJk3rOWfxEV9Ilig5lgzH1qg8Ss=",
"path": "github.com/keybase/go-crypto/brainpool",
Expand Down

0 comments on commit e86a0bf

Please sign in to comment.