Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!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:19:25 +0200 Lines: 93 Message-ID: <53B7529D.9050002@arnowelzel.de> References: <53B7520B.8080506@arnowelzel.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net xM08KJ5ryIafdL6/p/9s5wh65yYZmRiQIUt2poWl02Y/d5h4gw Cancel-Lock: sha1:yIB2zBFAHLgg4cFaXqe53DXRhg8= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <53B7520B.8080506@arnowelzel.de> X-Enigmail-Version: 1.6 Xref: csiph.com comp.lang.php:14064 Arno Welzel, 2014-07-05 03:16: > 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); Ups - sorry for the c&p typo. Of course it should be: $body = base64_decode($body); > break; > } > > $body = renderPlainText($body); > } > > Also see and > the comments there. -- Arno Welzel http://arnowelzel.de http://de-rec-fahrrad.de http://fahrradzukunft.de