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: ParseAddress fails if the name part contains round parentheses #16692

Closed
zephyr opened this issue Aug 14, 2016 · 2 comments
Closed

Comments

@zephyr
Copy link

zephyr commented Aug 14, 2016

I'm using

go version devel +31ad583 2016-08-10 19:44:08 +0000 linux/amd64

I tried to parse all email adresses from the git log output of https://github.com/golang/go.

mail.ParseAddress choked on five adresses. Two times it was legitimate; but three of them failed to parse just because they contain round parentheses in the name part.

Here is a minimal example:

package main

import (
    "fmt"
    "log"
    "net/mail"
)

func main() {
    s := "Hyang-Ah (Hana) Kim <hyangah@gmail.com>"
    a, err := mail.ParseAddress(s)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(a)
}

I expected to see

"Hyang-Ah (Hana) Kim" <hyangah@gmail.com>

but instead i see

2016/08/14 21:28:50 mail: no angle-addr

Even if name aren’t allowed to contain round parentheses, the error message is confusing, because there clearly are square/angle bracket with an email adress between.

@hirochachacha
Copy link
Contributor

I think that address format is illegal.
You can use git log --pretty=format:'"%an" %aE' to get a legal address.

I agree that error message is poor, though.

Maybe,

2016/08/14 21:28:50 mail: expected angle-addr, got '('

is better?

@zephyr
Copy link
Author

zephyr commented Aug 15, 2016

Thank you very much, this solves my issue!

And I totally agree that you version of the error message would be clearer.

@zephyr zephyr closed this as completed Aug 15, 2016
@golang golang locked and limited conversation to collaborators Aug 15, 2017
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

3 participants