From 5faffbbfe333cb651e9d71aaafdbbc364180f023 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Thu, 13 Oct 2016 21:55:23 +0100 Subject: [PATCH] courier: Simplify procmail's execution logic The way the procmail courier runs the command is unnecessary convoluted, this patch simplifies it by using the corresponding standard tools. --- internal/courier/procmail.go | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/internal/courier/procmail.go b/internal/courier/procmail.go index a0d9188..d16ea53 100644 --- a/internal/courier/procmail.go +++ b/internal/courier/procmail.go @@ -56,29 +56,12 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) { defer cancel() cmd := exec.CommandContext(ctx, p.Binary, args...) - cmdStdin, err := cmd.StdinPipe() - if err != nil { - return tr.Errorf("StdinPipe: %v", err), true - } - + cmd.Stdin = bytes.NewReader(data) output := &bytes.Buffer{} cmd.Stdout = output cmd.Stderr = output - err = cmd.Start() - if err != nil { - return tr.Errorf("Error starting procmail: %v", err), true - } - - _, err = bytes.NewBuffer(data).WriteTo(cmdStdin) - if err != nil { - return tr.Errorf("Error sending data to procmail: %v", err), true - } - - cmdStdin.Close() - - err = cmd.Wait() - + err := cmd.Run() if ctx.Err() == context.DeadlineExceeded { return tr.Error(errTimeout), false }