Browse Source

don't consider "\n" part of boundary

flashmob 6 years ago
parent
commit
03ad4ac09a
3 changed files with 10 additions and 17 deletions
  1. 1 1
      backends/gateway.go
  2. 1 1
      mail/mime/mime.go
  3. 8 15
      mail/mime/mime_test.go

+ 1 - 1
backends/gateway.go

@@ -602,8 +602,8 @@ func (gw *BackendGateway) workDispatcher(
 				err := stream.open(msg.e)
 				if err == nil {
 					var buf []byte
+					// TODO make the buffer configurable
 					buf = make([]byte, 1024*4)
-					buf = make([]byte, 210)
 					if msg.e.Values["size"], err = io.CopyBuffer(stream, msg.r, buf); err != nil {
 						Log().WithError(err).Error("stream writing failed")
 					}

+ 1 - 1
mail/mime/mime.go

@@ -242,7 +242,7 @@ func (p *Parser) boundary(contentBoundary string) (end bool, err error) {
 	if len(contentBoundary) < 1 {
 		err = errors.New("content boundary too short")
 	}
-	boundary := "\n" + doubleDash + contentBoundary
+	boundary := doubleDash + contentBoundary
 	p.boundaryMatched = 0
 	for {
 		if i := bytes.Index(p.buf[p.pos:], []byte(boundary)); i > -1 {

+ 8 - 15
mail/mime/mime_test.go

@@ -111,15 +111,6 @@ This
 	}
 	if _, err := p.boundary(h.ContentBoundary); err != nil {
 		t.Error(err)
-	} else {
-		//_ = part
-		//p.addPart(part)
-
-		//nextPart := newPart()
-		//err = p.body(part)
-		//if err != nil {
-		//	t.Error(err)
-		//}
 	}
 }
 
@@ -137,7 +128,10 @@ func TestBoundary(t *testing.T) {
 	if err != nil && err != io.EOF {
 		t.Error(err)
 	}
-	fmt.Println(string(test[:p.lastBoundaryPos]))
+	body := string(test[:p.lastBoundaryPos])
+	if body != "The quick brown fo" {
+		t.Error("p.lastBoundaryPos seems incorrect")
+	}
 
 	// at the end (with the -- postfix)
 	p.inject([]byte("The quick brown fox jumped over the lazy dog---wololo---\n"))
@@ -146,9 +140,6 @@ func TestBoundary(t *testing.T) {
 		t.Error(err)
 	}
 
-	//for c := p.next(); c != 0; c = p.next() {
-	//} // drain
-
 	// the boundary with an additional buffer in between
 	p.inject([]byte("The quick brown fox jumped over the lazy dog"),
 		[]byte("this is the middle"),
@@ -161,7 +152,6 @@ func TestBoundary(t *testing.T) {
 
 }
 
-// todo: make sure next() advances properly
 func TestBoundarySplit(t *testing.T) {
 	p = NewMimeParser()
 	var err error
@@ -177,7 +167,10 @@ func TestBoundarySplit(t *testing.T) {
 		t.Error(err)
 	}
 
-	fmt.Println(string([]byte("The quick brown fox jumped ov---wolo")[:p.lastBoundaryPos]))
+	body := string([]byte("The quick brown fox jumped ov---wolo")[:p.lastBoundaryPos])
+	if body != "The quick brown fox jumped ov" {
+		t.Error("p.lastBoundaryPos value seems incorrect")
+	}
 
 	// boundary has a space, pointer advanced before, and is split over multiple slices
 	part.ContentBoundary = "XXXXboundary text" // 17 chars