Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/mail: misleading ParseAddress error message when german umlauts in display-name #12492

Closed
ulrichSchreiner opened this issue Sep 4, 2015 · 11 comments
Milestone

Comments

@ulrichSchreiner
Copy link

If the display-name part contains a german umlaut, the ParseAddress fails.

    s := "aä <aa.bb@cc.com>"
    m, e := mail.ParseAddress(s)
    if e != nil {
        panic(e)
    }
    fmt.Printf("%v\n",m)

panics with

panic: mail: no angle-addr

This happens very often with german adresses. If the display-name only contains umlauts like "ää öö <aa.bb@cc.com>" it panics with:

panic: mail: missing word in phrase: mail: invalid string
@stemar94
Copy link

stemar94 commented Sep 4, 2015

Take a look at #7079
ParseAddress parses according to RFC 5322, which only allows US-ASCII characters.
A possible workaround for you: Use the mail.AddressParser struct, to encode your umlauts, guess there should be some examples in the web.

@bradfitz bradfitz changed the title mail.ParseAddress fails when german umlauts in display-name net/mail: misleading ParseAddress error message when german umlauts in display-name Sep 4, 2015
@bradfitz bradfitz added this to the Go1.6 milestone Sep 4, 2015
@bradfitz
Copy link
Contributor

bradfitz commented Sep 4, 2015

Yes, only ASCII is allowed there. Perhaps we should return a more clear error message if we see any octet greater than 127 in the input.

@nightlyone
Copy link
Contributor

Ok, took a stab on better error message at https://go-review.googlesource.com/14312

Any feedback on the text would be great!

@gopherbot
Copy link

CL https://golang.org/cl/14312 mentions this issue.

@gobwas
Copy link

gobwas commented Sep 14, 2015

@ulrichSchreiner hi! Did you solved this issue? =)

@stemar94
Copy link

@gobwas take a look at my answer

@gobwas
Copy link

gobwas commented Sep 14, 2015

@stemar94 i saw your answer, thanks. There are no examples in the web. How could mail.AddressParser encode non ASCII chars? I think, by the spec, it should decode, not encode.

m := "Иван Иванов <ivanov@example.com>"
parser := mail.AddressParser{WordDecoder: &mime.WordDecoder{}}
encodedM := HowCouldIEncodeThisToRFC5322(m) // ?
parser.Parse(m)

@ulrichSchreiner
Copy link
Author

try this:

    s := "aä <aa.bb@cc.com>"
    se := mime.QEncoding.Encode("utf-8", s)

    m, e := mail.ParseAddress(se)
    if e != nil {
        panic(e)
    }
    fmt.Printf("%v\n",m.Address)
    fmt.Printf("%v\n",m.Name)
    dec := new(mime.WordDecoder)
    decname, err := dec.Decode(m.Name+"?=")
    if err != nil {
        panic(err)
    }
    fmt.Printf("%v\n",decname)

but only for names with illegal characters :-)

@gobwas
Copy link

gobwas commented Sep 14, 2015

@ulrichSchreiner your example just not panics, but m.Name is still encoded like:

fmt.Printf("%s %s", m.Name, m.Address) // => ivanov@example.com =?utf-8?q?=D0=98=D0=B2=D0=B0=D0=BD_=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?=

I mean, is it possible to parse without second part of your code? )

@ulrichSchreiner
Copy link
Author

if you want the name, you have to decode the name with the WordDecoder: http://play.golang.org/p/OzcpaQh9jj

@gobwas
Copy link

gobwas commented Sep 14, 2015

@ulrichSchreiner okay. I've got this. Thank you!

@golang golang locked and limited conversation to collaborators Dec 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants