decode Subject of mail using ImapX lib?

1.5k Views Asked by At

I have problem when get Subject of mail. Problem is: if subject is English it is can get good but if subject is vietnamese (my language) it return null;

2

There are 2 best solutions below

0
On

If you're using the old ImapX library, I invite you to upgrade to ImapX 2. It now supports automated decoding of subjects, file names and body content. The library is being constantly developed and supported. There is also sample code for all common operations.

1
On
string encoding = msg.HtmlBody.ContentType.Split('=')[1];

string decodedBody = Encoding.GetEncoding(encoding).GetString(Convert.FromBase64String(msg.HtmlBody.TextData));
string decodedSubject = Encoding.GetEncoding(encoding).GetString(Convert.FromBase64String(msg.Subject.Split('?')[3]));