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 parsing fails when name contains '@' #66447

Closed
jonasgeiler opened this issue Mar 21, 2024 · 2 comments
Closed

net/mail: address parsing fails when name contains '@' #66447

jonasgeiler opened this issue Mar 21, 2024 · 2 comments

Comments

@jonasgeiler
Copy link

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/jonas/.cache/go-build'
GOENV='/home/jonas/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jonas/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jonas/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/tmp/mailtest/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3581226906=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I tried to parse a mail address formatted like Software @ Server <noreply@example.com>, but I got the error mail: missing '@' or angle-addr. I assume this is a bug since I can't find the RFC5322 mentioning anywhere that an '@' is not allowed in the name, and also because this works with other software I have used in the past (but they might have implemented RFC5322 incorrectly...).

Here is the code that fails:

package main

import (
        "fmt"
        "log"
        "net/mail"
)

func main() {
        e, err := mail.ParseAddress("Software @ Server <noreply@example.com>")
        if err != nil {
                log.Fatal(err)
        }

        fmt.Println(e.Name)
        fmt.Println(e.Address)
}

What did you see happen?

The following was printed out when I ran the program above:

2024/03/21 17:49:14 mail: missing '@' or angle-addr
exit status 1

What did you expect to see?

Something like:

Software @ Server
noreply@example.com
@seankhliao
Copy link
Member

https://www.rfc-editor.org/rfc/rfc5322.html#section-3.4

address         =   mailbox / group
mailbox         =   name-addr / addr-spec
name-addr       =   [display-name] angle-addr
display-name    =   phrase

https://www.rfc-editor.org/rfc/rfc5322.html#section-3.2.5

phrase          =   1*word / obs-phrase
word            =   atom / quoted-string

https://www.rfc-editor.org/rfc/rfc5322.html#section-3.2.3

atom            =   [CFWS] 1*atext [CFWS]
atext           =   ALPHA / DIGIT /    ; Printable US-ASCII
                    "!" / "#" /        ;  characters not including
                    "$" / "%" /        ;  specials.  Used for atoms.
                    "&" / "'" /
                    "*" / "+" /
                    "-" / "/" /
                    "=" / "?" /
                    "^" / "_" /
                    "`" / "{" /
                    "|" / "}" /
                    "~"

it's not an allowed character.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 21, 2024
@jonasgeiler
Copy link
Author

jonasgeiler commented Mar 21, 2024

Alright, seems like I'm not very well versed in reading RFCs 😅 🤦🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants