-
-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More unit tests for Experimental/MimeParser
- Loading branch information
Showing
2 changed files
with
568 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 |
---|---|---|
|
@@ -2605,6 +2605,262 @@ public async Task TestMessageRfc822WithMungedFromMarkerBeforeMessageAsync () | |
} | ||
} | ||
|
||
[Test] | ||
public void TestMessageRfc822WithMungedFromMarkerEOF () | ||
{ | ||
string text = @"From - Fri Mar 7 02:51:22 1997 | ||
Return-Path: <[email protected]> | ||
Received: from gruntle ([205.217.227.10]) by dredd.mcom.com | ||
(Netscape Mail Server v2.02) with SMTP id AAA4040 | ||
for <[email protected]>; Fri, 7 Mar 1997 02:50:37 -0800 | ||
Sender: [email protected] (Jamie Zawinski) | ||
Message-ID: <[email protected]> | ||
Date: Fri, 07 Mar 1997 02:50:39 -0800 | ||
From: Jamie Zawinski <[email protected]> | ||
Organization: Netscape Communications Corporation, Mozilla Division | ||
X-Mailer: Mozilla 3.01 (X11; U; IRIX 6.2 IP22) | ||
MIME-Version: 1.0 | ||
To: Jamie Zawinski <[email protected]> | ||
Subject: forwarded encrypted message | ||
Content-Type: message/rfc822; name=""smime18-encrypted.msg"" | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: inline; filename=""smime18-encrypted.msg"" | ||
X-Mozilla-Status: 0001 | ||
Content-Length: 2812 | ||
>From - Fri Dec 13 15:01:21 1996".Replace ("\r\n", "\n"); | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From - Fri Dec 13 15:01:21 1996")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text.Replace ("\n", "\r\n")), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From - Fri Dec 13 15:01:21 1996")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestMessageRfc822WithMungedFromMarkerEOFAsync () | ||
{ | ||
string text = @"From - Fri Mar 7 02:51:22 1997 | ||
Return-Path: <[email protected]> | ||
Received: from gruntle ([205.217.227.10]) by dredd.mcom.com | ||
(Netscape Mail Server v2.02) with SMTP id AAA4040 | ||
for <[email protected]>; Fri, 7 Mar 1997 02:50:37 -0800 | ||
Sender: [email protected] (Jamie Zawinski) | ||
Message-ID: <[email protected]> | ||
Date: Fri, 07 Mar 1997 02:50:39 -0800 | ||
From: Jamie Zawinski <[email protected]> | ||
Organization: Netscape Communications Corporation, Mozilla Division | ||
X-Mailer: Mozilla 3.01 (X11; U; IRIX 6.2 IP22) | ||
MIME-Version: 1.0 | ||
To: Jamie Zawinski <[email protected]> | ||
Subject: forwarded encrypted message | ||
Content-Type: message/rfc822; name=""smime18-encrypted.msg"" | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: inline; filename=""smime18-encrypted.msg"" | ||
X-Mozilla-Status: 0001 | ||
Content-Length: 2812 | ||
>From - Fri Dec 13 15:01:21 1996".Replace ("\r\n", "\n"); | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From - Fri Dec 13 15:01:21 1996")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text.Replace ("\n", "\r\n")), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From - Fri Dec 13 15:01:21 1996")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestMessageRfc822WithTruncatedMungedFromMarker () | ||
{ | ||
string text = @"From - Fri Mar 7 02:51:22 1997 | ||
Return-Path: <[email protected]> | ||
Received: from gruntle ([205.217.227.10]) by dredd.mcom.com | ||
(Netscape Mail Server v2.02) with SMTP id AAA4040 | ||
for <[email protected]>; Fri, 7 Mar 1997 02:50:37 -0800 | ||
Sender: [email protected] (Jamie Zawinski) | ||
Message-ID: <[email protected]> | ||
Date: Fri, 07 Mar 1997 02:50:39 -0800 | ||
From: Jamie Zawinski <[email protected]> | ||
Organization: Netscape Communications Corporation, Mozilla Division | ||
X-Mailer: Mozilla 3.01 (X11; U; IRIX 6.2 IP22) | ||
MIME-Version: 1.0 | ||
To: Jamie Zawinski <[email protected]> | ||
Subject: forwarded encrypted message | ||
Content-Type: message/rfc822; name=""smime18-encrypted.msg"" | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: inline; filename=""smime18-encrypted.msg"" | ||
X-Mozilla-Status: 0001 | ||
Content-Length: 2812 | ||
>From".Replace ("\r\n", "\n"); | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text.Replace ("\n", "\r\n")), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = parser.ParseMessage (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestMessageRfc822WithTruncatedMungedFromMarkerAsync () | ||
{ | ||
string text = @"From - Fri Mar 7 02:51:22 1997 | ||
Return-Path: <[email protected]> | ||
Received: from gruntle ([205.217.227.10]) by dredd.mcom.com | ||
(Netscape Mail Server v2.02) with SMTP id AAA4040 | ||
for <[email protected]>; Fri, 7 Mar 1997 02:50:37 -0800 | ||
Sender: [email protected] (Jamie Zawinski) | ||
Message-ID: <[email protected]> | ||
Date: Fri, 07 Mar 1997 02:50:39 -0800 | ||
From: Jamie Zawinski <[email protected]> | ||
Organization: Netscape Communications Corporation, Mozilla Division | ||
X-Mailer: Mozilla 3.01 (X11; U; IRIX 6.2 IP22) | ||
MIME-Version: 1.0 | ||
To: Jamie Zawinski <[email protected]> | ||
Subject: forwarded encrypted message | ||
Content-Type: message/rfc822; name=""smime18-encrypted.msg"" | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: inline; filename=""smime18-encrypted.msg"" | ||
X-Mozilla-Status: 0001 | ||
Content-Length: 2812 | ||
>From".Replace ("\r\n", "\n"); | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
|
||
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text.Replace ("\n", "\r\n")), false)) { | ||
var parser = new ExperimentalMimeParser (ParserOptions.Default, stream, MimeFormat.Mbox); | ||
var message = await parser.ParseMessageAsync (); | ||
|
||
Assert.That (message.Body, Is.InstanceOf<MessagePart> (), "Expected top-level to be a MessagePart"); | ||
var rfc822 = (MessagePart) message.Body; | ||
|
||
Assert.That (rfc822.ContentType.Name, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentType.Name"); | ||
Assert.That (rfc822.ContentDisposition.Disposition, Is.EqualTo ("inline"), "MessagePart.ContentDisposition.DIsposition"); | ||
Assert.That (rfc822.ContentDisposition.FileName, Is.EqualTo ("smime18-encrypted.msg"), "MessagePart.ContentDisposition.FileName"); | ||
//Assert.That (rfc822.ContentTransferEncoding, Is.EqualTo (ContentEncoding.SevenBit), "MessagePart.ContentTransferEncoding"); | ||
|
||
Assert.That (rfc822.Message, Is.Not.Null, "MessagePart.Message"); | ||
Assert.That (rfc822.Message.MboxMarker, Is.Not.Null, "MessagePart.Message.MboxMarker"); | ||
Assert.That (Encoding.ASCII.GetString (rfc822.Message.MboxMarker), Is.EqualTo (">From")); | ||
Assert.That (rfc822.Message.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Headers.Count"); | ||
Assert.That (rfc822.Message.Body.Headers.Count, Is.EqualTo (0), "MessagePart.Message.Body.Headers.Count"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestMessageRfc822 () | ||
{ | ||
|
Oops, something went wrong.