Browse Source

fixed boundary ending position marker

flashmob 6 years ago
parent
commit
ceebf8242a
2 changed files with 6 additions and 11 deletions
  1. 3 9
      backends/s_mime.go
  2. 3 2
      backends/s_mime_test.go

+ 3 - 9
backends/s_mime.go

@@ -247,7 +247,7 @@ func (p *parser) boundary(contentBoundary string) (end bool, err error) {
 			// will wait until we get a new buffer
 
 			p.skip(i)
-			p.lastBoundaryPos = p.msgPos // - uint(len(boundary))
+			p.lastBoundaryPos = p.msgPos - 1 // - uint(len(boundary))
 			p.skip(len(boundary))
 			end, err = p.boundaryEnd()
 			if err != nil {
@@ -290,7 +290,7 @@ func (p *parser) boundary(contentBoundary string) (end bool, err error) {
 					// advance the pointer
 					p.skip(len(boundary) - p.boundaryMatched)
 
-					p.lastBoundaryPos = p.msgPos - uint(len(boundary))
+					p.lastBoundaryPos = p.msgPos - uint(len(boundary)) - 1
 					end, err = p.boundaryEnd()
 					if err != nil {
 						return
@@ -805,10 +805,6 @@ func (p *parser) mime(parent *mimeHeader, depth string) (err error) {
 			if err != nil {
 				return err
 			}
-		} else {
-			moo := p.buf[p.pos:]
-			_ = moo
-			//break
 		}
 		if p.ch == '\n' && p.peek() == '\n' {
 			p.next()
@@ -833,11 +829,9 @@ func (p *parser) mime(parent *mimeHeader, depth string) (err error) {
 				break
 			}
 
-			//return
-		} else {
-
 		}
 		if end, bErr := p.boundary(parent.contentBoundary); bErr != nil {
+			part.endingPosBody = p.lastBoundaryPos
 			return bErr
 		} else if end {
 			part.endingPosBody = p.lastBoundaryPos

+ 3 - 2
backends/s_mime_test.go

@@ -3,6 +3,7 @@ package backends
 import (
 	"bytes"
 	"fmt"
+	"io"
 	"strconv"
 	"testing"
 )
@@ -365,7 +366,7 @@ func TestNestedEmail(t *testing.T) {
 	email = email2
 	p.inject([]byte(email))
 
-	if err := p.mime(nil, ""); err != nil {
+	if err := p.mime(nil, ""); err != nil && err != io.EOF {
 		t.Error(err)
 	}
 	for part := range p.parts {
@@ -378,7 +379,7 @@ func TestNestedEmail(t *testing.T) {
 	//fmt.Println(strings.Index(email, "--D7F------------D7FD5A0B8AB9C65CCDBFA872--"))
 
 	//fmt.Println(email[p.parts[1].startingPosBody:p.parts[1].endingPosBody])
-	i := 6
+	i := 2
 	fmt.Println("**********{" + email[p.parts[i].startingPosBody:p.parts[i].endingPosBody] + "}**********")
 }