Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.php Subject: Re: Encoding Problems Date: Sat, 05 Jul 2014 03:16:59 +0200 Lines: 86 Message-ID: <53B7520B.8080506@arnowelzel.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net ra0XTtIAoZXFO5B9lkWcrQPawyeDqFHiVGXnVWI1QdA47IFe55 Cancel-Lock: sha1:Jf7IilDWMb2tY6lK8ZNtRpH903o= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-Enigmail-Version: 1.6 Xref: csiph.com comp.lang.php:14063 stef_204, 2014-07-02 17:53: > Hi, > > Newbie at php; please bear with me. > > I am trying to use a script which basically creates an xml feed for email > messages found in an IMAP account; one can then either subscribe to feed > via an rss reader/aggregator or use browser to read html page. > > Here is the script: > (imap2rss.php) > > My problem: almost all of the messages (emails) show garbled text, I > believe due to encoding problems. > > Here is a picture of how it looks both using a browser like Firefox or an > rss news feed reader. > > This is base64 and as to be decoded. [...] > I could be completely wrong about the utf-8 issue; and perhaps it has > more something to do with decoding base64 in general. Yep - that's the point. > This is what I now think is the problem, more specifically: > I have just tried a base64 online decoder and pasted the garbled text in > it and used the "decode" online feature, and the result is perfectly > legible once decoded, whether I choose utf-8 or ascii as charset (but I > should use utf-8). > > So, looks like the feed is "echoed" or "printed" in base64 format.... > It doesn't look like charset is the problem but decoding base64. Yep. > > I can see the base64_decode function here > > but not sure if this is the right way to go about this; or how to apply > it in this script. Well - unfortunately there is no easy "put it in there and it works". First of all: Just testing for the subtype "PLAIN" (is not enough. You also have to check for the encoding. As far i see, this should be added here: if($msgStructure->subtype=="PLAIN") $body = renderPlainText($body); So extend that for the encoding: if($msgStructure->subtype=="PLAIN") { switch($msgStructure->encoding) { case 4: // Body text is quoted-printable encoded $body = quoted_printable_decode($body); break; case 3: // Body text is base64 encoded $body = base64_decode($data); break; } $body = renderPlainText($body); } Also see and the comments there. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de