-
-
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.
Added Experimental/MimeParser test for content with mixed line endings
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3411,6 +3411,44 @@ This is some raw data. | |
} | ||
} | ||
|
||
[Test] | ||
public void TestMimePartContentWithMixedLineEndings () | ||
{ | ||
string text = "From: [email protected]\r\nTo: [email protected]\r\nSubject: content with mixed line endings\r\nDate: Sat, Dec 21 2024 09:12:42 -0500\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is a normal line of text.\r\nThis line ends with a bare LF.\nAnd this line endds with CRLF.\r\n"; | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<TextPart> (), "Expected body of the message to be text/plain"); | ||
var body = (TextPart) message.Body; | ||
|
||
Assert.That (body.Headers[HeaderId.ContentType], Is.EqualTo ("text/plain; charset=utf-8")); | ||
Assert.That (body.ContentType.Charset, Is.EqualTo ("utf-8")); | ||
Assert.That (body.Text, Is.EqualTo ("This is a normal line of text.\r\nThis line ends with a bare LF.\r\nAnd this line endds with CRLF.\r\n")); | ||
Assert.That (body.Content.NewLineFormat, Is.EqualTo (NewLineFormat.Mixed)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestMimePartContentWithMixedLineEndingsAsync () | ||
{ | ||
string text = "From: [email protected]\r\nTo: [email protected]\r\nSubject: content with mixed line endings\r\nDate: Sat, Dec 21 2024 09:12:42 -0500\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is a normal line of text.\r\nThis line ends with a bare LF.\nAnd this line endds with CRLF.\r\n"; | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<TextPart> (), "Expected body of the message to be text/plain"); | ||
var body = (TextPart) message.Body; | ||
|
||
Assert.That (body.Headers[HeaderId.ContentType], Is.EqualTo ("text/plain; charset=utf-8")); | ||
Assert.That (body.ContentType.Charset, Is.EqualTo ("utf-8")); | ||
Assert.That (body.Text, Is.EqualTo ("This is a normal line of text.\r\nThis line ends with a bare LF.\r\nAnd this line endds with CRLF.\r\n")); | ||
Assert.That (body.Content.NewLineFormat, Is.EqualTo (NewLineFormat.Mixed)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestGarbageBeforeMessageHeaders () | ||
{ | ||
|
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 |
---|---|---|
|
@@ -3481,6 +3481,44 @@ This is some raw data. | |
} | ||
} | ||
|
||
[Test] | ||
public void TestMimePartContentWithMixedLineEndings () | ||
{ | ||
string text = "From: [email protected]\r\nTo: [email protected]\r\nSubject: content with mixed line endings\r\nDate: Sat, Dec 21 2024 09:12:42 -0500\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is a normal line of text.\r\nThis line ends with a bare LF.\nAnd this line endds with CRLF.\r\n"; | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new MimeParser (stream, MimeFormat.Entity); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<TextPart> (), "Expected body of the message to be text/plain"); | ||
var body = (TextPart) message.Body; | ||
|
||
Assert.That (body.Headers[HeaderId.ContentType], Is.EqualTo ("text/plain; charset=utf-8")); | ||
Assert.That (body.ContentType.Charset, Is.EqualTo ("utf-8")); | ||
Assert.That (body.Text, Is.EqualTo ("This is a normal line of text.\r\nThis line ends with a bare LF.\r\nAnd this line endds with CRLF.\r\n")); | ||
Assert.That (body.Content.NewLineFormat, Is.EqualTo (NewLineFormat.Mixed)); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestMimePartContentWithMixedLineEndingsAsync () | ||
{ | ||
string text = "From: [email protected]\r\nTo: [email protected]\r\nSubject: content with mixed line endings\r\nDate: Sat, Dec 21 2024 09:12:42 -0500\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is a normal line of text.\r\nThis line ends with a bare LF.\nAnd this line endds with CRLF.\r\n"; | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new MimeParser (stream, MimeFormat.Entity); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<TextPart> (), "Expected body of the message to be text/plain"); | ||
var body = (TextPart) message.Body; | ||
|
||
Assert.That (body.Headers[HeaderId.ContentType], Is.EqualTo ("text/plain; charset=utf-8")); | ||
Assert.That (body.ContentType.Charset, Is.EqualTo ("utf-8")); | ||
Assert.That (body.Text, Is.EqualTo ("This is a normal line of text.\r\nThis line ends with a bare LF.\r\nAnd this line endds with CRLF.\r\n")); | ||
Assert.That (body.Content.NewLineFormat, Is.EqualTo (NewLineFormat.Mixed)); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestGarbageBeforeMessageHeaders () | ||
{ | ||
|