-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: characters allowed in RFC 5322 are invalid while parsing email header #58862
Comments
https://dev.golang.org/owners lists @bradfitz as the maybe-owner of |
Duplicate #39591 |
It's working on version 1.19 |
cc @neild |
The problem code in net/mail/message.go is:
Using
which is incorrect for a mail header, RFC 5322 says a valid header name is:
Can someone please fix it? ....please.... |
@gopherbot Please open backport to 1.20. This stopped working due to the changes in #53188, but those changes don't apply to net/mail. |
Change https://go.dev/cl/504416 mentions this issue: |
Backport issue(s) opened: #60875 (for 1.20). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/504881 mentions this issue: |
We parse mail messages using net/textproto. For #53188, we tightened up the bytes permitted by net/textproto to match RFC 7230. However, this package uses RFC 5322 which is more permissive. Restore the permisiveness we used to have, so that older code continues to work. For #58862 For #60332 Fixes #60874 Fixes #60875 Change-Id: I5437f5e18a756f6ca61c13c4d8ba727be73eff9a Reviewed-on: https://go-review.googlesource.com/c/go/+/504881 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]>
We parse mail messages using net/textproto. For golang#53188, we tightened up the bytes permitted by net/textproto to match RFC 7230. However, this package uses RFC 5322 which is more permissive. Restore the permisiveness we used to have, so that older code continues to work. Fixes golang#58862 Fixes golang#60332 Change-Id: I5437f5e18a756f6ca61c13c4d8ba727be73eff9a Reviewed-on: https://go-review.googlesource.com/c/go/+/504416 Run-TryBot: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Create an empty directory and save code below in
main.go
, rungo mod tidy && go run .
.Note: it contains header
Custom/Header: v
.What did you expect to see?
Print value of email header
Custom/Header
:v
What did you see instead?
Function
mail.ReadMessage()
callstextproto.ReadMIMEHeader()
, it calls internal functionvalidHeaderValueByte()
(innet/textproto
) to validate characters in email header field,/
in header field is considered as invalid.The problem is,
validHeaderValueByte()
is designed to validate characters in HTTP header, not email header.According to RFC 5322 "Internet Message Format", section "2.2 Header fields":
Here's full list of printable US-ASCII characters:
https://www.ascii-code.com/characters/printable-characters
For example, characters
/
,*
,[
,]
are allowed in email header field according to RFC doc, but it won't pass currentvalidHeaderFieldByte()
because it's disallowed in http header field. This causes parse error as shown in above sample code. I believe there're some similar issues caused byvalidHeaderValueByte()
too.We may need a new exported function like
ReadMIMEHeader
but for email (maybe name it asReadEmailMIMEHeader()
), and allow characters as defined in RFC 5322, but other code innet/textproto
may need some changes too.The text was updated successfully, but these errors were encountered: