Franciszek Stachura, Sep 12, 2026 at 23:06:
> 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`

pkg/config/config.go:61:2: structtag: struct field tag `help:"Do not send 
email." default:false` not compatible with reflect.StructTag.Get: bad syntax 
for struct tag value (govet)
        Disabled   bool   `help:"Do not send email." default:false`
        ^


Struct tags values must always be quoted:

        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)


-- 
Robin

# To order, call toll-free.
_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork

Reply via email to