Skip to content

Commit

Permalink
net/mail: skip empty entries in parseAddressList
Browse files Browse the repository at this point in the history
RFC 5322 has a section 4.4 where it says that address-list could
have "null" members: "That is, there could be two or more commas in
such a list with nothing in between them, or commas at the beginning
or end of the list." This change handles such a case so that mail
clients using this method on actual email messages get a reasonable
return value when they parse email.

Fixes golang#36959
  • Loading branch information
Timmy Douglas committed Feb 1, 2020
1 parent 866920a commit 4f04c6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/net/mail/message.go
Expand Up @@ -274,6 +274,15 @@ func (p *addrParser) parseAddressList() ([]*Address, error) {
var list []*Address
for {
p.skipSpace()

// allow skipping empty entries (RFC5322 obs-addr-list)
if p.consume(',') {
p.skipSpace()
}
if p.empty() {
break
}

addrs, err := p.parseAddress(true)
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions src/net/mail/message_test.go
Expand Up @@ -431,6 +431,20 @@ func TestAddressParsing(t *testing.T) {
},
},
},
// RFC5322 4.4 obs-addr-list
{
` , joe@where.test,,John <jdoe@one.test>,`,
[]*Address{
{
Name: "",
Address: "joe@where.test",
},
{
Name: "John",
Address: "jdoe@one.test",
},
},
},
{
`Group1: <addr1@example.com>;, Group 2: addr2@example.com;, John <addr3@example.com>`,
[]*Address{
Expand Down

0 comments on commit 4f04c6a

Please sign in to comment.