]> Cypherpunks repositories - gostls13.git/commitdiff
net/mail: skip empty entries in parseAddressList
authorTimmy Douglas <timmyd983@gmail.com>
Sat, 1 Feb 2020 22:14:30 +0000 (22:14 +0000)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 21 Feb 2020 18:18:25 +0000 (18:18 +0000)
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 #36959

Change-Id: I3ca240969935067262e3d751d376a06db1fef2a2
GitHub-Last-Rev: b96a9f2c075dfd67c3ff7b8ae0c12e12035f0da0
GitHub-Pull-Request: golang/go#36966
Reviewed-on: https://go-review.googlesource.com/c/go/+/217377
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
src/net/mail/message.go
src/net/mail/message_test.go

index 0781310ed3fc0e721cb0865c511f355da47a7d2c..6833cfaec11c1803dda89b5a8a68663cd9816764 100644 (file)
@@ -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(',') {
+                       continue
+               }
+               if p.empty() {
+                       break
+               }
+
                addrs, err := p.parseAddress(true)
                if err != nil {
                        return nil, err
index acab538e18b6f4f4b4174620a5f628e2c2359611..75db767547334b9179a93790a2aeff859e0b73f5 100644 (file)
@@ -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{