c# - Encoding issue when reading .eml file from MailBee -
this has mailing tool use: mailbee, pretty easy use.
- we create mailing (define message body , attachments if needed)
- we create list of contacts , add datatable
- we call mailbee's addjob method generates .eml file in ansi format
- after writing files completed, read files , find
to:
string using:match match = regex.match(recipient, @"""(.*?)"" <(.*?)>");
this value seems base64 encoded. here code unit test parsing.
[testclass] public class unittest1 { [testmethod] public void testmethod1() { testmethods.decodestring("to: \"=?utf-8?b?qwjkdxjyywhpbsdvv716z2vub2dsdq==?=\" <email@somehost.com;;>"); // results in "abdurrahim �zgenoglu" while should "abdurrahim Ă–zgenoglu" } } public class testmethods { public static string decodestring(string stringtodecode) { match base64match = regex.match(stringtodecode, @"=\?utf-8\?b\?(.*)\?="); if (base64match.success) { string encodedname = base64match.groups[1].value; byte[] bytes = convert.frombase64string(encodedname); return encoding.utf8.getstring(bytes); } return stringtodecode; } }
any suggestions on going wrong here? suspect mailbee right before converts text base64. can't verify that.
you're trying convert ansi string utf-8. that's why you're seeing error.
instead of...
encoding.utf8.getstring(bytes);
try using:
encoding.getencoding(1252).getstring(bytes);
or
encoding.getencoding("iso-8859-1").getstring(bytes);
Comments
Post a Comment