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: Address and ParseAddress are not symmetric with parentheses #13966

Closed
chowey opened this issue Jan 15, 2016 · 2 comments
Closed

net/mail: Address and ParseAddress are not symmetric with parentheses #13966

chowey opened this issue Jan 15, 2016 · 2 comments

Comments

@chowey
Copy link

@chowey chowey commented Jan 15, 2016

In the net/mail package, Address is used to generate a valid RFC 5322 address. ParseAddress is used to parse a single RFC 5322 address.

There is currently a bug if the address name contains parentheses.

The following code fails to run:

package main

import "fmt"
import "net/mail"

func main() {

    tests := []*mail.Address{
        {Name: "Robert Müller", Address: "bob@example.com"},
        {Name: "Robert (Bob) Müller", Address: "bob@example.com"},
    }

    for i, in := range tests {
        fmt.Printf("\nTest %d\n", i)

        // straight encoding, will use q-encoding if needed
        fmt.Printf("In:  %s\n", in)

        // decode the q-encoding
        out, err := mail.ParseAddress(in.String())
        if err != nil {
            // oops! cannot parse our own address?
            panic(err)
        }

        // should match our earlier q-encoding
        fmt.Printf("Out: %s\n", out)
    }
}

Expected output:

Test 0
In:  =?utf-8?q?Robert_M=C3=BCller?= <bob@example.com>
Out: =?utf-8?q?Robert_M=C3=BCller?= <bob@example.com>

Test 1
In:  =?utf-8?q?Robert_(Bob)_M=C3=BCller?= <bob@example.com>
Out: =?utf-8?q?Robert_(Bob)_M=C3=BCller?= <bob@example.com>

Actual output:

Test 0
In:  =?utf-8?q?Robert_M=C3=BCller?= <bob@example.com>
Out: =?utf-8?q?Robert_M=C3=BCller?= <bob@example.com>

Test 1
In:  =?utf-8?q?Robert_(Bob)_M=C3=BCller?= <bob@example.com>
panic: mail: no angle-addr

goroutine 1 [running]:
main.main()

See it in action here.

These functions should be symmetric if I correctly understand the documentation.

@alexcesaro
Copy link
Contributor

@alexcesaro alexcesaro commented Jan 15, 2016

This is a duplicate of #11292 and it has already been fixed in Go1.6.

You can already use Go1.6beta2 where this bug is fixed if you want: https://groups.google.com/forum/#!topic/golang-nuts/DUwMjOWLA6s

@chowey
Copy link
Author

@chowey chowey commented Jan 15, 2016

Great to hear! Thank you very much.

@chowey chowey closed this Jan 15, 2016
@golang golang locked and limited conversation to collaborators Jan 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.