0

I'm working to clean up emails before they get stored in a database. A fandango email was sent as being encoded as 4 (quoted-printable). Here is part of the message without decoding...

=0A=0A=A0=0AJohn=0A(800) 123-4567=0A=0A----- Forwarded Message =

=20=0ASent:=20Thursday,=20July=204,=202013=204:14=20PM=0ASubject:=20Your=20Despicab=

le=20Me=202=20iTunes=20Download=0A=20=0A=0A=0ADespicable=20Me=202=20=0A=20=20=0A=20Your=20purchase=20=

of=20tickets=20for=20Despicable=20Me=202=20has=20earned=20you=20a=20complimentary=20download=20of=20t=

he=20song=20'Just=20a=20Cloud=20Away'=20by=20Pharrell=20from=20the=20Original=20Motion=20Picture=20So=

undtrack=20on=20iTunes.=20=0AWe=20hope=20you=20enjoy=20the=20song=20and=20the=20film!=0AIf=20you=20ha=

ve=20iTunes=20installed,=20click=20here=20to=20start=20your=20complimentary=20download.=0AIF=20=

YOU=20DO=20NOT=20HAVE=20iTunes=20INSTALLED:=0A=0A1.=20Download=20iTunes=20for=20Mac=20or=20Window=

s,=20free=20of=20charge=20at=20www.iTunes.com.=20=0A2.=20Open=20iTunes=20and=20click=20iTunes=20Sto=

re.=20=0A3.=20Click=20Redeem=20under=20Quick=20Links.=20=0A4.=20Enter=20the=20code=20below.=20Your=20=

download=20will=20start=20immediately.=20Enjoy.=20=0ADownload=20Code:=20FML6H34XXTMJ=20=0AC=

But when I use quoted_printable_decode() on the variable it produces no text.


This url has a decoder that works, albeit in ASP/VB...

http://www.motobit.com/util/quoted-printable-decoder.asp

I'm guessing the code here is relevant...

http://www.motobit.com/tips/detpg_quoted-printable-decode/

It decodes the quote-printable HTML above correctly. Hopefully this will help someone trying to help me. I'm sure I'm not the only one to encounter broken quote-printable email messages.

John
  • 1
  • 13
  • 98
  • 177

2 Answers2

0

It looks like there are some spaces in the quoted-printable encoded string that you posted. That's probably what's causing the problem - if it's truly quoted-printable, than the encoded string should not contain any spaces. Spaces are =20 in quoted printable. If you use a replace function (e.g. PHP's str_replace) to replace the spaces in the encoded string with =20, then you get the following quoted-printable encoded string:

John=0D=0A(800)=20123-4567=0D=0A=0D=0A-----=20Forwarded=20Message=20

Then, this string can be decoded using PHP's quoted_printable_decode() function.

mti2935
  • 11,465
  • 3
  • 29
  • 33
  • Well that seems to be moving me in the right direction. Do you see anything else? I've updated my question with most of the email's contents. I've thought about just manually converting it over, I don't want to waste three days of time on this issue alone. Let me know, thanks! – John Jul 08 '13 at 21:49
0

If you copy the quoted-printable encoded text above to a file, then run the following PHP script (which reads the quoted-printable text from the file, gets rid of the spaces using the str_replace function, then decodes the quoted-printable text using the quoted_printable_decode function), you should see that it produces the correct decoded output:

 <?
 $filename="./qp.txt";
 $file = fopen($filename,"r");
 $qp = fread($file,filesize($filename));
 fclose($file);

 $qp=str_replace(" ", "", $qp);
 print "<plaintext>";    
 print quoted_printable_decode($qp);
 ?>
mti2935
  • 11,465
  • 3
  • 29
  • 33