pkg/email: fix bug in context extraction

Compare email addresses without full name.
This commit is contained in:
Dmitry Vyukov 2017-07-05 21:29:41 +02:00
parent 6fe1bcf384
commit f68d78b5a8
2 changed files with 9 additions and 3 deletions

View File

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

View File

@ -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)
}
@ -133,7 +133,7 @@ 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
@ -141,10 +141,10 @@ 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