Skip to content

Commit

Permalink
Merge branch 'feature/RootBoundary' of https://github.com/philipyaz/e…
Browse files Browse the repository at this point in the history
…nmime into philipyaz-feature/RootBoundary
  • Loading branch information
jhillyerd committed Nov 27, 2017
2 parents 4eeb33d + a150bb6 commit 5bd2baf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions part.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ func ReadParts(r io.Reader) (*Part, error) {
if strings.HasPrefix(mediatype, ctMultipartPrefix) {
// Content is multipart, parse it
boundary := params[hpBoundary]
err = parseParts(root, br, boundary)
root.boundary = boundary
err = parseParts(root, br)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -215,7 +216,7 @@ func parseBadContentType(ctype, sep string) string {
}

// parseParts recursively parses a mime multipart document and sets each Part's PartID.
func parseParts(parent *Part, reader *bufio.Reader, boundary string) error {
func parseParts(parent *Part, reader *bufio.Reader) error {
var prevSibling *Part

firstRecursion := parent.Parent == nil
Expand All @@ -227,7 +228,7 @@ func parseParts(parent *Part, reader *bufio.Reader, boundary string) error {
var indexPartID int = 0

// Loop over MIME parts
br := newBoundaryReader(reader, boundary)
br := newBoundaryReader(reader, parent.boundary)
for {

indexPartID++
Expand Down Expand Up @@ -265,10 +266,10 @@ func parseParts(parent *Part, reader *bufio.Reader, boundary string) error {
owner.addWarning(
errorMissingBoundary,
"Boundary %q was not closed correctly",
boundary)
parent.boundary)
break
}
return fmt.Errorf("Error at boundary %v: %v", boundary, err)
return fmt.Errorf("Error at boundary %v: %v", parent.boundary, err)
}
} else if err != nil {
return err
Expand Down Expand Up @@ -302,7 +303,7 @@ func parseParts(parent *Part, reader *bufio.Reader, boundary string) error {

if p.boundary != "" {
// Content is another multipart
err = parseParts(p, bbr, p.boundary)
err = parseParts(p, bbr)
if err != nil {
return err
}
Expand Down

0 comments on commit 5bd2baf

Please sign in to comment.