-
Notifications
You must be signed in to change notification settings - Fork 18k
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 doesn't handle ISO-8859-15, windows-1252 etc charsets #7079
Comments
CL https://golang.org/cl/101330049 mentions this issue. |
CL https://golang.org/cl/132680044 mentions this issue. |
CL https://golang.org/cl/7890 mentions this issue. |
This issue is not really fixed since decoding an address before parsing it does not always work: to := "=?ISO-8859-15?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>"
// Parsing the address still fails because of the unhandled charset.
addr, err := mail.ParseAddress(to)
fmt.Println(addr) // <nil>
fmt.Println(err) // mail: missing word in phrase: charset not supported: "iso-8859-15"
// Decoding the address before parsing it also fails because mail.ParseAddress then
// fails parsing it.
var dec mime.WordDecoder
dec.CharsetReader = func(charset string, input io.Reader) (io.Reader, error) {
return input, nil
}
d, err := dec.DecodeHeader(to)
fmt.Println(err) // <nil>
addr, err = mail.ParseAddress(d)
fmt.Println(addr) // <nil>
fmt.Println(err) // mail: no angle-addr Possible solutions:
/cc @bradfitz |
I'm not sure I care enough for Go 1.5. Perhaps the minimum thing we can do is return an exported error type from mail.ParseAddress for unknown charset (instead for using fmt.Errorf) so callers can know to use mime.WordDecoder with a CharsetReader with a specific charset. |
That does not work as mail.ParseAddress then throws |
I meant from the first ParseAddress call. I was going to say let's make the mail.ParseAddress func act identically as it did in Go 1.4 for unknown charsets, but it just returned an error then too, so it's already identical. I also considered just saying that we return the unable-to-decode part as the Name in e.g. Yeah, maybe we just add a new func like `mail.ParseAddressWithDecoder' and take a *mime.WordDecoder. But I feel that that will both be too word and too limiting. How about this: package mail // in net/mail
type AddressParser struct {
// WordDecoder optionally specifies a decoder for RFC 2047 encoded-words.
WordDecoder *mime.WordDecoder
// any future options here (inevitable) like sloppiness modes
}
func (p *AddressParser) Parse(address string) (*Address, error)
func (p *AddressParser) ParseList(list string) ([]*Address, error) I know we already have a private And the addrParser (lowercase) would still be made per-call (and consumed). I don't now why it's backed by a |
CL https://golang.org/cl/10392 mentions this issue. |
by Famcool:
The text was updated successfully, but these errors were encountered: