-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed MimeReader/ExperimentalMimeParser to handle really long mbox ma…
…rkers Working on making MimeReader/ExperimentalMimeParser more robust.
- Loading branch information
Showing
5 changed files
with
170 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,6 +405,46 @@ public async Task TestDoubleMboxMarkerAsync () | |
} | ||
} | ||
|
||
[Test] | ||
public void TestReallyLongMboxMarker () | ||
{ | ||
var content = Encoding.ASCII.GetBytes ("\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: test message\r\n\r\nBody text\r\n"); | ||
var marker = "From " + new string ('X', 4092); | ||
|
||
using (var stream = new MemoryStream ()) { | ||
var bytes = Encoding.ASCII.GetBytes (marker); | ||
stream.Write (bytes, 0, bytes.Length); | ||
stream.Write (content, 0, content.Length); | ||
stream.Position = 0; | ||
|
||
var parser = new ExperimentalMimeParser (stream, MimeFormat.Mbox); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Headers.Count, Is.EqualTo (3)); | ||
Assert.That (parser.MboxMarker, Is.EqualTo (marker)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestReallyLongMboxMarkerAsync () | ||
{ | ||
var content = Encoding.ASCII.GetBytes ("\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: test message\r\n\r\nBody text\r\n"); | ||
var marker = "From " + new string ('X', 4092); | ||
|
||
using (var stream = new MemoryStream ()) { | ||
var bytes = Encoding.ASCII.GetBytes (marker); | ||
stream.Write (bytes, 0, bytes.Length); | ||
stream.Write (content, 0, content.Length); | ||
stream.Position = 0; | ||
|
||
var parser = new ExperimentalMimeParser (stream, MimeFormat.Mbox); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Headers.Count, Is.EqualTo (3)); | ||
Assert.That (parser.MboxMarker, Is.EqualTo (marker)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestEmptyMessage () | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -389,6 +389,52 @@ public async Task TestDoubleMboxMarkerAsync () | |
} | ||
} | ||
|
||
[Test] | ||
public void TestReallyLongMboxMarker () | ||
{ | ||
var content = Encoding.ASCII.GetBytes ("\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: test message\r\n\r\nBody text\r\n"); | ||
var marker = "From " + new string ('X', 4092); | ||
|
||
using (var stream = new MemoryStream ()) { | ||
var bytes = Encoding.ASCII.GetBytes (marker); | ||
stream.Write (bytes, 0, bytes.Length); | ||
stream.Write (content, 0, content.Length); | ||
stream.Position = 0; | ||
|
||
// FIXME: Fix MimeParser to handle this as well as ExperimentalMimeParser? | ||
var parser = new MimeParser (stream, MimeFormat.Mbox); | ||
//var message = parser.ParseMessage (); | ||
|
||
//Assert.That (message.Headers.Count, Is.EqualTo (3)); | ||
//Assert.That (parser.MboxMarker, Is.EqualTo (marker)); | ||
|
||
Assert.Throws<FormatException> (() => parser.ParseMessage ()); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestReallyLongMboxMarkerAsync () | ||
{ | ||
var content = Encoding.ASCII.GetBytes ("\r\nFrom: [email protected]\r\nTo: [email protected]\r\nSubject: test message\r\n\r\nBody text\r\n"); | ||
var marker = "From " + new string ('X', 4092); | ||
|
||
using (var stream = new MemoryStream ()) { | ||
var bytes = Encoding.ASCII.GetBytes (marker); | ||
stream.Write (bytes, 0, bytes.Length); | ||
stream.Write (content, 0, content.Length); | ||
stream.Position = 0; | ||
|
||
// FIXME: Fix MimeParser to handle this as well as ExperimentalMimeParser? | ||
var parser = new MimeParser (stream, MimeFormat.Mbox); | ||
//var message = await parser.ParseMessageAsync (); | ||
|
||
//Assert.That (message.Headers.Count, Is.EqualTo (3)); | ||
//Assert.That (parser.MboxMarker, Is.EqualTo (marker)); | ||
|
||
Assert.ThrowsAsync<FormatException> (async () => await parser.ParseMessageAsync ()); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestEmptyMessage () | ||
{ | ||
|