<ol dir="auto">
<li>go version 1.4.2</li>
<li>Linux sanydellubuntu 3.19.0-30-generic <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="51275960" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/33" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/33/hovercard" href="https://github.com/golang/go/issues/33">#33</a>-Ubuntu SMP Mon Sep 21 20:58:04 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux</li>
<li>See my code below.</li>
<li>I expected mail.Address.String() can escape the comma for non-ASCII characters.</li>
<li>Comma is output without escape and cause error <em>mail: no angle-addr</em> during parsing.</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;log&quot;
    &quot;net/mail&quot;
)

func formatEmailAddress(emailaddress, name string) string {
    a := new(mail.Address)
    if &quot;&quot; == emailaddress {
        return &quot;&quot;
    }
    a.Address = emailaddress
    if &quot;&quot; != name {
        a.Name = name
    }
    return a.String()
}

func main() {
    s := formatEmailAddress(&quot;test.mail@gmail.com&quot;, &quot;naé, mée&quot;)
    log.Println(s)
    a, err := mail.ParseAddress(s)
    if nil != err {
        log.Println(&quot;error because:&quot;, err)
    } else {
        log.Println(&quot;name is:&quot;, a.Name, &quot;email is:&quot;, a.Address)
    }
}"><pre class="notranslate"><code class="notranslate">package main

import (
    "log"
    "net/mail"
)

func formatEmailAddress(emailaddress, name string) string {
    a := new(mail.Address)
    if "" == emailaddress {
        return ""
    }
    a.Address = emailaddress
    if "" != name {
        a.Name = name
    }
    return a.String()
}

func main() {
    s := formatEmailAddress("test.mail@gmail.com", "naé, mée")
    log.Println(s)
    a, err := mail.ParseAddress(s)
    if nil != err {
        log.Println("error because:", err)
    } else {
        log.Println("name is:", a.Name, "email is:", a.Address)
    }
}
</code></pre></div>
<p dir="auto">The following program fails the panic:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;fmt&quot;
    &quot;net/mail&quot;
)

func main() {
    data := &quot;\&quot;\\\x1f,\&quot;&lt;0@0&gt;&quot;
    addr, err := mail.ParseAddress(data)
    if err != nil {
        return
    }
    _, err = mail.ParseAddress(addr.String())
    if err != nil {
        fmt.Printf(&quot;failed to parse addr: %q -&gt; %q\n&quot;, data, addr)
        panic(err)
    }
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
    <span class="pl-s">"fmt"</span>
    <span class="pl-s">"net/mail"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">data</span> <span class="pl-c1">:=</span> <span class="pl-s">"<span class="pl-cce">\"</span><span class="pl-cce">\\</span><span class="pl-cce">\x1f</span>,<span class="pl-cce">\"</span>&lt;0@0&gt;"</span>
    <span class="pl-s1">addr</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">mail</span>.<span class="pl-en">ParseAddress</span>(<span class="pl-s1">data</span>)
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-k">return</span>
    }
    <span class="pl-s1">_</span>, <span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-s1">mail</span>.<span class="pl-en">ParseAddress</span>(<span class="pl-s1">addr</span>.<span class="pl-en">String</span>())
    <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
        <span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"failed to parse addr: %q -&gt; %q<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">data</span>, <span class="pl-s1">addr</span>)
        <span class="pl-en">panic</span>(<span class="pl-s1">err</span>)
    }
}</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed to parse addr: &quot;\&quot;\\\x1f,\&quot;&lt;0@0&gt;&quot; -&gt; &quot;=?utf-8?q?=1F,?= &lt;0@0&gt;&quot;
panic: mail: no angle-addr"><pre class="notranslate"><code class="notranslate">failed to parse addr: "\"\\\x1f,\"&lt;0@0&gt;" -&gt; "=?utf-8?q?=1F,?= &lt;0@0&gt;"
panic: mail: no angle-addr
</code></pre></div>
<p dir="auto">ParseAddress must handle result of Address.String, or else first ParseAddress must fail.</p>
<p dir="auto">go version devel +514014c Thu Jun 18 15:54:35 2015 +0200 linux/amd64</p>