]> Cypherpunks repositories - gostls13.git/commitdiff
net/mail: propagate unsupported charset error
authorDavid Crawshaw <david.crawshaw@zentus.com>
Wed, 7 May 2014 09:58:36 +0000 (05:58 -0400)
committerDavid Crawshaw <david.crawshaw@zentus.com>
Wed, 7 May 2014 09:58:36 +0000 (05:58 -0400)
Fixes #6807.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/95060043

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

index 4b332c1b5be6e8ffd2cf95e1eaf1246f341f9ee8..ba0778caa73af448b960f71557b239f9f2debfd4 100644 (file)
@@ -363,7 +363,7 @@ func (p *addrParser) consumePhrase() (phrase string, err error) {
        // Ignore any error if we got at least one word.
        if err != nil && len(words) == 0 {
                debug.Printf("consumePhrase: hit err: %v", err)
-               return "", errors.New("mail: missing word in phrase")
+               return "", fmt.Errorf("mail: missing word in phrase: %v", err)
        }
        phrase = strings.Join(words, " ")
        return phrase, nil
@@ -442,11 +442,11 @@ func (p *addrParser) len() int {
 func decodeRFC2047Word(s string) (string, error) {
        fields := strings.Split(s, "?")
        if len(fields) != 5 || fields[0] != "=" || fields[4] != "=" {
-               return "", errors.New("mail: address not RFC 2047 encoded")
+               return "", errors.New("address not RFC 2047 encoded")
        }
        charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2])
        if charset != "iso-8859-1" && charset != "utf-8" {
-               return "", fmt.Errorf("mail: charset not supported: %q", charset)
+               return "", fmt.Errorf("charset not supported: %q", charset)
        }
 
        in := bytes.NewBufferString(fields[3])
@@ -457,7 +457,7 @@ func decodeRFC2047Word(s string) (string, error) {
        case "q":
                r = qDecoder{r: in}
        default:
-               return "", fmt.Errorf("mail: RFC 2047 encoding not supported: %q", enc)
+               return "", fmt.Errorf("RFC 2047 encoding not supported: %q", enc)
        }
 
        dec, err := ioutil.ReadAll(r)
index 1bb4e8bc40137e6c72d9049b03d7b55c1014ea04..eb9c8cbdc9b61ccc09aabea0d7b2586c50067a4c 100644 (file)
@@ -8,6 +8,7 @@ import (
        "bytes"
        "io/ioutil"
        "reflect"
+       "strings"
        "testing"
        "time"
 )
@@ -116,6 +117,14 @@ func TestDateParsing(t *testing.T) {
        }
 }
 
+func TestAddressParsingError(t *testing.T) {
+       const txt = "=?iso-8859-2?Q?Bogl=E1rka_Tak=E1cs?= <unknown@gmail.com>"
+       _, err := ParseAddress(txt)
+       if err == nil || !strings.Contains(err.Error(), "charset not supported") {
+               t.Errorf(`mail.ParseAddress(%q) err: %q, want ".*charset not supported.*"`, txt, err)
+       }
+}
+
 func TestAddressParsing(t *testing.T) {
        tests := []struct {
                addrsStr string