Skip to content

Commit

Permalink
Add a test for boundaries terminated by semicolon
Browse files Browse the repository at this point in the history
References #13
  • Loading branch information
blabber committed Oct 7, 2018
1 parent 655029d commit e5c5e79
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,71 @@ This is the second email in a test of boundaries.
}
}

func TestScanMessageWithBoundarySemicolon(t *testing.T) {
mbox := `From [email protected] Tue Jun 7 05:46:46 2016
From: Sender <[email protected]>
To: foo/bar <[email protected]>
Message-ID: <foo/bar/1/[email protected]>
Subject: Re: [foo/bar] [question] Baz? (#1)
Content-Type: multipart/alternative; boundary="--==_mimepart_5755da228145a_38da3facdf97329c42987b";
MIME-Version: 1.0
----==_mimepart_5755da228145a_38da3facdf97329c42987b
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Blah blah
----==_mimepart_5755da228145a_38da3facdf97329c42987b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 8bit
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<p>Blah blah</p>
----==_mimepart_5755da228145a_38da3facdf97329c42987b--
From [email protected] Tue Jun 7 05:52:15 2016
From: Author <[email protected]>
To: frob/blab <[email protected]>
Message-ID: <frob/blab/1/[email protected]>
Subject: Re: [frob/blab] [question] Bling? (#1)
Content-Type: multipart/alternative; boundary="--==_mimepart_5755db739a819_79783f996b0172c04025ee";
MIME-Version: 1.0
----==_mimepart_5755db739a819_79783f996b0172c04025ee
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Blah blah
----==_mimepart_5755db739a819_79783f996b0172c04025ee
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 8bit
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<p>Blah blah</p>
----==_mimepart_5755db739a819_79783f996b0172c04025ee--
`
expected := 2

b := bytes.NewBufferString(mbox)
m := NewScanner(b)

parsedMessages := 0
for m.Next() {
parsedMessages += 1
}

if parsedMessages != expected {
t.Errorf("Expected: %d; got: %d", expected, parsedMessages)
}
}

func ExampleScanner() {
r := strings.NewReader(`From herp.derp at example.com Thu Jan 1 00:00:01 2015
From: herp.derp at example.com (Herp Derp)
Expand Down

0 comments on commit e5c5e79

Please sign in to comment.