From ed01d6bc14307ca5e361417a6b68dfac94db8c6e Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Fri, 18 Jan 2019 14:47:21 -0500 Subject: [PATCH] notify-mailer: skip invalid contact emails (#4021) Resolves #4020 --- cmd/notify-mailer/main.go | 7 ++++++- cmd/notify-mailer/main_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/notify-mailer/main.go b/cmd/notify-mailer/main.go index aa969d54a..92e067a59 100644 --- a/cmd/notify-mailer/main.go +++ b/cmd/notify-mailer/main.go @@ -177,7 +177,12 @@ func (m *mailer) resolveDestinations() ([]string, error) { if strings.TrimSpace(email) == "" { continue } - contactsList = append(contactsList, email) + parsedEmail, err := mail.ParseAddress(email) + if err != nil { + m.log.Errf("unparseable email for reg ID %d : %q", c.ID, email) + continue + } + contactsList = append(contactsList, parsedEmail.Address) } } return contactsList, nil diff --git a/cmd/notify-mailer/main_test.go b/cmd/notify-mailer/main_test.go index 3b62469be..24e71de5c 100644 --- a/cmd/notify-mailer/main_test.go +++ b/cmd/notify-mailer/main_test.go @@ -338,6 +338,10 @@ func (bs mockEmailResolver) SelectOne(output interface{}, _ string, args ...inte ID: 6, Contact: []byte(`["mailto:mail@example.com"]`), }, + { + ID: 7, + Contact: []byte(`["mailto:***********"]`), + }, } // Play the type cast game so that we can dig into the arguments map and get @@ -391,6 +395,11 @@ func TestResolveEmails(t *testing.T) { { ID: 999, }, + // This registration ID deliberately returns an invalid email to make sure any + // invalid contact info that slipped into the DB once upon a time will be ignored + { + ID: 7, + }, } contactsJSON, err := json.Marshal(regs) test.AssertNotError(t, err, "failed to marshal test regs")