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 Error while parsing an email address with string literal(\n) inside a quoted string #39856

Closed
TVenuMadhav opened this issue Jun 25, 2020 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@TVenuMadhav
Copy link

TVenuMadhav commented Jun 25, 2020

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

$ go version
go version 1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

yes, https://play.golang.org/p/RPf1mhjMTby (playground go1.14.3)

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tvm/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/tvmv/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/gn/9krbz6jn7dlcglg8y_2plq5c0000gp/T/go-build519177471=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/RPf1mhjMTby

package main

import (
	"fmt"
	"net/mail"
)

func main() {
	sample_addresses := []string{"\"Testing \n Parsing\" <abc@def.com>", "\"Testing \\n Parsing\" <abc@def.com>"}
	
	for i := range sample_addresses {
		addr, err := mail.ParseAddress(sample_addresses[i])
		if err != nil {
			fmt.Println(i, "[ERROR]: ", err)
		} else {
			fmt.Println(i, "[NO ERROR]: ", addr.Name, addr.Address)
		}
	}
}

What did you expect to see?

0 [NO ERROR]:  Testing \n Parsing abc@def.com
1 [NO ERROR]:  Testing n Parsing abc@def.com

What did you see instead?

0 [ERROR]:  mail: missing word in phrase: mail: bad character in quoted-string: '\n'
1 [NO ERROR]:  Testing n Parsing abc@def.com
@davecheney
Copy link
Contributor

According to https://tools.ietf.org/html/rfc5322#section-3.2.4, a quoted string may only contain ascii values, 33, 35-91 , and 93-126.

\n is ascii 10 which is not valid according to my reading of section 3.2.4.

Can you explain how you came across this arguably invalid address, does it appear in the wild?

@davecheney davecheney added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jun 25, 2020
@TVenuMadhav
Copy link
Author

TVenuMadhav commented Jun 25, 2020

Thanks,

Can you explain how you came across this arguably invalid address, does it appear in the wild?

No, The email fields were generated, (checked^) before email is sent

I had \n in the name field after generating the email and the parsing using mail package (similar to above example) raised the error

I also want to point out that '\t' in the quoted string, somehow gets parsed (even though it is ascii 9) https://play.golang.org/p/Pgwes5n-N5y

@davecheney
Copy link
Contributor

I don’t disagree that mail.Parse can be inconsistent, see #39591, but it’s important to recognise any changes should drive towards better compliance with the RFC, so starting from what is valid according to the spec is probably a good place to start.

@mvdan
Copy link
Member

mvdan commented Jun 15, 2021

Closing old issues that still have the WaitingForInfo label where enough details to investigate weren't provided. Feel free to leave a comment with more details and we can reopen.

@mvdan mvdan closed this as completed Jun 15, 2021
@golang golang locked and limited conversation to collaborators Jun 15, 2022
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

4 participants