This is a difficult question to answer! :-)
If all parts of the message only use
base64 content-transfer-encodings and all the headers are properly encoded (=standard-compliant), you can simply call
Encoding.ASCII.GetString(ms.ToArray()) on the
If one or more message parts use
binary content-transfer-encodings and a non-ASCII charset, things get very complicated. To get a single .NET string that contains all of these parts (each using a different charset), you would have to decode each part using a different charset. This process would produce a representation of the message contents, but it could no longer be called raw. Saving that string into a file would result in a broken message if you attempted to parse it later (unless you exactly reproduce the original charsets in different message parts).
So this leaves us with two options:
1) Get a .NET string representation of the message contents. This would be somewhat readable, but not necessarily a raw representation, as explained above. Also, when saved to a file, it would not produce a MIME-compliant message identical to the original one.
2) Find all message parts that use 8bit or binary content-transfer-encoding and change it to quoted-printable or base64. Find all improperly-encoded headers and fix them to be MIME-compliant. Then, save the message into a
MemoryStream and call
Encoding.ASCII.GetString(ms.ToArray()) to get a .NET string representation of the e-mail. The drawback of this is that the string will be the raw representation of the "fixed" message, not the original one.
If you like any of these options, please let me know. We can write some code that demonstrates how to do that.
By the way, why do you need a string representation of a MIME message? An answer to that question might help in finding the best solution.