views:

31

answers:

2

Hi everyone,

I have tested PHP's IMAP lib. to fetch emails from a GMAIL account, but I've just can't get my head around trying to make the characters to display correctly.

At first, I was close to pull my hair off when I realized that I accidentally fetched the attachments instead of the message body - not good, but now when that is solved, I still have problems viewing the actual messages with appropriate Swedish characters, like åÅ äÄ öÖ which instead appear as their ASCII-cousins; =E4, =E5 - and so on.

What is the appropriate way to solve this? I've tested all encoding functions that I can think of by myself - and it won't work...

Thanks!

A: 

Try this

function fixEncoding($in_str) {
      $cur_encoding = mb_detect_encoding($in_str) ;
      if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
         return $in_str;
      else
         return utf8_encode($in_str);
    }
Centurion
This only converts ISO-8859-1 to UTF-8.
Artefacto
Hi Vadim, I'm afraid that it doesn't work either. Thanks for your help!
Industrial
+1  A: 

Not 100% sure, but it seems to me that the content of the message is quoted-printable encoded. Try quoted_printable_decode - http://www.php.net/manual/en/function.quoted-printable-decode.php

If you are already using the IMAP extension, you can also try imap_qprint - http://www.php.net/manual/en/function.imap-qprint.php

Max
Hi Max! Thanks a lot! It does work at some of the messages, but I believe that it's different message settings that screws it up now. Very appreciated! Thanks!
Industrial
@Industrial: There are, unfortunately, multiple encoding schemes that could be used to represent the non-ASCII characters. =E4, =E5, etc. are quoted-printable, so this will decode them correctly, but it won't handle other encoding schemes. Getting those to display correctly will probably require matching your HTML doc's charset to that used in the message... Good luck...
Dave Sherohman
Hi Dave, thanks a lot for your help!
Industrial