pkg/email: don't add <> to email when name is empty

Just unnecessary clutter.
This commit is contained in:
Dmitry Vyukov 2017-12-28 08:51:39 +01:00
parent 7d240098d8
commit f9e22d6230
4 changed files with 29 additions and 7 deletions

View File

@ -57,7 +57,7 @@ Unfortunately, I don't have any reproducer for this bug yet.
CC: [bar@foo.com foo@bar.com]
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: <syzbot+%v@testapp.appspotmail.com>
Reported-by: syzbot+%v@testapp.appspotmail.com
It will help syzbot understand when the bug is fixed. See footer for details.
If you forward the report, please keep this part and the footer.
@ -155,7 +155,7 @@ for information about syzkaller reproducers
CC: [bar@foo.com foo@bar.com]
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: <syzbot+%v@testapp.appspotmail.com>
Reported-by: syzbot+%v@testapp.appspotmail.com
It will help syzbot understand when the bug is fixed.
report1
@ -204,7 +204,7 @@ for information about syzkaller reproducers
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: <syzbot+%v@testapp.appspotmail.com>
Reported-by: syzbot+%v@testapp.appspotmail.com
It will help syzbot understand when the bug is fixed. See footer for details.
If you forward the report, please keep this part and the footer.
@ -286,7 +286,7 @@ for information about syzkaller reproducers
IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: <syzbot+%v@testapp.appspotmail.com>
Reported-by: syzbot+%v@testapp.appspotmail.com
It will help syzbot understand when the bug is fixed.
report1

View File

@ -192,7 +192,7 @@ Kernel config is attached.
syzbot has tested the proposed patch and the reproducer did not trigger crash:
Reported-and-tested-by: <syzbot+%v@testapp.appspotmail.com>
Reported-and-tested-by: syzbot+%v@testapp.appspotmail.com
Note: the tag will also help syzbot to understand when the bug is fixed.

View File

@ -128,8 +128,12 @@ func AddAddrContext(email, context string) (string, error) {
if at == -1 {
return "", fmt.Errorf("failed to parse %q as email: no @", email)
}
addr.Address = addr.Address[:at] + "+" + context + addr.Address[at:]
return addr.String(), nil
result := addr.Address[:at] + "+" + context + addr.Address[at:]
if addr.Name != "" {
addr.Address = result
result = addr.String()
}
return result, nil
}
// RemoveAddrContext extracts context after '+' from the local part of the provided email address.

View File

@ -81,6 +81,24 @@ func TestAddRemoveAddrContext(t *testing.T) {
}
}
func TestAddAddrContextEmptyName(t *testing.T) {
email := "<foo@bar.com>"
email1, err := AddAddrContext(email, "context")
if err != nil {
t.Fatal(err)
}
if want := "foo+context@bar.com"; want != email1 {
t.Fatalf("want: %q, got %q", want, email1)
}
email2, context1, err := RemoveAddrContext(email1)
if email != email2 {
t.Fatalf("want: %q, got %q", email, email2)
}
if context1 != "context" {
t.Fatalf("got context %q", context1)
}
}
func TestCanonicalEmail(t *testing.T) {
canonical := "foo@bar.com"
emails := []string{