From b0cc815189b7247d2fabd16c557bdfa4acf1e5d7 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Sun, 17 Oct 2021 16:19:13 +0200 Subject: [PATCH] add noop email sender --- internal/email/noop.go | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 internal/email/noop.go diff --git a/internal/email/noop.go b/internal/email/noop.go new file mode 100644 index 000000000..e80c078a4 --- /dev/null +++ b/internal/email/noop.go @@ -0,0 +1,57 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package email + +// NewNoopSender returns a no-op email sender that will just execute the given sendCallback +// every time it would otherwise send an email. +// +// The 'data' parameter in the callback will be either a ConfirmData or a ResetData struct. +// +// Passing a nil function is also acceptable, in which case the send functions will just return nil. +func NewNoopSender(sendCallback func (toAddress string, data interface{})) Sender { + return &noopSender{ + sendCallback: sendCallback, + } +} + +type noopSender struct { + sendCallback func (toAddress string, data interface{}) +} + +func (s *noopSender) SendConfirmEmail(toAddress string, data ConfirmData) error { + if s.sendCallback != nil { + s.sendCallback(toAddress, data) + } + return nil +} + +func (s *noopSender) SendResetEmail(toAddress string, data ResetData) error { + if s.sendCallback != nil { + s.sendCallback(toAddress, data) + } + return nil +} + +func (s *noopSender) ExecuteTemplate(templateName string, data interface{}) (string, error) { + return "", nil +} + +func (s *noopSender) AssembleMessage(mailSubject string, mailBody string, mailTo string) []byte { + return []byte{} +}