diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-10-24 11:10:19 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-10-31 10:06:02 +0100 |
| commit | 6ddaf205add421609ab82777d9d45da8b09ceb46 (patch) | |
| tree | 9d4020eacb593195310cda6b42d6cce8921e99a3 /pkg | |
| parent | edfd374bd609e5f416ab9dce9d02f4645188c05f (diff) | |
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).
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/email/parser.go | 15 | ||||
| -rw-r--r-- | pkg/email/parser_test.go | 13 |
2 files changed, 28 insertions, 0 deletions
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\" <foo+123+456@Bar.com>", + "<Foo@bar.com>", + } + 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) { |
