Sometimes it's necessary to deal with emails that do not follow the specification; in particular, it's possible to download such email via gmail.
When the existing implementation handle invalid mime media parameters, it returns nils and error, although there is a valid media type, which may be returned.
If this behavior changes, it may not affect any existing programs, but it will help to parse some emails.
Fixes#19498
Change-Id: Ieb2fdbddfd93857faee941d2aa49d59e286d57fd
Reviewed-on: https://go-review.googlesource.com/38190
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Change-Id: I6343c162e27e2e492547c96f1fc504909b1c03c0
Reviewed-on: https://go-review.googlesource.com/37793
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
These are possible use-cases for sync.Map.
Updates golang/go#18177
Change-Id: I5e2a3d1249967c37d3f89a41122bf4a90522db11
Reviewed-on: https://go-review.googlesource.com/36964
Reviewed-by: Ian Lance Taylor <iant@golang.org>
As per RFC 2046, the boundary for multipart MIME is allowed up to 70
characters. The old SetBoundary implementation only allowed up to 69 so
this bumps it to the correct value of 70.
The relevant RFC is at https://www.ietf.org/rfc/rfc2046.txt and section
5.1.1 defines the boundary specification.
Fixes#18793
Change-Id: I91d2ed4549c3d27d6049cb473bac680a750fb520
Reviewed-on: https://go-review.googlesource.com/35830
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Some multipart data arrives in a stream, where subsequent parts may not
be ready yet. Read should return a complete part as soon as
possible.
Fixes#15431
Change-Id: Ie8c041b853f3e07f0f2a66fbf4bcab5fe9132a7c
Reviewed-on: https://go-review.googlesource.com/32032
Run-TryBot: Quentin Smith <quentin@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
I used the slowtests.go tool as described in
https://golang.org/cl/32684 on packages that stood out.
go test -short std drops from ~56 to ~52 seconds.
This isn't a huge win, but it was mostly an exercise.
Updates #17751
Change-Id: I9f3402e36a038d71e662d06ce2c1d52f6c4b674d
Reviewed-on: https://go-review.googlesource.com/32751
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The basic structure of Part.Read should be simple:
do what you can with the current buffered data,
reading more as you need it. Make it that way.
Working entirely in the bufio.Reader's buffer eliminates
the need for an additional bytes.Buffer.
This structure should be easier to extend in the future as
more special cases arise.
Change-Id: I83cb24a755a1767c4c037f9ece6716460c3ecd01
Reviewed-on: https://go-review.googlesource.com/32092
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This lets quotedprintable handle some inputs found in the wild,
most notably generated by "Microsoft CDO for Exchange 2000",
and it also matches how Python's quopri package handles these inputs.
Fixes#13219.
Change-Id: I69d400659d01b6ea0f707b7053d61803a85b4799
Reviewed-on: https://go-review.googlesource.com/32174
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
When MSIE sends a full file path (in "intranet mode"), it does not
escape backslashes: "C:\dev\go\foo.txt", not "C:\\dev\\go\\foo.txt".
No known MIME generators emit unnecessary backslash escapes
for simple token characters like numbers and letters.
If we see an unnecessary backslash escape, assume it is from MSIE
and intended as a literal backslash. This makes Go servers deal better
with MSIE without affecting the way they handle conforming MIME
generators.
Fixes#15664.
Change-Id: Ia3b03b978317d968dc11b2f6de1df913c6bcbfcc
Reviewed-on: https://go-review.googlesource.com/32175
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Always close the file regardless of whether the copy succeeds or fails.
Pass along the close error if the copy succeeds
Fixes#16296
Change-Id: Ib394655b91d25750f029f17b3846d985f673fb50
Reviewed-on: https://go-review.googlesource.com/30410
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Adds a transparent sort to the mime/multipart package, which is
only used in the CreatePart func. This will ensure the ordering
of the MIMEHeader.
The point of this change was to ensure the output would be consistent
and something that could be depended on.
Fixes#13522
Change-Id: I9584ef9dbe98ce97d536d897326914653f8d9ddf
Reviewed-on: https://go-review.googlesource.com/17497
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
There was a typo introduced in the initial
implementation of the Plan 9 support of
the mime package.
On Plan 9, the mime type file name should be
/sys/lib/mimetype instead of /sys/lib/mimetypes.
Change-Id: If0f0a9b6f3fbfa8dde551f790e83bdd05e8f0acb
Reviewed-on: https://go-review.googlesource.com/23087
Run-TryBot: Minux Ma <minux@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
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>
RFC 2047 recommends a maximum length of 75 characters for
encoded-words. Due to a bug, encoded-words were limited to 77
characters instead of 75.
Change-Id: I2ff9d013ab922df6fd542464ace70b1c46dc7ae7
Reviewed-on: https://go-review.googlesource.com/20918
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The io.Reader contract makes no promises about how a Reader should
behave after it returns its first error. Usually the errors are
sticky, but they don't have to be. A regression in zlib.Reader (bug
accidentally relied on sticky errors.
Minimal fix: wrap the user's provided Reader in a Reader which
guarantees stickiness. The minimal fix is less scary than touching
the multipart state machine.
Fixes#14676
Change-Id: I8dd8814b13ae5530824ae0e68529f788974264a5
Reviewed-on: https://go-review.googlesource.com/20297
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions. This means contributors won't be confused by
misleading precedence.
This CL doesn't use go/doc to parse. It only addresses // comments.
It was generated with:
$ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])')
$ go test go/doc -update
Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7
Reviewed-on: https://go-review.googlesource.com/20022
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dave Day <djd@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Named returned values should only be used on public funcs and methods
when it contributes to the documentation.
Named return values should not be used if they're only saving the
programmer a few lines of code inside the body of the function,
especially if that means there's stutter in the documentation or it
was only there so the programmer could use a naked return
statement. (Naked returns should not be used except in very small
functions)
This change is a manual audit & cleanup of public func signatures.
Signatures were not changed if:
* the func was private (wouldn't be in public godoc)
* the documentation referenced it
* the named return value was an interesting name. (i.e. it wasn't
simply stutter, repeating the name of the type)
There should be no changes in behavior. (At least: none intended)
Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109
Reviewed-on: https://go-review.googlesource.com/20024
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Found this while reading through the code. The benchmark
accidently called the wrong function.
Change-Id: Idb88aa71e7098a4e29e7f5f39e64f8c5f8936a2a
Reviewed-on: https://go-review.googlesource.com/19977
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
A Content-Type always has a slash (type/subtype)
A Content-Disposition does not (e.g. "attachment" or "line").
A "media type" is either one of those, plus optional parameters afterwards.
Our ParseMediaType and FormatMediaType weren't consistent in whether
they permitted Content-Dispositions. Now they both do.
Fixes#11289
Change-Id: Ia75723c9d7adb7f4de0f65482780f823cdadb5bd
Reviewed-on: https://go-review.googlesource.com/17135
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Fix an old bug where media type parameter values could be escaped by
either double quotes (per the spec) or single quotes (due to my bug).
The original bug was introduced by me in git rev 90e4ece3
(https://golang.org/cl/4430049) in April 2011 when adding more tests
from http://greenbytes.de/tech/tc2231/ and misinterpreting the
expected value of test "attwithfntokensq" and not apparently thinking
about it enough.
No known spec or existing software produces or expects single quotes
around values. In fact, it would have be a parsing ambiguity if it
were allowed: the string `a=', b='` could parse as two keys "a" and
"b" both with value "'", or it could be parse as a single key "a" with
value "', b=".
Fixes#11291
Change-Id: I6de58009dd47dcabb120b017245d237cb7b1e89a
Reviewed-on: https://go-review.googlesource.com/17136
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
As specified by RFC 2047 section 2, encoded-words may not be more than
75 characters long.
We only enforce this rule when the charset is UTF-8, since multi-bytes
characters must not be split accross encoded-words (see section 5.3).
Fixes#12300
Change-Id: I72a43fc3fe6ddeb3dab54dcdce0837d7ebf658f0
Reviewed-on: https://go-review.googlesource.com/14957
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The case fixed by this change happens when, in func (pr partReader)
Read, the Peek happens to read so that peek looks like:
"somedata\r\n--Boundary\r"
peekBufferSeparatorIndex was returning (-1, false) because it didn't
find the trailing '\n'.
This was wrong because:
1) It didn't match the documentation: as "\r\n--Boundary" was found, it
should return the index of that pattern, not -1.
2) It lead to an nCopy cut such as:
"somedata\r| |\n--Boundary\r" instead of "somedata| |\r\n--Boundary\r"
which made the subsequent Read miss the boundary, and eventually end
with a "return 0, io.ErrUnexpectedEOF" case, as reported in:
https://github.com/camlistore/camlistore/issues/642
Change-Id: I1ba78a741bc0c7719e160add9cca932d10f8a615
Reviewed-on: https://go-review.googlesource.com/15269
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
When parsing the multipart data, if the delimiter appears but doesn't
finish with -- or \n or \r\n, it assumes the data can be consumed. This
is incorrect when the peeking buffer finishes with --delimiter-
Fixes#12662
Change-Id: I329556a9a206407c0958289bf7a9009229120bb9
Reviewed-on: https://go-review.googlesource.com/14652
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
It was correct for an early version of the CL which introduced the
type, but later versions of the CL changed the behavior without
updating the documentation.
Fixes#12568
Change-Id: Ia4090a02ba122e9f8317ed86c4c9839ae2c539e0
Reviewed-on: https://go-review.googlesource.com/14496
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.
I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.
Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
The names of examples were wrong so they were not shown in
the documentation.
Change-Id: Ib1b985b44d2e056c38c008a591cb441e422c4717
Reviewed-on: https://go-review.googlesource.com/10404
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This CL copies golang.org/x/sys/windows/registry into
internal/syscall/windows/registry (minus KeyInfo.ModTime to prevent
dependency cycles). New registry package is used in mime and time
packages instead of calling Windows API directly.
Change-Id: I965a5a41d4739b3ba38e539a7b8d96d3223e3d56
Reviewed-on: https://go-review.googlesource.com/9271
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
It is not needed right now, but it will allow more flexibility in
the future.
Fixes#10472
Change-Id: I2eaea70abeca5ed10f89b0b2dfdabdac376a0a41
Reviewed-on: https://go-review.googlesource.com/8964
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Don't test so much at once.
Fixes#10278
Change-Id: I32a9cb81a3cffecc7ce4f83c35a4b589bcd3a9f7
Reviewed-on: https://go-review.googlesource.com/8213
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Added the inverse of TypeByExtension for discovering an appropriate
extensions for a given MIME type.
Fixes#10144
Change-Id: I6a80e1af3db5d45ad6a4c7ff4ccfdf6a4f424367
Reviewed-on: https://go-review.googlesource.com/7444
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
RFC 2045 says:
An "=" followed by two hexadecimal digits, one or both
of which are lowercase letters in "abcdef", is formally
illegal. A robust implementation might choose to
recognize them as the corresponding uppercase letters.
https://tools.ietf.org/html/rfc2045#page-22
Change-Id: Ibb4b1e4b8bf4fa65ff895ba486a931d90308bf70
Reviewed-on: https://go-review.googlesource.com/7891
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Since there is internal usage of svg files in cmd/trace served via
HTTP, add it to the (small) map of mime types.
MIME type as documented at http://www.w3.org/TR/SVG11/mimereg.html
Change-Id: If14f07cbe2e55d8d68af663f30920a530e2e7974
Reviewed-on: https://go-review.googlesource.com/7942
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit creates the mime/quotedprintable package. It moves and
exports the QP reader of mime/internal/quotedprintable.
The code is almost unchanged to preserve the commit history.
Updates #4943
Change-Id: I4b7b5a2a40a4c84346d42e4cdd2c11a91b28f9e3
Reviewed-on: https://go-review.googlesource.com/5940
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The code concerning quoted-printable encoding (RFC 2045) and its
variant for MIME headers (RFC 2047) is currently spread in
mime/multipart and net/mail. It is also not exported.
This commit is the first step to fix that issue. It moves the
quoted-printable decoding code from mime/multipart to
mime/internal/quotedprintable. The exposed API is unchanged.
Concerns #4943.
Change-Id: I11352afbb2edb4d6ef62870b9bc5c87c639eff12
Reviewed-on: https://go-review.googlesource.com/1810
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>