-
-
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 message reserialization after prepending headers
Fixes issue #524
- Loading branch information
Showing
2 changed files
with
45 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
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 |
---|---|---|
|
@@ -104,6 +104,40 @@ public void TestArgumentExceptions () | |
Assert.Throws<ArgumentNullException> (() => MimeMessage.CreateFromMailMessage (null)); | ||
} | ||
|
||
[Test] | ||
public void TestPrependHeader () | ||
{ | ||
string rawMessageText = @"Date: Fri, 22 Jan 2016 8:44:05 -0500 (EST) | ||
From: MimeKit Unit Tests <[email protected]> | ||
To: MimeKit Unit Tests <[email protected]> | ||
Subject: This is a test off prepending headers. | ||
Message-Id: <[email protected]> | ||
MIME-Version: 1.0 | ||
Content-Type: text/plain | ||
This is the message body. | ||
".Replace ("\r\n", "\n"); | ||
string expected = "X-Prepended: This is the prepended header\n" + rawMessageText; | ||
|
||
using (var source = new MemoryStream (Encoding.UTF8.GetBytes (rawMessageText))) { | ||
var parser = new MimeParser (source, MimeFormat.Default); | ||
var message = parser.ParseMessage (); | ||
|
||
message.Headers.Insert (0, new Header ("X-Prepended", "This is the prepended header")); | ||
|
||
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 (expected, result, "Reserialized message is not identical to the original."); | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task TestReserialization () | ||
{ | ||
|