1
0
mirror of https://github.com/golang/go synced 2024-11-05 15:36:09 -07:00

mime/multipart: moved some code to mime/internal/quotedprintable

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>
This commit is contained in:
Alexandre Cesaro 2014-12-18 21:33:34 +01:00 committed by Brad Fitzpatrick
parent 10be797578
commit 0d4ea0c70d
4 changed files with 8 additions and 7 deletions

View File

@ -311,7 +311,7 @@ var pkgDeps = map[string][]string{
"crypto/x509/pkix": {"L4", "CRYPTO-MATH"},
// Simple net+crypto-aware packages.
"mime/multipart": {"L4", "OS", "mime", "crypto/rand", "net/textproto"},
"mime/multipart": {"L4", "OS", "mime", "crypto/rand", "net/textproto", "mime/internal/quotedprintable"},
"net/smtp": {"L4", "CRYPTO", "NET", "crypto/tls"},
// HTTP, kingpin of dependencies.

View File

@ -8,7 +8,7 @@
// 2. it will pass through a '\r' or '\n' not preceded by '=', consistent
// with other broken QP encoders & decoders.
package multipart
package quotedprintable
import (
"bufio"
@ -23,7 +23,7 @@ type qpReader struct {
line []byte // to be consumed before more of br
}
func newQuotedPrintableReader(r io.Reader) io.Reader {
func NewReader(r io.Reader) io.Reader {
return &qpReader{
br: bufio.NewReader(r),
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package multipart
package quotedprintable
import (
"bufio"
@ -65,7 +65,7 @@ func TestQuotedPrintable(t *testing.T) {
}
for _, tt := range tests {
var buf bytes.Buffer
_, err := io.Copy(&buf, newQuotedPrintableReader(strings.NewReader(tt.in)))
_, err := io.Copy(&buf, NewReader(strings.NewReader(tt.in)))
if got := buf.String(); got != tt.want {
t.Errorf("for %q, got %q; want %q", tt.in, got, tt.want)
}
@ -116,7 +116,7 @@ func TestQPExhaustive(t *testing.T) {
return
}
buf.Reset()
_, err := io.Copy(&buf, newQuotedPrintableReader(strings.NewReader(s)))
_, err := io.Copy(&buf, NewReader(strings.NewReader(s)))
if err != nil {
errStr := err.Error()
if strings.Contains(errStr, "invalid bytes after =:") {

View File

@ -19,6 +19,7 @@ import (
"io"
"io/ioutil"
"mime"
"mime/internal/quotedprintable"
"net/textproto"
)
@ -111,7 +112,7 @@ func newPart(mr *Reader) (*Part, error) {
const cte = "Content-Transfer-Encoding"
if bp.Header.Get(cte) == "quoted-printable" {
bp.Header.Del(cte)
bp.r = newQuotedPrintableReader(bp.r)
bp.r = quotedprintable.NewReader(bp.r)
}
return bp, nil
}