golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124k stars 17.67k forks source link

net/mail: Provide Address.String() alternative which only converts to RFC 5322 and does not encode as RFC 2047 #27908

Open epelc opened 6 years ago

epelc commented 6 years ago

The Address.String() method sometimes encodes as RFC 2047 after the 5322 formatting depending on the characters in the address. However some services (Ala sparkpost transmission api header fields) want RFC 5322 formatted addresses in UTF8 and not encoded as RFC 2047.

I'm not sure if the [quoting]( I don't think you can easily or safely reverse the 2047 encoding via the mime package because the code has two paths for quoting. I think you'd want a String() method which basically returned before this.) is a part of rfc 2047 or not.

I know this isn't required to the use the api but I'm wondering if there are any other use case which wouldn't require RFC 2047 encoding as well. If so it might be worthwhile to add an additional string/format function.

epelc commented 6 years ago

For reference here are the sparkpost docs requiring no RFC 2047 encoding of header fields. I believe they do this because they are allows template/substitution variables within their headers.

Each header value is expected in the UTF-8 charset without RFC2047 encoding. https://developers.sparkpost.com/api/transmissions/#header-header-notes

katiehockman commented 6 years ago

/cc @bradfitz

bradfitz commented 6 years ago

Could you provide some examples?

Any suggested method name?

epelc commented 6 years ago

I just looked through the rfc(5322) a bit and it refers to this syntax as name-addr

name-addr = [display-name] angle-addr Section 3.4 https://tools.ietf.org/html/rfc5322#section-3

Maybe func (*Address) NameAddr() string I'm pretty sure go is against putting rfc numbers in names of things besides the time formatting vars and I don't think there are competing standards since rfc 2044 is just an encoding and not a formatting rfc afaik.

bradfitz commented 6 years ago

Name sounds fine. Feel free to send a change.

gopherbot commented 6 years ago

Change https://golang.org/cl/139077 mentions this issue: net/mail: addsNameAddr() stringmethod to return UTF8 RFC 5322name-addrformatted addresses

andrius4669 commented 5 years ago

RFC 6532 section 3.2 specifically allows this, so I believe it should be documented as such; RFC 5322 on itself doesn't specify raw UTF-8 in addresses.

smasher164 commented 5 years ago

@epelc Any update on this? Is there still a desire for this to get in 1.14? I see some unaddressed comments on the CL.