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 cannot parse email address with name contains chinese character #36200

Closed
m3ng9i opened this issue Dec 18, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@m3ng9i
Copy link

m3ng9i commented Dec 18, 2019

What version of Go are you using (go version)?

$ go version
go version go1.13.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/username/.cache/go-build"
GOENV="/home/username/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/username/dev/go-packages/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/username/dev/go/go1.13.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/username/dev/go/go1.13.5/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build697152646=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
    "fmt"
    "net/mail"
)

func main() {

    // 测试<example@example.com>
    addr1 := "=?GB2312?B?suLK1A==?= <example@example.com>"
    addr2 := "=?GB18030?B?suLK1A==?= <example@example.com>"
    addr3 := "=?GBK?B?suLK1A==?= <example@example.com>"

    var err error

    _, err = mail.ParseAddress(addr1)
    fmt.Println(err) // mail: missing word in phrase: charset not supported: "gb2312"

    _, err = mail.ParseAddress(addr2)
    fmt.Println(err) // mail: missing word in phrase: charset not supported: "gb18030"

    _, err = mail.ParseAddress(addr3)
    fmt.Println(err) // mail: missing word in phrase: charset not supported: "gbk"
}

What did you expect to see?

Chinese name should be parsed correctly.

What did you see instead?

mail: missing word in phrase: charset not supported: "gb2312"
@mvdan
Copy link
Member

mvdan commented Dec 18, 2019

Why not use utf-8? See https://golang.org/pkg/mime/#WordDecoder:

utf-8, iso-8859-1 and us-ascii charsets are handled by default.

I don't think we want to be implementing all possible charsets out there in the standard library. If you really need to support arbitrary charsets, you should probably supply your own word decoder via https://golang.org/pkg/net/mail/#AddressParser.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 18, 2019
@m3ng9i
Copy link
Author

m3ng9i commented Dec 18, 2019

Why not use utf-8? See https://golang.org/pkg/mime/#WordDecoder:

Because the email is from the sender, I cannot control the charset they use.

I don't think we want to be implementing all possible charsets out there in the standard library. If you really need to support arbitrary charsets, you should probably supply your own word decoder via https://golang.org/pkg/net/mail/#AddressParser.

Thanks for the response, I'll try to make my own word decoder.

@mvdan
Copy link
Member

mvdan commented Dec 18, 2019

Great. I'm closing this for now. If you want to open an issue for the mime package to support many more encodings, you can do that too, but we'd probably need a good argument to add more code to the standard library.

@mvdan mvdan closed this as completed Dec 18, 2019
@golang golang locked and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants