This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: blmayer (bleemayer@gmail.com)
Date: Tue Oct 3 20:38:57 2023 -0300
Parent: 6e3d4ea
Added buffer to read hook output
diff --git a/cmd/dovel/backend.go b/cmd/dovel/backend.go
index a26e561..d4fbe63 100644
--- a/cmd/dovel/backend.go
+++ b/cmd/dovel/backend.go
@@ -93,7 +93,7 @@ func (s *Session) Data(raw io.Reader) error {
}
// running handlers is optional
- h := path.Join(configPath, "hooks", "send-" + cfg.Domain)
+ h := path.Join(configPath, "hooks", "send-"+cfg.Domain)
if f, err := os.Lstat(h); err == nil {
if !f.Mode().IsRegular() {
h, err = os.Readlink(h)
@@ -105,9 +105,10 @@ func (s *Session) Data(raw io.Reader) error {
c := exec.Command(h)
c.Dir = path.Join(configPath, "hooks")
c.Stdin = strings.NewReader(string(mess))
- c.Stdout = os.Stdout
+ out := bytes.Buffer{}
+ c.Stdout = &out
if err := c.Run(); err != nil {
- slog.Error("run script", err.Error())
+ slog.Error("run script", "error", err.Error(), "output", out.String())
return err
}
}
@@ -117,7 +118,7 @@ func (s *Session) Data(raw io.Reader) error {
for _, to := range tos {
domain := strings.Split(to.Address, "@")[1]
- h := path.Join(configPath, "hooks", "receive-" + domain)
+ h := path.Join(configPath, "hooks", "receive-"+domain)
if f, err := os.Lstat(h); err != nil {
slog.Error("lstat error", "domain", domain, "error", err.Error())
continue
@@ -131,8 +132,10 @@ func (s *Session) Data(raw io.Reader) error {
c := exec.Command(h)
c.Dir = path.Join(configPath, "hooks")
c.Stdin = strings.NewReader(string(mess))
- c.Stdout = os.Stdout
+ out := bytes.Buffer{}
+ c.Stdout = &out
if err := c.Run(); err != nil {
+ slog.Error("run script", "error", err.Error(), "output", out.String())
slog.Error("run script", err.Error())
continue
}