I have string data as CDATA Format. How can I convert this to Html or normal view text at C#? Should I use mimeKit or something else?
Received: from 172.19.76.148 (proxying for 85.105.234.193) (InterKepWebMail authenticated user parkentegrasyon) by kep.local with HTTP; Mon, 29 Jan 2018 18:51:40 +0300 Content-Type: multipart/mixed; boundary="------_=_NextPart_001_01F869E9.0A514C28" Message-ID: <8ec68378-eca0-428d-a350-94427435a521.webmail@testkep.inter-kep.com.tr> MIME-Version: 1.0 Date: Mon, 29 Jan 2018 18:51:40 +0300 From: "parkentegrasyon" <parkentegrasyon@testkep.inter-kep.com.tr> To: <parkentegrasyon@testkep.inter-kep.com.tr> Cc: <parkentegrasyon@testkep.inter-kep.com.tr> Subject: =?utf-8?Q?=C3=96rnek_KEP_2018-01-29_18=3A51=3A41?= User-Agent: InterKepWebMail/1.0.0 X-TR-REM-iletiTip: standart X-TR-REM-iletiID: --------_=_NextPart_001_01F869E9.0A514C28 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable <b>Merhaba D=C3=BCnya!</b> --------_=_NextPart_001_01F869E9.0A514C28 Content-Type: application/octet-stream; name="test.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="test.txt" dGVzdCBlaw== --------_=_NextPart_001_01F869E9.0A514C28--
It's base64 encoded text. You can decode it like this
byte[] data = Convert.FromBase64String("dGVzdCBlaw==");
string decodedString = Encoding.UTF8.GetString(data);
Console.WriteLine(decodedString);
That prints 'Test ek'.
If you use MimeKit to parse the message, it will automatically decode the content (whether it be in base64 or quoted-printable).
In your example message, the text/html
message body can be gotten like this:
var html = message.HtmlBody;
To get the decoded attachment content, you can do this:
foreach (var attachment in message.Attachments.OfType<MimePart> ()) {
using (var memory = new MemoryStream ()) {
attachment.Content.DecodeTo (memory);
var data = memory.ToArray ();
var text = Encoding.UTF8.GetString (data);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.