notify-mailer: skip invalid contact emails (#4021)

Resolves #4020
This commit is contained in:
Daniel McCarney 2019-01-18 14:47:21 -05:00 committed by Jacob Hoffman-Andrews
parent 92e8e1708a
commit ed01d6bc14
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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")