aboutsummaryrefslogtreecommitdiff
path: root/src/net/mail/message.go
AgeCommit message (Collapse)Author
9 daysnet/mail: fix quadratic complexity in consumeCommentmohammadmseet-hue
consumeComment builds the comment string by repeated string concatenation inside a loop. Each concatenation copies the entire string built so far, making the function O(n^2) in the depth of nested comments. Replace the concatenation with a strings.Builder, which amortizes allocation by doubling its internal buffer. This reduces consumeComment from O(n^2) to O(n). This is the same bug class as the consumeDomainLiteral fix in CVE-2025-61725. Benchmark results (benchstat, 8 runs): name old time/op new time/op delta ConsumeComment/depth10 2.481us 1.838us -25.92% ConsumeComment/depth100 86.58us 6.498us -92.50% ConsumeComment/depth1000 7.963ms 52.82us -99.34% ConsumeComment/depth10000 897.8ms 521.3us -99.94% The quadratic cost becomes visible at depth 100 and dominant by depth 1000. At depth 10000, the fix is roughly 1700x faster. Change-Id: I3c927f02646fcab7bab167cb82fd46d3327d6d34 GitHub-Last-Rev: 7742dad716ee371766543f88e82bd163bd9d7ac2 GitHub-Pull-Request: golang/go#78393 Reviewed-on: https://go-review.googlesource.com/c/go/+/759940 Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Junyang Shao <shaojunyang@google.com>
2025-10-07net/mail: avoid quadratic behavior in mail address parsingDamien Neil
RFC 5322 domain-literal parsing built the dtext value one character at a time with string concatenation, resulting in excessive resource consumption when parsing very large domain-literal values. Replace with a subslice. Benchmark not included in this CL because it's too narrow to be of general ongoing use, but for: ParseAddress("alice@[" + strings.Repeat("a", 0x40000) + "]") goos: darwin goarch: arm64 pkg: net/mail cpu: Apple M4 Pro │ /tmp/bench.0 │ /tmp/bench.1 │ │ sec/op │ sec/op vs base │ ParseAddress-14 1987.732m ± 9% 1.524m ± 5% -99.92% (p=0.000 n=10) │ /tmp/bench.0 │ /tmp/bench.1 │ │ B/op │ B/op vs base │ ParseAddress-14 33692.767Mi ± 0% 1.282Mi ± 0% -100.00% (p=0.000 n=10) │ /tmp/bench.0 │ /tmp/bench.1 │ │ allocs/op │ allocs/op vs base │ ParseAddress-14 263711.00 ± 0% 17.00 ± 0% -99.99% (p=0.000 n=10) Thanks to Philippe Antoine (Catena cyber) for reporting this issue. Fixes CVE-2025-61725 Fixes #75680 Change-Id: Id971c2d5b59882bb476e22fceb7e01ec08234bb7 Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/2840 Reviewed-by: Roland Shoemaker <bracewell@google.com> Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/709860 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Bypass: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
2025-03-11net/mail: use sync.OnceValue to build dateLayouts1911860538
Simplify buildDateLayouts with sync.OnceValue. Change-Id: Ib48ab20ee00f5e44cc1b0f6e1afe3fcd1b7dc3c7 GitHub-Last-Rev: 0866d463de1ec618d0d645b98f5e94917b8c3bde GitHub-Pull-Request: golang/go#72743 Reviewed-on: https://go-review.googlesource.com/c/go/+/656055 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-19net/mail: enhance address parser to include support for domain literalsNuno Gonçalves
The existing implementation of the mail package conforms to RFC 5322 for parsing mail messages, but it lacks support for domain literals. This patch addresses this limitation by adding support for domain literals in the address parser. The Addr-Spec Specification, defined in RFC 5322 Section 3.4.1, outlines the format for email addresses: https://datatracker.ietf.org/doc/html/rfc5322\#section-3.4.1 Fixes #60206 Change-Id: Ic901418325bd1da69e70800d70b87d658b953738 GitHub-Last-Rev: bdda66f3fe098df3a62d803b1f69e63fef6281e3 GitHub-Pull-Request: golang/go#66075 Reviewed-on: https://go-review.googlesource.com/c/go/+/567777 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-01-26net/mail: remove obsolete commentRoland Shoemaker
Forgot to remove this in CL 555596. Change-Id: I903a6d1c02ee38b676e3e5860376d8d9509f0e03 Reviewed-on: https://go-review.googlesource.com/c/go/+/558675 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Roland Shoemaker <roland@golang.org>
2024-01-22net/mail: properly handle special characters in phrase and obs-phraseRoland Shoemaker
Fixes a couple of misalignments with RFC 5322 which introduce significant diffs between (mostly) conformant parsers. This change reverts the changes made in CL50911, which allowed certain special RFC 5322 characters to appear unquoted in the "phrase" syntax. It is unclear why this change was made in the first place, and created a divergence from comformant parsers. In particular this resulted in treating comments in display names incorrectly. Additionally properly handle trailing malformed comments in the group syntax. Fixes #65083 Change-Id: I00dddc044c6ae3381154e43236632604c390f672 Reviewed-on: https://go-review.googlesource.com/c/go/+/555596 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-06-21net/mail: permit more characters in mail headersIan Lance Taylor
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. Fixes #58862 Fixes #60332 Change-Id: I5437f5e18a756f6ca61c13c4d8ba727be73eff9a Reviewed-on: https://go-review.googlesource.com/c/go/+/504416 Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-03-24net/mail: fix EOF error while reading header-only message0xc0d
Check if any header found in case of EOF to recognize header-only messages and if so, return a Message with the found headers and a body from the reader which is already empty. Fixes #33823. Change-Id: I2f0396b08e9be4e6c89c212ce62b9c87b5f63123 GitHub-Last-Rev: 356a9420837bf7e247247f7dc7c8a1d218684aeb GitHub-Pull-Request: golang/go#47898 Reviewed-on: https://go-review.googlesource.com/c/go/+/344269 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
2022-11-18all: add missing periods in commentscui fliter
Change-Id: I69065f8adf101fdb28682c55997f503013a50e29 Reviewed-on: https://go-review.googlesource.com/c/go/+/449757 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joedian Reid <joedian@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-03all: use strings.Builder instead of bytes.BufferSasha Melentyev
Change-Id: I6d7213d29ade591b8366d5640833bd5a20474165 GitHub-Last-Rev: 94195832873fe6764d45ffdd6efa1ca49e57a743 GitHub-Pull-Request: golang/go#54834 Reviewed-on: https://go-review.googlesource.com/c/go/+/427814 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: hopehook <hopehook@golangcn.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-28net/mail: accept UT as a timezoneIan Lance Taylor
Fixes #39906 Change-Id: I8fcaf4c1ccc4131d770cff08d9c80f520885a6b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/396214 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2022-03-25net/mail: improve detection of charset errorsRuss Cox
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>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-05net/mail: avoid ParseDate confusion if day name includes "T"Emmanuel T Odeke
Fixes the check for RFC 5322 "obsolete time zone" to ensure that we correctly extract the entire date from the "T" of the implied time zone. Obsolete Time zones come in the form: * GMT * PST * MDT etc, as per Section 4.3 of RFC 5322, https://tools.ietf.org/html/rfc5322#section-4.3. The prior check from CL 117596 erronenously used strings.Index which selects the first "T", and that meant that dates containing days "Tue" or "Thu" could not be parsed. We also now deal with "T" in the CFWS "Comment Folding White Space". Thus we'll now accept dates: * Thu, 20 Nov 1997 09:55:06 MDT * Thu, 20 Nov 1997 09:55:06 MDT (MDT) * Fri, 21 Nov 1997 09:55:06 MDT (This comment) * Fri, 21 Nov 1997 09:55:06 MDT (MDT Fixes #39260 Change-Id: I6d59d99bc4f05a82582c826b5c5a080a25fd999b Reviewed-on: https://go-review.googlesource.com/c/go/+/235200 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2020-08-27net/mail: return error on empty address listIan Lance Taylor
This restores the handling accidentally changed in CL 217377. Fixes #40803 For #36959 Change-Id: If77fbc0c2a1dde4799f760affdfb8dde9bcaf458 Reviewed-on: https://go-review.googlesource.com/c/go/+/248598 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Jeremy Fishman <jfishman@cloudflare.com>
2020-02-21net/mail: skip empty entries in parseAddressListTimmy Douglas
RFC 5322 has a section 4.4 where it says that address-list could have "null" members: "That is, there could be two or more commas in such a list with nothing in between them, or commas at the beginning or end of the list." This change handles such a case so that mail clients using this method on actual email messages get a reasonable return value when they parse email. Fixes #36959 Change-Id: I3ca240969935067262e3d751d376a06db1fef2a2 GitHub-Last-Rev: b96a9f2c075dfd67c3ff7b8ae0c12e12035f0da0 GitHub-Pull-Request: golang/go#36966 Reviewed-on: https://go-review.googlesource.com/c/go/+/217377 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-11net/mail: added support to trailing CFWS in dateConstantin Konstantinidis
RFC 5322 date format allows CFWS after the timezone. If CFWS is valid, it is discarded and parsing is done as before using time.Parse(). Existing test is extended with limit cases and invalid strings. Fixes #22661 Change-Id: I54b96d7bc384b751962a76690e7e4786217a7941 Reviewed-on: https://go-review.googlesource.com/c/go/+/117596 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-07-28all: change some function documentation to be more idiomaticDominik Honnef
Change-Id: I932de9bb061a8ba3332ef03207983e8b98d6f1e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/187918 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-06net/mail: better error in ParseAddress when missing "@domain"Daniel Martí
If the input was "John Doe", we're definitely missing "<email>", as "John Doe@domain" isn't a valid email address. However, if the input was "john.doe", it's possible that the user meant "john.doe@domain", and not just "john.doe <email>". Make it clear in the error that either could be the source of the problem. Fixes #27064. Change-Id: I1b8f1342775d711823dffc3db974898ee62d3a34 Reviewed-on: https://go-review.googlesource.com/c/go/+/165517 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-22net/mail: lazily initialize dateLayoutsCholerae Hu
Saves 6KB of memory in stdlib packages. Updates #26775 Change-Id: I1a6184cefa78e9a3c034fa84506fdfe0fec27add Reviewed-on: https://go-review.googlesource.com/127736 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-03-26all: use strings.Builder instead of bytes.Buffer where appropriateBrad Fitzpatrick
I grepped for "bytes.Buffer" and "buf.String" and mostly ignored test files. I skipped a few on purpose and probably missed a few others, but otherwise I think this should be most of them. Updates #18990 Change-Id: I5a6ae4296b87b416d8da02d7bfaf981d8cc14774 Reviewed-on: https://go-review.googlesource.com/102479 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-15net/mail: clarify doc commentRuss Cox
Rewrite the text added in CL 50911, which I did not understand. Change-Id: Id6271ffe2f7c8833dd7733fe0254fa4927fac150 Reviewed-on: https://go-review.googlesource.com/78124 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-14net/mail: treat comment in address as display nameMichael Stapelberg
I verified this change on a corpus of > 200 GB of emails since the mid-90s. With this change, more addresses parse than before, and anything which parsed before still parses. In said corpus, I came across the edge case of comments preceding an addr-spec (with angle brackets!), e.g. “(John Doe) <john@example.com>”, which does not satisfy the conditions to be treated as a fallback, as per my reading of RFC2822. This change does not parse quoted-strings within comments (a corresponding TODO is in the code), but I have not seen that in the wild. Fixes #22670 Change-Id: I526fcf7c6390aa1c219fdec1852f26c514506f76 Reviewed-on: https://go-review.googlesource.com/77474 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-11-01net/mail: capitalize acronym on helper function nameMikio Hara
Change-Id: Ibae06adcc69cae34cb0a14d990a0949b77fa772c Reviewed-on: https://go-review.googlesource.com/73930 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-05all: revert "all: prefer strings.LastIndexByte over strings.LastIndex"Marvin Stenger
This reverts https://golang.org/cl/66372. Updates #22148 Change-Id: I3e94af3dfc11a2883bf28e1d5e1f32f98760b3ee Reviewed-on: https://go-review.googlesource.com/68431 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-27net/mail: parse group in email addressMihail Minaev
This change adds the ability to parse group into email address. The information about group name and group members is lost for backwards compatibility. According to this rule address `Group: Test <text@example.com>;` would be parsed into `Test <test@example.com>`. Fixes #22014 Change-Id: I6e804a62f3ede04f555a1b82500b8ca030eeb431 Reviewed-on: https://go-review.googlesource.com/66250 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-27all: prefer strings.LastIndexByte over strings.LastIndexMarvin Stenger
strings.LastIndexByte was introduced in go1.5 and it can be used effectively wherever the second argument to strings.LastIndex is exactly one byte long. This avoids generating unnecessary string symbols and saves a few calls to strings.LastIndex. Change-Id: I7b5679d616197b055cffe6882a8675d24a98b574 Reviewed-on: https://go-review.googlesource.com/66372 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-24net/mail: skip trailing comment while parsing emailMinaev Mike
The existing implementation doesn't handle comment constructions in email address. So addresses that are consistent with RFC 5322 don't parse at all. Fixes #21257 Change-Id: Iae3ba951dfb26b7cf0e1885a680bbceb9123d6d5 Reviewed-on: https://go-review.googlesource.com/53550 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-29net/mail: parse cases when phrase has special chars without quotesGuilherme Rezende
Updates #21018 Change-Id: I00b6667fb5fee78559a391815f58760a2baea90e Reviewed-on: https://go-review.googlesource.com/50911 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Avelino <t@avelino.xxx> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-19net/mail: Fix typoyansal
Fixes #21089 Change-Id: Idd65c7185b3e19f33958eb165cb5b09c06db3d56 Reviewed-on: https://go-review.googlesource.com/50110 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-03-08net/mail: fix wrong error message in consumePhraseHiroshi Ioka
Fixes #19415 Change-Id: I6414f82e42bd09f1793156befce326aeac919ea2 Reviewed-on: https://go-review.googlesource.com/37911 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-03-07net/mail: ignore whitespace between adjacent 'encoded-word'sHiroshi Ioka
rfc2047 says: White space between adjacent 'encoded-word's is not displayed. Although, mime package already have that feature, we cannot simply reuse that code, because there is a subtle difference in quoted-string handling. Fixes #19363 Change-Id: I754201aa3c6b701074ad78fe46818af5b96cbd00 Reviewed-on: https://go-review.googlesource.com/37811 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-11-28net: document that Header.Get key is case insensitiveKaviraj
Document that key in Header.Get(key) is case insensitive in http.Header, mail.Header, textproto.Header. Fixes #18019 Change-Id: Iba7932491e02e555190b6fce053088b580a853ef Reviewed-on: https://go-review.googlesource.com/33530 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-27net/mail: allow empty quoted string name in address againRuss Cox
CL 12905 disallowed "Bob" <""@example.com> but inadvertently also disallowed "" <bob@example.com>. Move the empty string check to apply only in the addr-spec. Fixes #14866. Change-Id: Ia0b7a1a32810aa78157ae77bd0130b78154c460d Reviewed-on: https://go-review.googlesource.com/32176 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-10-24net/mail: expose ParseDate, for use parsing Resent-Date headersRuss Cox
Fixes #16657. Change-Id: I9425af91a48016b1d7465b9f43cafa792bc00bb3 Reviewed-on: https://go-review.googlesource.com/31581 Reviewed-by: Quentin Smith <quentin@golang.org>
2016-04-15net/mail: allow utf-8 in ParseAddressConrad Irwin
The existing implementation correctly supported RFC 5322, this change adds support for UTF-8 while parsing as specified by RFC 6532. The serialization code is unchanged, so emails created by go remain compatible with very legacy systems. Fixes #14260 Change-Id: Ib57e510f5834d273605e1892679f2df19ea931b1 Reviewed-on: https://go-review.googlesource.com/19687 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alexandre Cesaro <alexandre.cesaro@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-04-15all: remove unnecessary type conversionsMatthew Dempsky
cmd and runtime were handled separately, and I'm intentionally skipped syscall. This is the rest of the standard library. CL generated mechanically with github.com/mdempsky/unconvert. Change-Id: I9e0eff886974dedc37adb93f602064b83e469122 Reviewed-on: https://go-review.googlesource.com/22104 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-04-12all: standardize RFC mention formatDan Peterson
Standardize on space between "RFC" and number. Additionally change the couple "a RFC" instances to "an RFC." Fixes #15258 Change-Id: I2b17ecd06be07dfbb4207c690f52a59ea9b04808 Reviewed-on: https://go-review.googlesource.com/21902 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-31net/mail: throw error when multiple addresses are given to ParseAddressHiroshi Ioka
Fixes #14610 Change-Id: I3e57dd60b531c1495ea3bc37ef707a1e4e644baa Reviewed-on: https://go-review.googlesource.com/20180 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-04net/mail: do not parse RFC 2047 tokens in quoted stringsRuss Cox
RFC 2047 tokens like =?utf-8?B?whatever?= can only appear unquoted, but this code was trying to decode them even when they came out of quoted strings. Quoted strings must be left alone. Fixes #11294. Change-Id: I41b371f5b1611f1e56d93623888413d07d4ec878 Reviewed-on: https://go-review.googlesource.com/17381 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-02net/mail: use base64 encoding when needed in Address.String()Alexandre Cesaro
When the name of an Address contains non-ASCII characters, Address.String() used mime.QEncoding to encode the name. However certain characters are forbidden when an encoded-word is in a phrase context (see RFC 2047 section 5.3) and these characters are not encoded by mime.QEncoding. In this case we now use mime.BEncoding (base64 encoding) so that forbidden characters are also encoded. Fixes #11292 Change-Id: I52db98b41ece439295e97d7e94c8190426f499c2 Reviewed-on: https://go-review.googlesource.com/16012 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-12-02net/mail: better errors on non-ascii charactersIngo Oeser
Fixes #12492 Change-Id: I8bb512027639301e2f2c41aab84e6d06ae88b137 Reviewed-on: https://go-review.googlesource.com/14312 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-08-11net/mail: fix build.David Symonds
Change-Id: I8f5c72c6c0db015c06d564523bab35d97d934578 Reviewed-on: https://go-review.googlesource.com/13510 Reviewed-by: Michael McGreevy <mcgreevy@golang.org> Reviewed-by: David Symonds <dsymonds@golang.org>
2015-08-11net/mail: avoid panic in (*Address).String for malformed addresses.David Symonds
Fixes #12098. Change-Id: I190586484cd34856dccfafaba60eff0197c7dc20 Reviewed-on: https://go-review.googlesource.com/13500 Reviewed-by: Rob Pike <r@golang.org>
2015-07-31net/mail: fixed quoted-localMathiasB
Fixes some minor issues regarding quoted-string when parsing the local-part. Those strings should return an error: - quoted-string without any content: `""@test.com` - quoted-string containing tab: "\"\t\"@test.com" Fixes #11293 Change-Id: Ied93eb6831915c9b1f8e727cea14168af21f8d3b Reviewed-on: https://go-review.googlesource.com/12905 Reviewed-by: Russ Cox <rsc@golang.org>
2015-07-22net/mail: enhanced Address.String and ParseAddress to match RFC 5322MathiasB
Updated Address.String so it restores quoted local parts, which wasn't done before. When parsing `<" "@example.com>`, the formatted string returned `< @example>`, which doens't match RFC 5322, since a space is not atext. Another example is `<"bob@valid"@example.com>` which returned `<bob@valid@example.com>`, which is completely invalid. I also added support for quotes and backslashes in a quoted local part. Besides formatting a parsed Address, the ParseAddress function also needed more testing and finetuning for special cases. Things like `<.john.doe@example.com>` and `<john..doe@example.com>` e.a. were accepted, but are invalid. I fixed those details and add tests for some other special cases. Fixes #10768 Change-Id: Ib0caf8ad603eb21e32fcb957a5f1a0fe5d1c6e6e Reviewed-on: https://go-review.googlesource.com/8724 Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-26net/mail: add AddressParser typeAlexandre Cesaro
Add the AddressParser type to allow decoding any charset in mail addresses. Fixes #7079 Change-Id: Ic34efb3e3d804a4e17149a6c38cfd73f5f275ab7 Reviewed-on: https://go-review.googlesource.com/10392 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-05-11mime: Export RFC 2047 codeAlexandre Cesaro
Fixes #4943 Fixes #4687 Fixes #7079 Change-Id: Ia96f07d650a3af935cd75fd7e3253f4af2977429 Reviewed-on: https://go-review.googlesource.com/7890 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>