Sending emails during development and testing of Patchwork is not always
necessary. Add a short-circuit to SMTP that gives extra assurance that
no emails will be sent.

Signed-off-by: Franciszek Stachura <[email protected]>
---
 pkg/config/config.go | 1 +
 pkg/events/email.go  | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/pkg/config/config.go b/pkg/config/config.go
index 0a86496..e6e1f99 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -58,6 +58,7 @@ type SMTPConfig struct {
        User       string `help:"SMTP authentication username."`
        Password   string `help:"SMTP authentication password."`
        From       string `help:"Sender email address for outgoing mail." 
default:"patchwork@localhost"`
+       Disabled   bool   `help:"Do not send email." default:false`
 }
 
 const commonDescription = `
diff --git a/pkg/events/email.go b/pkg/events/email.go
index 64acdd3..32b7f4f 100644
--- a/pkg/events/email.go
+++ b/pkg/events/email.go
@@ -20,6 +20,11 @@ import (
 )
 
 func SendEmail(cfg *config.SMTPConfig, to, subject, body string, extraHeaders 
map[string]string) error {
+       if cfg.Disabled {
+               log.Infof("sending emails is disabled, attempted to send: to=%s 
subject=%q", to, subject)
+               return nil
+       }
+
        from, err := mail.ParseAddress(cfg.From)
        if err != nil {
                return fmt.Errorf("from: %q %w", from, err)
-- 
2.55.0

_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to