-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: net/mail: allow AddressParser helper code to signal invalid character set #41625
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
Comments
AddressParser
ignores errors
Change https://golang.org/cl/257398 mentions this issue: |
I think the change in error handling happened in https://golang.org/cl/7890 aka 2b03610 |
Thank you for filing this bug @tt! As @ianlancetaylor mentioned on your CL https://go-review.googlesource.com/c/go/+/257398, exporting new errors requires a proposal review firstly. Could you please convert this issue into a proposal and I can help you tweak the title but please help tweak the body to make it a concrete proposal. Thank you! |
Given the current rush for time and the fact that holding this up presents a potential bug, we can apply a pragmatic approach with either: if if _, ok := err.(charsetError); ok {
return s, true, err
} else if strings.HasPrefix(err.Error(), "mime: unhandled charset") {
// Unfortunately before we have an exported cross-package error,
// we have to rely on string matching. TODO: replace this check with
// errors.Is/As whenever https://golang.org/issue/41625 is accepted.
return s, true, err
} b) Create an internal package called customerrors or so, and in it define that error that can then type CharsetError = customerrors.CharsetError |
It doesn't seem like we should change anything for Go 1.16. For the future, why does mime need to export the CharsetError? Why not net/mail? |
The parsing starts from mime which is where it is necessary. However I
proposed 2 alternatives to begin with: 1. Internal package 2. Sub string
match.
…On Wed, Oct 28, 2020 at 10:51 AM Russ Cox ***@***.***> wrote:
It doesn't seem like we should change anything for Go 1.16.
For the future, why does mime need to export the CharsetError? Why not
net/mail?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#41625 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3V7HKT6HIIDC4YC4UHDSNBKY5ANCNFSM4RZHM35Q>
.
|
It looks like if WordDecoder.CharsetReader returns any error, that should be taken to mean "character set not supported". So maybe some code in mime or net/mail needs to be more careful about doing that, and there is just a bug here. |
I finally looked at this and mailed https://go-review.googlesource.com/c/go/+/283632. |
Change https://golang.org/cl/283632 mentions this issue: |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
The detection of the "unknown charset" case was too tailored to one specific address parser. Make it generalize, so that custom address parsers behave the same way as the default one for character sets they do not handle. Fixes #41625. Change-Id: I347d4bb6844d0a1f23e908b776d21e8be5af3874 Reviewed-on: https://go-review.googlesource.com/c/go/+/283632 Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I assigned a
mime.WordDecoder
tomail.AddressParser
in order to be able to support more charsets.This changes the behavior of the parsing:
(&mail.AddressParser{}).Parse("=?foo?Q?=00?= <foo@example.com>")
returns no value and the error (&errors.errorString{s:"mail: missing word in phrase: charset not supported: \"foo\""}
)(&mail.AddressParser{WordDecoder: &mime.WordDecoder{}}).Parse("=?foo?Q?=00?= <foo@example.com>")
returns the value&mail.Address{Name:"=?foo?Q?=00?=", Address:"foo@example.com"}
and no errorAssigning the decoder's
CharsetReader
makes no difference.See this Go playground for an example.
What did you expect to see?
I would expect to be able to still error when encountering an unsupported charset and maybe generally to know whether any error occurred.
What did you see instead?
The error was ignored and the name was set to the decoded word.
When
mail.AddressParser
was first implemented in 1defd22, it would return any error.That changed in 6491496 and since only the unexported
charsetError
is treated as an error:go/src/net/mail/message.go
Lines 733 to 750 in 3e636ab
However, it feels like an unintended consequence of that commit.
I think one approach to solving this would be moving
charsetError
to themime
package (wheremime.WordDecoder
itself could use it) and exporting it.The text was updated successfully, but these errors were encountered: