PHP Reading POP Account - How to decode utf8 with php

esnagel

Director of Common Sense
I've got my PHP script reading a POP account, and I can pull everything out nicely, but I'm getting some strange subject lines. Here are two:

Code:
Subject: =?utf-8?Q?It=27s=20time=20to=20brighten=20your=20weekends...=20Launching=20Blooms=20to=20Go=21=20=3A=29?=
Subject: =?UTF-8?B?RFZEIERpc2Mtby1yYW1hIOKAlCBGbGlja3MgVW5kZXIg?= =?UTF-8?B?JDchIFRoZSBTb24gb2YgQnV5bmFuemEgU3RyaWtlcyE=?=

Now the first one, I can almost make out:

PHP:
php > echo(quoted_printable_decode("=?utf-8?Q?It=27s=20time=20to=20brighten=20your=20weekends...=20Launching=20Blooms=20to=20Go=21=20=3A=29?="));
=?utf-8?Q?It's time to brighten your weekends... Launching Blooms to Go! :)?

But doing the same thing for the second, I get junk

PHP:
php > echo(quoted_printable_decode("?UTF-8?B?RFZEIERpc2Mtby1yYW1hIOKAlCBGbGlja3MgVW5kZXIg?= =?UTF-8?B?JDchIFRoZSBTb24gb2YgQnV5bmFuemEgU3RyaWtlcyE=?="));
?UTF-8?B?RFZEIERpc2Mtby1yYW1hIOKAlCBGbGlja3MgVW5kZXIg?= =?UTF-8?B?JDchIFRoZSBTb24gb2YgQnV5bmFuemEgU3RyaWtlcyE=?

I've also tried utf8_decode() and didn't get any closer. Any ideas how I can read these subjects?

Thanks,
Eric
 

esnagel

Director of Common Sense
Ray helped me out, and here's what we figured out:

Quoted Printable (subject starts with "=?utf-8?Q")
Base64 (subject starts with "=?utf-8?B")

So the one line, we use quoted_printable_decode and the other, use imap_base64.

PHP:
php > var_dump(quoted_printable_decode('It=27s=20time=20to=20brighten=20your=20weekends...=20Launching=20Blooms=20to=20Go=21=20=3A=29'));
string(65) "It's time to brighten your weekends... Launching Blooms to Go! :)"

PHP:
php > var_dump(imap_base64('RFZEIERpc2Mtby1yYW1hIOKAlCBGbGlja3MgVW5kZXIgJDchIFRoZSBTb24gb2YgQnV5bmFuemEgU3RyaWtlcyE='));
string(65) "DVD Disc-o-rama â Flicks Under $7! The Son of Buynanza Strikes!"
 
Top