E-Mail Body Encoding

0 votes
asked Jul 2, 2015 by ertan2002 (120 points)

Hi,

I am using Xamarin.iOs and want to display e-mail. It works very well, but today i found out something wrong regarding encoding..

enter image description here

The email is in german language but seems like chinese..

Well I tried to convert as UTF-8 but not works..

like this

_mail.DefaultCharset = Encoding.UTF8;

and after tried like that

byte[] bytes = Encoding.Default.GetBytes(bodyText);
var myString = Encoding.UTF8.GetString(bytes);

Root.Add(
        new Section()
    {
     new MultilineElement(myString) //(bodyText)
    }

I used sample of rebex mail.

What should I do to solve it?

Applies to: Rebex Secure Mail
commented Jul 2, 2015 by Tomas Knopp (58,890 points)
I am not sure what is going on whether it is a problem directly in Rebex Secure Mail component, or just in the UI of our sample program. To determine what is going on, could you please zip the problematic email and send it to support@rebex.net?

Or if you are unable to share your email, alternatively run this code:

            MailMessage mail = new MailMessage();
            mail.Load("german-mail.eml");

            string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "mail-body.txt");
            File.WriteAllText(filePath, mail.BodyText);

It will load the email and save the mail body text into a text file of your iOS app documents folder. Then please send us the content of the resulting file 'mail-body.txt' or at least look into the file and let us know what you see there. Is there a german human readable text, or still some strange characters? Thanks
commented Jul 3, 2015 by ertan2002 (120 points)
Hey, I used  your code and it seems like that

http://oi57.tinypic.com/14botup.jpg

2 Answers

0 votes
answered Jul 2, 2015 by Tomas Knopp (58,890 points)

Did you see my comment above? Btw, which one of the sample did you use? If you need to download the email from the mail (POP3 or IMAP) server, just call:

string mailPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "mail.eml");
client.GetMessage(_sequenceNumber, mailPath);

It would help us if you could send the saved email back to support@rebex.net. Thank you for your reply.

commented Jul 3, 2015 by ertan2002 (120 points)
Hello, No I am trying to read msg format email, not from pop3/imap service.

Well I downloaded the full samples and used the xamarin.ios/mail/Mail_CS.sln

and copied my email to the "data-mail" folder..

and the result of your app

http://oi59.tinypic.com/2hy81ls.jpg

It is blank.. but in my app it has chinese chars..

never mind, problem is not related with the german. Because I can open other emails which were written in german. The msg file contains some passwords then I cant send you it. I believe that something is wrong with encoding. I do not understand why others work properly.. until now, I just found out this email. But I can open it with outlook and the file is OK.
commented Jul 3, 2015 by Tomas Knopp (58,890 points)
Hello,  and thank you for your replies!
One more request, could you please try running the same code on a standard Windows machine?

             MailMessage mail = new MailMessage();
             mail.Load("mail.eml");

             File.WriteAllText(@"C:\temp\mail-body-dot-net.txt", mail.BodyText);

Running on normal .NET, do you still see the strange characters in the saved file as with Xamarin.iOS or not? This would help us to see whether it is something specific to the Xamarin.iOS platform.

I also have one wild guess that if your Outlook MSG email uses a very strange encoding that you might have to enable the encodings in you Xamarin Studio project as described at https://docs.xamarin.com/guides/ios/advanced_topics/localization_and_internationalization/

Please give the two suggestions a try and let me know the results.
commented Jul 3, 2015 by ertan2002 (120 points)
Hello Tomaš,

this is for the desktop version

http://i.imgur.com/W5tB9Qe.png

and still the same characters..

and I added encodings from xamarin, the result is the same, nothing  changed.
commented Jul 3, 2015 by Tomas Knopp (58,890 points)
Thanks for your reply so it is not related to Xamarin, and it means something is wrong either with the email or with the component, however, we are unable to fix it or add a workaround into the Secure Mail component unless we actually see the probably broken MSG email. If you come accross some email that behaves the same that you are able to share with us, send it to support@rebex.net and we'll be able to help you then.
commented Jul 3, 2015 by ertan2002 (120 points)
okay, thank you for your attention. When I have the same problem with a msg file, I will share it with you.
commented Jul 7, 2015 by Tomas Knopp (58,890 points)
Thank you for sharing the new MSG file with us! we were able to replicate your issue and we'll get back to you via email and also we'll post here when the problem is resolved.
0 votes
answered Jul 8, 2015 by Tomas Knopp (58,890 points)
reshown Jul 8, 2015 by Tomas Knopp
We looked into your mail and found that it is corrupted:

1.    Mail is Unicode .msg file, it states that all text fields are Unicode encoded, but the Body is stored using the Windows-1252 encoding
2.    After decoding Body using Windows-1252 I saw this:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>…

As you can see, this is Html Body, not a Text Body.

The problem seems to be within the generator of this .MSG file.

Please note that you sent the MSG attached to your email. In this case we are not sure whether it was not modified by other mail servers when being sent.  If you want to be sure, that we have exactly same .msg as you are working with, please send us the .msg file ZIP compressed one more time. And we will check it once again. Thank you.
...