Click here to Skip to main content
15,886,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good morning everyone.

I am writing a C++ application which tries to get some information from a mail box using POP3 protocol. The information I am trying to get contains French characters, means accentuated characters like "é, ç, à". I need to store this information in a MySQL database. To display this information on the screen or in a file I get strange characters instead of the accentuated ones.
an example :
instead of getting:

"Super U La Ferté Gaucher : Démarrage"

I get:

"Super U La Fert=?iso-8859-1?B?6SBHYXVjaGVyIDogTlJ2aXNpb24gMjAxMy0xMSA6IETp?=marrage"

I can read from the generated information that my characters are coded in iso-8859-1, but I need them in UTF-8.
Is there any way to decode this information, or maybe some configuration that should be done to get the right result.
I don't want to use any non-standard libraries (only Microsoft tools).
Remarks: I am using Visual Studio 2010, Windows 8. My application is in two versions Console CLR and MFC.

Thank you in advance
Posted

1 solution

The message is encoded according to RFC 2047[^]. The encoding mechanism from your example is Base64[^] (indicated by the 'B').

If you don't want to use an additional library, you must write your own parser to get the code page and encoding ('B' for Base64 or 'Q' for quoted-printable) and decode the text (there are many C/C++ source examples in the net).

Once you have the decoded text, convert it to Unicode using MultiByteToWideChar[^] passing the corresponding code page number, and finally convert the wide string to UTF-8 using WideCharToMultiByte[^].
 
Share this answer
 
Comments
TAREK BAZINGA 7-Apr-15 5:17am    
Thank you @Jochen Arndt for your answer, it clarified many things. Can you advise me, please, of one popular library that can help me, I will work on my own code, but I really want to try what those libraries can give me.

Regards
Jochen Arndt 7-Apr-15 5:44am    
It is difficult to mention a popular library. Such conversion functions are usually part of mail (MIME) handling libraries. Some are mentioned in this SO thread: http://stackoverflow.com/questions/218089/simple-c-mime-parser.

If you don't need the general mail handling, it may be better to just use the decoding function sources as base for your own implementation (most are for Linux but it is plain C/C++).

Base64 and quoted-printable decoding is simple and there are lot of examples. Parsing the input string is more complex if it should be full RFC-2047 compatible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900