Skip to content

Commit

Permalink
Sendmail : revert string filtering and pass optional parameters instead
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Apr 19, 2021
1 parent 969516f commit ac60f68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
15 changes: 2 additions & 13 deletions broker/mailer/gomail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,12 @@ package mailer

import (
"fmt"
"regexp"

"gopkg.in/gomail.v2"

"github.com/pydio/cells/common/proto/mailer"
)

var (
sendmailCheck *regexp.Regexp
semdmailReplace = ". "
)

func init() {
// Check for line containing just one dot, to avoid truncating sendmail input
sendmailCheck = regexp.MustCompile("(?m)^\\.$")
}

// NewGomailMessage prepares a new Message to be sent.
func NewGomailMessage(email *mailer.Mail) (*gomail.Message, error) {

Expand Down Expand Up @@ -75,9 +64,9 @@ func NewGomailMessage(email *mailer.Mail) (*gomail.Message, error) {
m.SetHeader("Subject", email.Subject)

if len(email.ContentHtml) > 0 {
m.SetBody("text/html", sendmailCheck.ReplaceAllString(email.ContentHtml, semdmailReplace))
m.SetBody("text/html", email.ContentHtml)
} else {
m.SetBody("text/plain", sendmailCheck.ReplaceAllString(email.ContentPlain, semdmailReplace))
m.SetBody("text/plain", email.ContentPlain)
}
for _, a := range email.Attachments {
m.Attach(a)
Expand Down
16 changes: 11 additions & 5 deletions broker/mailer/sender-sendmail.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,26 @@ import (
"os/exec"
"regexp"

"github.com/pydio/cells/common/log"
"github.com/pydio/cells/x/filex"

"github.com/pkg/errors"

"github.com/pydio/cells/common/log"
"github.com/pydio/cells/common/proto/mailer"
"github.com/pydio/cells/x/configx"
"github.com/pydio/cells/x/filex"
)

type Sendmail struct {
BinPath string
BinPath string
BinParams []string
}

func (s *Sendmail) Configure(ctx context.Context, conf configx.Values) error {
s.BinPath = conf.Val("#/defaults/sendmail").Default("/usr/bin/sendmail").String()
log.Logger(ctx).Info("Configuring sendmail with binary path: " + s.BinPath)
params := conf.Val("#/defaults/sendmailParams").StringArray()
if len(params) > 0 {
s.BinParams = params
}
return nil
}

Expand Down Expand Up @@ -80,7 +84,9 @@ func (d *Sendmail) Send(email *mailer.Mail) error {
toStr = "\"" + toStr + "\""

// Call the system command
cmd := exec.Command(d.BinPath, "-t", toStr)
params := d.BinParams
params = append(params, "-t", toStr)
cmd := exec.Command(d.BinPath, params...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

Expand Down

0 comments on commit ac60f68

Please sign in to comment.