2

I have a problem with my script. It reads mails from stdin and do whatever it's needed. My script works like a charm for some mail clients like thunderbird or outlook.com. The main problem is that it doesn't work with the program 'mail' from apple (that is very used in my enterprise).

For some reason the text readed from mail it's not codificated. For example:

Respuesta 5 desde Mail
El 17/03/2015, a = las 13:13, app@******.es = escribi=F3:

--=3D=3D--
RESPONDER POR ENCIMA DE ESTA L=CDNEA

Comunicaci=F3n

C=F3digo:   PRB03154
Nombre del grupo:   MYSTICA

Prueba de = comunicaciones a trav=E9s de mails

Comunicaci=F3n enviada por **** (Departamento de = ****)

As you can see there are some =F3 that are the equivalents to char ó and there are multiples single '=' that, I assume, comes from =\n

I've tried codes like:

echo utf8_encode($texto);

or

mb_internal_encoding('UTF-8');
echo str_replace("_"," ", mb_decode_mimeheader($texto));

or

echo iconv(mb_detect_encoding($texto, mb_detect_order(), true), "UTF-8", $texto);

Is there a way to convert this text to something more readable?

Thanks

kenorb
  • 155,785
  • 88
  • 678
  • 743
Serpes
  • 672
  • 4
  • 14
  • How exactly are you sending mails? The problem is likely that you're not setting the necessary mail headers to correctly describe what the content of your mail is encoded as. Different mail clients make different default assumptions if you do not specify things explicitly; Mail.app apparently makes different assumptions than Outlook. – deceze Mar 17 '15 at 15:02
  • Well, the mails that are like the one of the text are sent with Mail.app. – Serpes Mar 17 '15 at 15:05
  • Ah, so the other way around. *You* aren't parsing the mail headers appropriately. There are a ton of different ways to encode email, and you need to support them all. You need to parse the headers to figure out how the mail was encoded, and decode it using the right tool. PHP offers these tools mostly under the `imap` extension. – deceze Mar 17 '15 at 15:12

1 Answers1

0

Ok, The problem is resolved. I had to use quoted_printable_decode function.

I found the solution in SO: PHP giving a trailing “=” on each line after reading from stdin

Community
  • 1
  • 1
Serpes
  • 672
  • 4
  • 14