]> Cypherpunks repositories - gostls13.git/commitdiff
mail: decode RFC 2047-encoded words, not phrases.
authorDavid Symonds <dsymonds@golang.org>
Thu, 9 Jun 2011 22:47:27 +0000 (08:47 +1000)
committerDavid Symonds <dsymonds@golang.org>
Thu, 9 Jun 2011 22:47:27 +0000 (08:47 +1000)
R=rsc, r, bradfitz
CC=golang-dev
https://golang.org/cl/4590047

src/pkg/mail/message.go
src/pkg/mail/message_test.go

index ca818ebde40bfb6e4ba543f0a3d9b5847b1a2e1f..754b779bede38c72b1af761955045d84659e1026 100644 (file)
@@ -330,6 +330,12 @@ func (p *addrParser) consumePhrase() (phrase string, err os.Error) {
                        // atom
                        word, err = p.consumeAtom(false)
                }
+
+               // RFC 2047 encoded-word starts with =?, ends with ?=, and has two other ?s.
+               if err == nil && strings.HasPrefix(word, "=?") && strings.HasSuffix(word, "?=") && strings.Count(word, "?") == 4 {
+                       word, err = decodeRFC2047Word(word)
+               }
+
                if err != nil {
                        break
                }
@@ -342,11 +348,6 @@ func (p *addrParser) consumePhrase() (phrase string, err os.Error) {
                return "", os.ErrorString("mail: missing word in phrase")
        }
        phrase = strings.Join(words, " ")
-
-       // RFC 2047 encoded-word starts with =?, ends with ?=, and has two other ?s.
-       if strings.HasPrefix(phrase, "=?") && strings.HasSuffix(phrase, "?=") && strings.Count(phrase, "?") == 4 {
-               return decodeRFC2047Word(phrase)
-       }
        return phrase, nil
 }
 
index 92e9ef8de768f74ac6d676e27f7e22c4363e5352..1ff45d2c130cc3e6b32e3d3c63f615d71036a072 100644 (file)
@@ -207,6 +207,16 @@ func TestAddressParsing(t *testing.T) {
                                },
                        },
                },
+               // RFC 2047, Section 8.
+               {
+                       `=?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>`,
+                       []*Address{
+                               &Address{
+                                       Name:    `AndrĂ© Pirard`,
+                                       Address: "PIRARD@vm1.ulg.ac.be",
+                               },
+                       },
+               },
        }
        for _, test := range tests {
                addrs, err := newAddrParser(test.addrsStr).parseAddressList()