From ebabe267cda9c25d5789f647339d237893eed10e Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 3 Jul 2017 18:24:39 +0200 Subject: pkg/email: don't add own email address to CC list Otherwise we we send each reply to ourselves and receive it again. --- pkg/email/parser.go | 20 ++++++++++++-------- pkg/email/parser_test.go | 12 ++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'pkg') diff --git a/pkg/email/parser.go b/pkg/email/parser.go index a764a5826..5d8c54d2c 100644 --- a/pkg/email/parser.go +++ b/pkg/email/parser.go @@ -50,10 +50,13 @@ func Parse(r io.Reader, ownEmail string) (*Email, error) { bugID := "" var ccList []string for _, addr := range append(cc, to...) { + bugID1, own := extractBugID(addr.Address, ownEmail) if bugID == "" { - bugID = extractBugID(addr.Address, ownEmail) + bugID = bugID1 + } + if !own { + ccList = append(ccList, addr.String()) } - ccList = append(ccList, addr.String()) } body, attachments, err := parseBody(msg.Body, msg.Header) if err != nil { @@ -89,25 +92,26 @@ func Parse(r io.Reader, ownEmail string) (*Email, error) { // from is potentially such email address, canonical is . // This function returns BUG_ID_HASH, or an empty string if from does not contain // the hash or is different from canonical. -func extractBugID(from, canonical string) string { +func extractBugID(from, canonical string) (string, bool) { if email, err := mail.ParseAddress(canonical); err == nil { canonical = email.Address } + canonical = strings.ToLower(canonical) plusPos := strings.IndexByte(from, '+') if plusPos == -1 { - return "" + return "", strings.ToLower(from) == canonical } atPos := strings.IndexByte(from[plusPos:], '@') if atPos == -1 { - return "" + return "", false } user := from[:plusPos] domain := from[plusPos+atPos:] hash := from[plusPos+1 : plusPos+atPos] - if strings.ToLower(user+domain) != strings.ToLower(canonical) { - return "" + if strings.ToLower(user+domain) != canonical { + return "", false } - return hash + return hash, true } // extractCommand extracts command to syzbot from email body. diff --git a/pkg/email/parser_test.go b/pkg/email/parser_test.go index 8d8e675e4..7b2aa9a0f 100644 --- a/pkg/email/parser_test.go +++ b/pkg/email/parser_test.go @@ -26,10 +26,10 @@ func TestExtractCommand(t *testing.T) { func TestExtractBugID(t *testing.T) { for i, test := range extractBugIDTests { t.Run(fmt.Sprint(i), func(t *testing.T) { - bugID := extractBugID(test.email, `"Foo Bar" `) - if bugID != test.bugID { - t.Logf("expect: %q", test.bugID) - t.Logf("got : %q", bugID) + bugID, own := extractBugID(test.email, `"Foo Bar" `) + if bugID != test.bugID || own != test.own { + t.Logf("expect: own=%v %q", test.own, test.bugID) + t.Logf("got : own=%v %q", test.own, bugID) t.Fail() } }) @@ -89,18 +89,22 @@ line 2 var extractBugIDTests = []struct { email string bugID string + own bool }{ { `foo@bar.com`, ``, + true, }, { `foo+123@baz.com`, ``, + false, }, { `foo+123@bar.com`, `123`, + true, }, } -- cgit mrf-deployment