mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-25 20:25:55 +00:00
courier: Let the users configure the mail delivery agent
This patch adds configuration options for the MDA binary and command line arguments, and changes the (soon to be renamed) procmail courier to make use of them.
This commit is contained in:
@@ -14,8 +14,10 @@ import (
|
||||
var (
|
||||
// Location of the procmail binary, and arguments to use.
|
||||
// The string "%user%" will be replaced with the local user.
|
||||
procmailBin = "procmail"
|
||||
procmailArgs = []string{"-d", "%user%"}
|
||||
// TODO: Make these a part of the courier instance itself? Why do they
|
||||
// have to be global?
|
||||
MailDeliveryAgentBin = "procmail"
|
||||
MailDeliveryAgentArgs = []string{"-d", "%user%"}
|
||||
|
||||
// Give procmail 1m to deliver mail.
|
||||
procmailTimeout = 1 * time.Minute
|
||||
@@ -39,10 +41,10 @@ func (p *Procmail) Deliver(from string, to string, data []byte) error {
|
||||
|
||||
// Prepare the command, replacing the necessary arguments.
|
||||
args := []string{}
|
||||
for _, a := range procmailArgs {
|
||||
for _, a := range MailDeliveryAgentArgs {
|
||||
args = append(args, strings.Replace(a, "%user%", user, -1))
|
||||
}
|
||||
cmd := exec.Command(procmailBin, args...)
|
||||
cmd := exec.Command(MailDeliveryAgentBin, args...)
|
||||
|
||||
cmdStdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
|
||||
@@ -15,8 +15,8 @@ func TestProcmail(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
procmailBin = "tee"
|
||||
procmailArgs = []string{dir + "/%user%"}
|
||||
MailDeliveryAgentBin = "tee"
|
||||
MailDeliveryAgentArgs = []string{dir + "/%user%"}
|
||||
|
||||
p := Procmail{}
|
||||
err = p.Deliver("from@x", "to@y", []byte("data"))
|
||||
@@ -31,8 +31,8 @@ func TestProcmail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestProcmailTimeout(t *testing.T) {
|
||||
procmailBin = "/bin/sleep"
|
||||
procmailArgs = []string{"1"}
|
||||
MailDeliveryAgentBin = "/bin/sleep"
|
||||
MailDeliveryAgentArgs = []string{"1"}
|
||||
procmailTimeout = 100 * time.Millisecond
|
||||
|
||||
p := Procmail{}
|
||||
@@ -48,19 +48,21 @@ func TestProcmailBadCommandLine(t *testing.T) {
|
||||
p := Procmail{}
|
||||
|
||||
// Non-existent binary.
|
||||
procmailBin = "thisdoesnotexist"
|
||||
MailDeliveryAgentBin = "thisdoesnotexist"
|
||||
err := p.Deliver("from", "to", []byte("data"))
|
||||
if err == nil {
|
||||
t.Errorf("Unexpected success: %q %v", procmailBin, procmailArgs)
|
||||
t.Errorf("Unexpected success: %q %v",
|
||||
MailDeliveryAgentBin, MailDeliveryAgentArgs)
|
||||
}
|
||||
|
||||
// Incorrect arguments.
|
||||
procmailBin = "cat"
|
||||
procmailArgs = []string{"--fail_unknown_option"}
|
||||
MailDeliveryAgentBin = "cat"
|
||||
MailDeliveryAgentArgs = []string{"--fail_unknown_option"}
|
||||
|
||||
err = p.Deliver("from", "to", []byte("data"))
|
||||
if err == nil {
|
||||
t.Errorf("Unexpected success: %q %v", procmailBin, procmailArgs)
|
||||
t.Errorf("Unexpected success: %q %v",
|
||||
MailDeliveryAgentBin, MailDeliveryAgentArgs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user