From 6ddaf205add421609ab82777d9d45da8b09ceb46 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Tue, 24 Oct 2017 11:10:19 +0200 Subject: dashboard/app: email fixes 1. Allows sending emails upstream. 2. Filter out duplicate emails coming from our mailing lists. 3. Increase retry attempts for email commands (don't want them to fail due to concurrent crash reports from managers). --- pkg/email/parser.go | 15 +++++++++++++++ pkg/email/parser_test.go | 13 +++++++++++++ 2 files changed, 28 insertions(+) (limited to 'pkg') diff --git a/pkg/email/parser.go b/pkg/email/parser.go index 56579157f..c000625b5 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -150,6 +150,21 @@ func RemoveAddrContext(email string) (string, string, error) { return addr.String(), context, nil } +func CanonicalEmail(email string) string { + addr, err := mail.ParseAddress(email) + if err != nil { + return email + } + at := strings.IndexByte(addr.Address, '@') + if at == -1 { + return email + } + if plus := strings.IndexByte(addr.Address[:at], '+'); plus != -1 { + addr.Address = addr.Address[:plus] + addr.Address[at:] + } + return strings.ToLower(addr.Address) +} + // extractCommand extracts command to syzbot from email body. // Commands are of the following form: // ^#syz cmd args... diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index 5156690d0..9c0a1ceec 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -76,6 +76,19 @@ func TestAddRemoveAddrContext(t *testing.T) { } } +func TestCanonicalEmail(t *testing.T) { + canonical := "foo@bar.com" + emails := []string{ + "\"Foo Bar\" ", + "", + } + for _, email := range emails { + if got := CanonicalEmail(email); got != canonical { + t.Errorf("got %q, want %q", got, canonical) + } + } +} + func TestParse(t *testing.T) { for i, test := range parseTests { body := func(t *testing.T, test ParseTest) { -- cgit mrf-deployment