Sicos1977 / MSGReader

C# Outlook MSG file reader without the need for Outlook
http://sicos1977.github.io/MSGReader
MIT License
478 stars 168 forks source link

Error reading Windows-1252 in .NET6, register code page provider by default? #287

Closed MichaelPeter closed 2 years ago

MichaelPeter commented 2 years ago

Describe the bug .NET Core/.Net5/.Net6 does not support Windows encoding by default. But German outlook seems to use that by default for msg files. This can be fixed by adding a reference to System.Text.Encoding.CodePages and registering the encoding like here: https://stackoverflow.com/questions/50858209/system-notsupportedexception-no-data-is-available-for-

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

Since this library should be able to open all kinds of .msg should this maybe be done already by default? Or add at least a comment in documenation?

To Reproduce call for the attached .msg file

using (var msg = new Storage.Message(stream))
{
   string bodyHtml = msg.BodyHtml;
}

test.mail.with.picture.and.listing.msg.txt

Sicos1977 commented 2 years ago

Added with this commit Encoding.RegisterProvider