c# - Encoding issue when reading .eml file from MailBee -


this has mailing tool use: mailbee, pretty easy use.

  1. we create mailing (define message body , attachments if needed)
  2. we create list of contacts , add datatable
  3. we call mailbee's addjob method generates .eml file in ansi format
  4. 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); 

source


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -