-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Multipart to properly ensure the epilogue ends w/ a new-line wh…
…en EnsureNewLine is true Partial fix for issue #499
- Loading branch information
Showing
2 changed files
with
87 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -398,6 +398,85 @@ ENCODING mime | |
} | ||
} | ||
|
||
[Test] | ||
public async Task TestReserializationEpilogue () | ||
{ | ||
string rawMessageText = @"From: Example Test <[email protected]> | ||
MIME-Version: 1.0 | ||
Content-Type: multipart/mixed; | ||
boundary=""simple boundary"" | ||
This is the preamble. | ||
--simple boundary | ||
Content-TypeS: text/plain | ||
This is a test. | ||
--simple boundary | ||
Content-Type: text/plain | ||
Content-Disposition: attachment | ||
Content-Transfer-Encoding: 7bit | ||
Another test. | ||
--simple boundary-- | ||
This is the epilogue.".Replace ("\r\n", "\n"); | ||
|
||
using (var source = new MemoryStream (Encoding.UTF8.GetBytes (rawMessageText))) { | ||
var parser = new MimeParser (source, MimeFormat.Default); | ||
var message = parser.ParseMessage (); | ||
|
||
using (var serialized = new MemoryStream ()) { | ||
var options = FormatOptions.Default.Clone (); | ||
options.NewLineFormat = NewLineFormat.Unix; | ||
|
||
message.WriteTo (options, serialized); | ||
|
||
var result = Encoding.UTF8.GetString (serialized.ToArray ()); | ||
|
||
Assert.AreEqual (rawMessageText, result, "Reserialized message is not identical to the original."); | ||
} | ||
|
||
using (var serialized = new MemoryStream ()) { | ||
var options = FormatOptions.Default.Clone (); | ||
options.NewLineFormat = NewLineFormat.Unix; | ||
|
||
await message.WriteToAsync (options, serialized); | ||
|
||
var result = Encoding.UTF8.GetString (serialized.ToArray ()); | ||
|
||
Assert.AreEqual (rawMessageText, result, "Reserialized (async) message is not identical to the original."); | ||
} | ||
|
||
using (var serialized = new MemoryStream ()) { | ||
var options = FormatOptions.Default.Clone (); | ||
options.NewLineFormat = NewLineFormat.Unix; | ||
options.EnsureNewLine = true; | ||
|
||
message.WriteTo (options, serialized); | ||
|
||
var result = Encoding.UTF8.GetString (serialized.ToArray ()); | ||
|
||
Assert.AreEqual (rawMessageText + "\n", result, "Reserialized message is not identical to the original (EnsureNewLine)."); | ||
} | ||
|
||
using (var serialized = new MemoryStream ()) { | ||
var options = FormatOptions.Default.Clone (); | ||
options.NewLineFormat = NewLineFormat.Unix; | ||
options.EnsureNewLine = true; | ||
|
||
await message.WriteToAsync (options, serialized); | ||
|
||
var result = Encoding.UTF8.GetString (serialized.ToArray ()); | ||
|
||
Assert.AreEqual (rawMessageText + "\n", result, "Reserialized (async) message is not identical to the original (EnsureNewLine)."); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestMailMessageToMimeMessage () | ||
{ | ||
|