mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
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.
This commit is contained in:
@@ -56,29 +56,12 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
cmd := exec.CommandContext(ctx, p.Binary, args...)
|
cmd := exec.CommandContext(ctx, p.Binary, args...)
|
||||||
|
|
||||||
cmdStdin, err := cmd.StdinPipe()
|
cmd.Stdin = bytes.NewReader(data)
|
||||||
if err != nil {
|
|
||||||
return tr.Errorf("StdinPipe: %v", err), true
|
|
||||||
}
|
|
||||||
|
|
||||||
output := &bytes.Buffer{}
|
output := &bytes.Buffer{}
|
||||||
cmd.Stdout = output
|
cmd.Stdout = output
|
||||||
cmd.Stderr = output
|
cmd.Stderr = output
|
||||||
|
|
||||||
err = cmd.Start()
|
err := cmd.Run()
|
||||||
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()
|
|
||||||
|
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
return tr.Error(errTimeout), false
|
return tr.Error(errTimeout), false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user