Skip to content

Commit

Permalink
More unit tests for Experimental/MimeParser
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Dec 21, 2024
1 parent dc64351 commit 56a2c5c
Show file tree
Hide file tree
Showing 2 changed files with 568 additions and 0 deletions.
256 changes: 256 additions & 0 deletions UnitTests/ExperimentalMimeParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down
Loading

0 comments on commit 56a2c5c

Please sign in to comment.