Skip to content

Commit

Permalink
pkg/email: fix bug in context extraction
Browse files Browse the repository at this point in the history
Compare email addresses without full name.
  • Loading branch information
dvyukov committed Jul 5, 2017
1 parent 6fe1bcf commit f68d78b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/email/parser.go
Expand Up @@ -49,8 +49,14 @@ func Parse(r io.Reader, ownEmail string) (*Email, error) {
cc, _ := msg.Header.AddressList("Cc")
bugID := ""
var ccList []string
if addr, err := mail.ParseAddress(ownEmail); err == nil {
ownEmail = addr.Address
}
for _, addr := range append(cc, to...) {
cleaned, context, _ := RemoveAddrContext(addr.Address)
if addr, err := mail.ParseAddress(cleaned); err == nil {
cleaned = addr.Address
}
if cleaned == ownEmail {
if bugID == "" {
bugID = context
Expand Down
6 changes: 3 additions & 3 deletions pkg/email/parser_test.go
Expand Up @@ -78,7 +78,7 @@ func TestAddRemoveAddrContext(t *testing.T) {
func TestParse(t *testing.T) {
for i, test := range parseTests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
email, err := Parse(strings.NewReader(test.email), "")
email, err := Parse(strings.NewReader(test.email), "bot <foo@bar.com>")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -133,18 +133,18 @@ var parseTests = []struct {
Message-ID: <123>
Subject: test subject
From: Bob <bob@example.com>
To: syzbot <bot@example.com>
To: syzbot <foo+4564456@bar.com>
Content-Type: text/plain; charset="UTF-8"
text body
second line
#syzbot command arg1 arg2 arg3
last line`,
&Email{
BugID: "4564456",
MessageID: "<123>",
Subject: "test subject",
From: "\"Bob\" <bob@example.com>",
Cc: []string{"\"syzbot\" <bot@example.com>"},
Body: `text body
second line
#syzbot command arg1 arg2 arg3
Expand Down

0 comments on commit f68d78b

Please sign in to comment.