]> Cypherpunks repositories - gostls13.git/commitdiff
mime/multipart: moved some code to mime/internal/quotedprintable
authorAlexandre Cesaro <alexandre.cesaro@gmail.com>
Thu, 18 Dec 2014 20:33:34 +0000 (21:33 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 23 Dec 2014 19:30:02 +0000 (19:30 +0000)
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>
src/go/build/deps_test.go
src/mime/internal/quotedprintable/quotedprintable.go [moved from src/mime/multipart/quotedprintable.go with 97% similarity]
src/mime/internal/quotedprintable/quotedprintable_test.go [moved from src/mime/multipart/quotedprintable_test.go with 97% similarity]
src/mime/multipart/multipart.go

index b74595ea837e39ae3b0569dc01aa898df51c0669..b3c1105156543a78502e95077a629101ffd4d773 100644 (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.
similarity index 97%
rename from src/mime/multipart/quotedprintable.go
rename to src/mime/internal/quotedprintable/quotedprintable.go
index 9ff4ee703ee1d952231ba76441d67cf0a51f1908..2417bf2148bfd4307de1dfeba8abf7ecba8e7c20 100644 (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),
        }
similarity index 97%
rename from src/mime/multipart/quotedprintable_test.go
rename to src/mime/internal/quotedprintable/quotedprintable_test.go
index c4de3eb756634e4b10ab683409f24cff0cc317b1..0c7760f4b9675915409d38ed93d488e846b45a6a 100644 (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 =:") {
index 01a667d930db371efe3576742a1fa6098d72e0d3..3f06c07dc86a788c821e651e29351a86d4f09f01 100644 (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
 }