1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

courier: Rename Procmail to MDA

This patch renames courier.Procmail to courier.MDA, to make it more
obvious that the functionality is not tied to that particular MDA.

It's just for readability, there are no functional changes.
This commit is contained in:
Alberto Bertogli
2020-09-17 02:45:48 +01:00
parent 1cc7b9a864
commit 025cb2d96a
4 changed files with 21 additions and 22 deletions

View File

@@ -159,7 +159,7 @@ func main() {
}
go stsCache.PeriodicallyRefresh(context.Background())
localC := &courier.Procmail{
localC := &courier.MDA{
Binary: conf.MailDeliveryAgentBin,
Args: conf.MailDeliveryAgentArgs,
Timeout: 30 * time.Second,

View File

@@ -18,12 +18,11 @@ var (
errTimeout = fmt.Errorf("operation timed out")
)
// Procmail delivers local mail by executing a local binary, like procmail or
// maildrop. It is named after procmail just for reference, it works with any
// binary that:
// MDA delivers local mail by executing a local binary, like procmail or
// maildrop. It works with any binary that:
// - Receives the email to deliver via stdin.
// - Exits with code EX_TEMPFAIL (75) for transient issues.
type Procmail struct {
type MDA struct {
Binary string // Path to the binary.
Args []string // Arguments to pass.
Timeout time.Duration // Timeout for each invocation.
@@ -31,13 +30,13 @@ type Procmail struct {
// Deliver an email. On failures, returns an error, and whether or not it is
// permanent.
func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
tr := trace.New("Courier.Procmail", to)
func (p *MDA) Deliver(from string, to string, data []byte) (error, bool) {
tr := trace.New("Courier.MDA", to)
defer tr.Finish()
// Sanitize, just in case.
from = sanitizeForProcmail(from)
to = sanitizeForProcmail(to)
from = sanitizeForMDA(from)
to = sanitizeForMDA(to)
tr.Debugf("%s -> %s", from, to)
@@ -78,7 +77,7 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
permanent = status.ExitStatus() != 75
}
}
err = tr.Errorf("procmail failed: %v - %q", err, string(output))
err = tr.Errorf("MDA delivery failed: %v - %q", err, string(output))
return err, permanent
}
@@ -86,12 +85,12 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
return nil, false
}
// sanitizeForProcmail cleans the string, removing characters that could be
// sanitizeForMDA cleans the string, removing characters that could be
// problematic considering we will run an external command.
//
// The server does not rely on this to do substitution or proper filtering,
// that's done at a different layer; this is just for defense in depth.
func sanitizeForProcmail(s string) string {
func sanitizeForMDA(s string) string {
valid := func(r rune) rune {
switch {
case unicode.IsSpace(r), unicode.IsControl(r),

View File

@@ -10,11 +10,11 @@ import (
"blitiri.com.ar/go/chasquid/internal/testlib"
)
func TestProcmail(t *testing.T) {
func TestMDA(t *testing.T) {
dir := testlib.MustTempDir(t)
defer testlib.RemoveIfOk(t, dir)
p := Procmail{
p := MDA{
Binary: "tee",
Args: []string{dir + "/%to_user%"},
Timeout: 1 * time.Minute,
@@ -31,8 +31,8 @@ func TestProcmail(t *testing.T) {
}
}
func TestProcmailTimeout(t *testing.T) {
p := Procmail{"/bin/sleep", []string{"1"}, 100 * time.Millisecond}
func TestMDATimeout(t *testing.T) {
p := MDA{"/bin/sleep", []string{"1"}, 100 * time.Millisecond}
err, permanent := p.Deliver("from", "to@local", []byte("data"))
if err != errTimeout {
@@ -43,9 +43,9 @@ func TestProcmailTimeout(t *testing.T) {
}
}
func TestProcmailBadCommandLine(t *testing.T) {
func TestMDABadCommandLine(t *testing.T) {
// Non-existent binary.
p := Procmail{"thisdoesnotexist", nil, 1 * time.Minute}
p := MDA{"thisdoesnotexist", nil, 1 * time.Minute}
err, permanent := p.Deliver("from", "to", []byte("data"))
if err == nil {
t.Errorf("unexpected success for non-existent binary")
@@ -55,7 +55,7 @@ func TestProcmailBadCommandLine(t *testing.T) {
}
// Incorrect arguments.
p = Procmail{"cat", []string{"--fail_unknown_option"}, 1 * time.Minute}
p = MDA{"cat", []string{"--fail_unknown_option"}, 1 * time.Minute}
err, _ = p.Deliver("from", "to", []byte("data"))
if err == nil {
t.Errorf("unexpected success for incorrect arguments")
@@ -82,7 +82,7 @@ func TestExitCode(t *testing.T) {
{"../../test/util/exitcode", []string{"75"}, false},
}
for _, c := range cases {
p := &Procmail{c.cmd, c.args, 5 * time.Second}
p := &MDA{c.cmd, c.args, 5 * time.Second}
err, permanent := p.Deliver("from", "to", []byte("data"))
if err == nil {
t.Errorf("%q: pipe delivery worked, expected failure", c.cmd)
@@ -116,7 +116,7 @@ func TestSanitize(t *testing.T) {
{"موزه‌ها", "موزه\u200cها"},
}
for _, c := range cases {
out := sanitizeForProcmail(c.v)
out := sanitizeForMDA(c.v)
if out != c.expected {
t.Errorf("%q: expected %q, got %q", c.v, c.expected, out)
}

View File

@@ -257,7 +257,7 @@ func init() {
s.AddAddr(submissionAddr, ModeSubmission)
s.AddAddr(submissionTLSAddr, ModeSubmissionTLS)
localC := &courier.Procmail{}
localC := &courier.MDA{}
remoteC := &courier.SMTP{}
s.InitQueue(tmpDir+"/queue", localC, remoteC)
s.InitDomainInfo(tmpDir + "/domaininfo")