jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.
http://www.mimekit.net
MIT License
6.13k stars 815 forks source link

.net core bad cyrillic symbols #528

Closed bloodyroll closed 7 years ago

bloodyroll commented 7 years ago

Hi! I am trying to retrieve messages with Pop3Client. In .net core console application there is a problem with cyrillic symbols in MimeMessage objects. Results of last 10 message subjects in console (with Console.OutputEncoding = Encoding.Unicode;):

Subject: ðÒÏÓØÂÁ! Subject: ïÔÐÒÁ×ËÁ: ëÏÎÃÅÐÃÉÑ E3.Hub 2.0.pptx Subject: FW: E3.Series × Wiki. æÏÒÕÍ E3.Series. Subject: ðÅÒÅÈÏÄÎÉË OTG c USB ÎÁ micro USB Subject: ðÅÞÁÌØÎÁÑ ÄÁÔÁ Subject: E3.Series × Wiki. æÏÒÕÍ E3.Series. Subject: [Zuken E3 GmbH] ZDE551435 Answer to [Panel Sheets (errors)] Subject: Анонс DotNext 2017 Moscow Subject: RE: E3.series файл лицензии до 19 июня Subject: ïÔÐÕÓË

The same code result data in .net framework 4.5.2 console app:

Subject: Просьба! Subject: Отправка: Концепция E3.Hub 2.0.pptx Subject: FW: E3.Series в Wiki. Форум E3.Series. Subject: Переходник OTG c USB на micro USB Subject: Печальная дата Subject: E3.Series в Wiki. Форум E3.Series. Subject: [Zuken E3 GmbH] ZDE551435 Answer to [Panel Sheets (errors)] Subject: Анонс DotNext 2017 Moscow Subject: RE: E3.series файл лицензии до 19 июня Subject: Отпуск

Method code is the same:

using (var client = new Pop3Client(new ProtocolLogger("pop3.log")))
            {
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                client.Connect("webhost.pointcad.ru", 0, true);
                client.AuthenticationMechanisms.Remove("XOAUTH2");

                client.Authenticate("somedomain/somelogin", "somepassword");

                for (int i = 0; i < 10; i++) 
                {
                    var message = client.GetMessage(client.Count - i - 1);

                    Console.WriteLine("Subject: {0}", message.Subject);
                }
                client.Disconnect(true);
            }
jstedfast commented 7 years ago

This suggests the problem is that your .net core installation does not include the proper text encodings. There's nothing MimeKit can do about that.

To test my theory, write a simple test program that tries to get a cyrilic encoding such as koi8-r:

var encoding = System.Text.Encoding.GetEncoding ("koi8-r");

My bet is that you'll get an exception.

bloodyroll commented 7 years ago

thank you for help. Need to install System.Text.Encoding.CodePages package and add:


Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
jstedfast commented 7 years ago

Thanks for the update, that will likely be helpful to others that run into this issue on .NET Core :)