Commit 0d4ea0c7 authored by Alexandre Cesaro's avatar Alexandre Cesaro Committed by Brad Fitzpatrick

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/1810Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 10be7975
...@@ -311,7 +311,7 @@ var pkgDeps = map[string][]string{ ...@@ -311,7 +311,7 @@ var pkgDeps = map[string][]string{
"crypto/x509/pkix": {"L4", "CRYPTO-MATH"}, "crypto/x509/pkix": {"L4", "CRYPTO-MATH"},
// Simple net+crypto-aware packages. // 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"}, "net/smtp": {"L4", "CRYPTO", "NET", "crypto/tls"},
// HTTP, kingpin of dependencies. // HTTP, kingpin of dependencies.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// 2. it will pass through a '\r' or '\n' not preceded by '=', consistent // 2. it will pass through a '\r' or '\n' not preceded by '=', consistent
// with other broken QP encoders & decoders. // with other broken QP encoders & decoders.
package multipart package quotedprintable
import ( import (
"bufio" "bufio"
...@@ -23,7 +23,7 @@ type qpReader struct { ...@@ -23,7 +23,7 @@ type qpReader struct {
line []byte // to be consumed before more of br 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{ return &qpReader{
br: bufio.NewReader(r), br: bufio.NewReader(r),
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package multipart package quotedprintable
import ( import (
"bufio" "bufio"
...@@ -65,7 +65,7 @@ func TestQuotedPrintable(t *testing.T) { ...@@ -65,7 +65,7 @@ func TestQuotedPrintable(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
var buf bytes.Buffer 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 { if got := buf.String(); got != tt.want {
t.Errorf("for %q, got %q; want %q", tt.in, 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) { ...@@ -116,7 +116,7 @@ func TestQPExhaustive(t *testing.T) {
return return
} }
buf.Reset() buf.Reset()
_, err := io.Copy(&buf, newQuotedPrintableReader(strings.NewReader(s))) _, err := io.Copy(&buf, NewReader(strings.NewReader(s)))
if err != nil { if err != nil {
errStr := err.Error() errStr := err.Error()
if strings.Contains(errStr, "invalid bytes after =:") { if strings.Contains(errStr, "invalid bytes after =:") {
......
...@@ -19,6 +19,7 @@ import ( ...@@ -19,6 +19,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"mime" "mime"
"mime/internal/quotedprintable"
"net/textproto" "net/textproto"
) )
...@@ -111,7 +112,7 @@ func newPart(mr *Reader) (*Part, error) { ...@@ -111,7 +112,7 @@ func newPart(mr *Reader) (*Part, error) {
const cte = "Content-Transfer-Encoding" const cte = "Content-Transfer-Encoding"
if bp.Header.Get(cte) == "quoted-printable" { if bp.Header.Get(cte) == "quoted-printable" {
bp.Header.Del(cte) bp.Header.Del(cte)
bp.r = newQuotedPrintableReader(bp.r) bp.r = quotedprintable.NewReader(bp.r)
} }
return bp, nil return bp, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment