~netlandish/gobwebs

40ce16c71d3251d5a7023d4abdb7a32046d1f671 — Peter Sanchez 1 year, 11 months ago 66642b8
Adding MailChecker interface for email.ServiceQueue
3 files changed, 25 insertions(+), 2 deletions(-)

M email/email.go
M email/helper.go
M interfaces.go
M email/email.go => email/email.go +9 -2
@@ 22,6 22,7 @@ type ServiceQueue struct {
	logger  echo.Logger
	service carrier.Service
	queue   *work.Queue
	checker gobwebs.MailChecker
}

// Service returns the email service


@@ 34,6 35,11 @@ func (s *ServiceQueue) Queue() *work.Queue {
	return s.queue
}

// Checker returns the mail checker
func (s *ServiceQueue) Checker() gobwebs.MailChecker {
	return s.checker
}

// SendMail sends an email message
func (s *ServiceQueue) SendMail(msg *carrier.Message) error {
	if s.queue == nil {


@@ 66,8 72,9 @@ func (s *ServiceQueue) mailTask(msg *carrier.Message) *work.Task {
}

// NewServiceQueue returns a new ServiceQueue instance
func NewServiceQueue(logger echo.Logger, service carrier.Service, queue *work.Queue) *ServiceQueue {
	return &ServiceQueue{logger, service, queue}
func NewServiceQueue(logger echo.Logger, service carrier.Service,
	queue *work.Queue, checker gobwebs.MailChecker) *ServiceQueue {
	return &ServiceQueue{logger, service, queue, checker}
}

// NewQueue Creates a new email processing queue.

M email/helper.go => email/helper.go +9 -0
@@ 76,6 76,15 @@ func (h *Helper) Send(name, from, rcpt string, data gobwebs.Map) error {
		return fmt.Errorf("No email address given to send to")
	}

	checker := h.q.Checker()
	if err := checker.Check(rcpt); err != nil {
		// Email address check failed. Don't email
		// We don't want to return error here. The checker.Check function
		// should do all the individual use case logging and other work.
		// XXX Maybe re-think this `return nil` decision in the future
		return nil
	}

	var (
		htmlok              bool
		sname, tname, hname string

M interfaces.go => interfaces.go +7 -0
@@ 73,3 73,10 @@ type UserFetch interface {
	ChangePasswordTemplateVars(c echo.Context) Map
	UpdateEmailTemplateVars(c echo.Context) Map
}

// MailChecker is an interface that the email module uses to verify
// if a an email address is allowed to be sent email or not. Useful
// to track bounces, spam complaints, etc.
type MailChecker interface {
	Check(email string) error
}