Browse Source

do not nest if content-boundary of child is equal to parent
fixes to peek()
branch counts, boundary counts

flashmob 6 years ago
parent
commit
943124ef9a
2 changed files with 41 additions and 12 deletions
  1. 21 12
      mail/mime/mime.go
  2. 20 0
      mail/mime/mime_test.go

+ 21 - 12
mail/mime/mime.go

@@ -196,7 +196,6 @@ func (p *Parser) peek() byte {
 		// reached the end? Wait for more bytes to consume
 		// reached the end? Wait for more bytes to consume
 		if p.pos+p.peekOffset >= len(p.buf) {
 		if p.pos+p.peekOffset >= len(p.buf) {
 			if !p.more() {
 			if !p.more() {
-				p.ch = 0
 				return 0
 				return 0
 			}
 			}
 		}
 		}
@@ -371,7 +370,7 @@ func (p *Parser) transportPadding() (err error) {
 			p.next()
 			p.next()
 			p.next()
 			p.next()
 		} else {
 		} else {
-			if p.ch == 0 {
+			if c == 0 {
 				err = io.EOF
 				err = io.EOF
 			}
 			}
 			return
 			return
@@ -826,7 +825,11 @@ func (p *Parser) mime(depth string, count int, cb string) (err error) {
 		p.next()
 		p.next()
 	}
 	}
 	part.StartingPosBody = p.msgPos
 	part.StartingPosBody = p.msgPos
+	skip := false
 	if part.ContentBoundary != "" {
 	if part.ContentBoundary != "" {
+		if cb == part.ContentBoundary {
+			skip = true
+		}
 		cb = part.ContentBoundary
 		cb = part.ContentBoundary
 	}
 	}
 
 
@@ -839,33 +842,39 @@ func (p *Parser) mime(depth string, count int, cb string) (err error) {
 	}
 	}
 
 
 	for {
 	for {
-		count++
 		if cb != "" {
 		if cb != "" {
-			if end, bErr := p.boundary(cb); bErr != nil {
-				part.EndingPosBody = p.lastBoundaryPos
-				return bErr
-			} else if end {
-				bErr = boundaryEnd{cb}
+			if end, bErr := p.boundary(cb); bErr != nil || end == true {
 				part.EndingPosBody = p.lastBoundaryPos
 				part.EndingPosBody = p.lastBoundaryPos
+				if end {
+					bErr = boundaryEnd{cb}
+
+					return bErr
+				}
 				return bErr
 				return bErr
 			}
 			}
-			part.EndingPosBody = p.lastBoundaryPos
+			part.EndingPosBody = p.msgPos
 		}
 		}
 
 
 		ct := part.ContentType
 		ct := part.ContentType
-		if ct != nil && (ct.superType == "multipart" || ct.superType == "message") {
+		if !skip && ct != nil && (ct.superType == "multipart" || ct.superType == "message") {
 			// start a new branch (count is 1)
 			// start a new branch (count is 1)
-			err = p.mime(partID, 1, cb)
+			err = p.mime(partID, count, cb)
 			part.EndingPosBody = p.msgPos // good?
 			part.EndingPosBody = p.msgPos // good?
 			if err != nil {
 			if err != nil {
 				if v, ok := err.(boundaryEnd); ok && v.Error() != cb {
 				if v, ok := err.(boundaryEnd); ok && v.Error() != cb {
 					// we are back to the upper level, stop propagating the content-boundary 'end' error
 					// we are back to the upper level, stop propagating the content-boundary 'end' error
+					count++
 					continue
 					continue
 				}
 				}
+				if depth == "" {
+					part.EndingPosBody = p.lastBoundaryPos
+				}
+
 				return
 				return
 			}
 			}
 		} else {
 		} else {
-			// new sibling for this node (count has incremented)
+			// new sibling for this node
+			count++
 			err = p.mime(depth, count, cb)
 			err = p.mime(depth, count, cb)
 			return
 			return
 		}
 		}

+ 20 - 0
mail/mime/mime_test.go

@@ -491,6 +491,26 @@ TmV4dFBhcnRfMDAwX0FFNkJfNzI1RTA5QUYuODhCN0Y5MzQtLQ0K
 `
 `
 
 
 /*
 /*
+
+email 1
+Array
+(
+    [0] => 1
+    [1] => 1.1
+    [2] => 1.2
+    [3] => 1.2.1
+    [4] => 1.2.1.1
+    [5] => 1.2.1.2
+)
+0 =>744 to 3029
+1 =>907 to 968
+2 =>1101 to 3029
+3 =>1889 to 3029
+4 =>2052 to 2402
+5 =>2594 to 2983
+
+email 2
+
 1  0  121  1763
 1  0  121  1763
 1.1  207  302  628
 1.1  207  302  628
 1.1.1  343  428  445
 1.1.1  343  428  445