~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/mime/multipart/multipart.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
type Part struct {
29
29
        // The headers of the body, if any, with the keys canonicalized
30
30
        // in the same fashion that the Go http.Request headers are.
31
 
        // i.e. "foo-bar" changes case to "Foo-Bar"
 
31
        // For example, "foo-bar" changes case to "Foo-Bar"
 
32
        //
 
33
        // As a special case, if the "Content-Transfer-Encoding" header
 
34
        // has a value of "quoted-printable", that header is instead
 
35
        // hidden from this map and the body is transparently decoded
 
36
        // during Read calls.
32
37
        Header textproto.MIMEHeader
33
38
 
34
39
        buffer    *bytes.Buffer
37
42
 
38
43
        disposition       string
39
44
        dispositionParams map[string]string
 
45
 
 
46
        // r is either a reader directly reading from mr, or it's a
 
47
        // wrapper around such a reader, decoding the
 
48
        // Content-Transfer-Encoding
 
49
        r io.Reader
40
50
}
41
51
 
42
52
// FormName returns the name parameter if p has a Content-Disposition
71
81
        }
72
82
}
73
83
 
74
 
// NewReader creates a new multipart Reader reading from r using the
 
84
// NewReader creates a new multipart Reader reading from reader using the
75
85
// given MIME boundary.
76
86
func NewReader(reader io.Reader, boundary string) *Reader {
77
87
        b := []byte("\r\n--" + boundary + "--")
94
104
        if err := bp.populateHeaders(); err != nil {
95
105
                return nil, err
96
106
        }
 
107
        bp.r = partReader{bp}
 
108
        const cte = "Content-Transfer-Encoding"
 
109
        if bp.Header.Get(cte) == "quoted-printable" {
 
110
                bp.Header.Del(cte)
 
111
                bp.r = newQuotedPrintableReader(bp.r)
 
112
        }
97
113
        return bp, nil
98
114
}
99
115
 
109
125
// Read reads the body of a part, after its headers and before the
110
126
// next part (if any) begins.
111
127
func (p *Part) Read(d []byte) (n int, err error) {
 
128
        return p.r.Read(d)
 
129
}
 
130
 
 
131
// partReader implements io.Reader by reading raw bytes directly from the
 
132
// wrapped *Part, without doing any Transfer-Encoding decoding.
 
133
type partReader struct {
 
134
        p *Part
 
135
}
 
136
 
 
137
func (pr partReader) Read(d []byte) (n int, err error) {
 
138
        p := pr.p
112
139
        defer func() {
113
140
                p.bytesRead += n
114
141
        }()
243
270
 
244
271
                return nil, fmt.Errorf("multipart: unexpected line in Next(): %q", line)
245
272
        }
246
 
        panic("unreachable")
247
273
}
248
274
 
249
275
// isFinalBoundary returns whether line is the final boundary line
250
 
// indiciating that all parts are over.
 
276
// indicating that all parts are over.
251
277
// It matches `^--boundary--[ \t]*(\r\n)?$`
252
278
func (mr *Reader) isFinalBoundary(line []byte) bool {
253
279
        if !bytes.HasPrefix(line, mr.dashBoundaryDash) {