phputf-8imapdecode

Using PHP, how do I decode an email's body with non-ASCII characters to plain text?


I'm trying to extract some content of some encoded emails with PHP but I can't.

With this:

$body = imap_body($imap_o, $email_n);

I get:

Pour = le r=E9cup=E9rer, il suffit de le t=E9l=E9charger, de le r=E9ceptionner puis de    l=92ouvrir.=Une f= ois votre traduction termin=E9e, n=92oubliez pas de sauvegarder vos paires de langues et d=92effectuer une v=E9rification g=E9n=E9rale (statuts des segments, b= alises, nombres, espaces, majuscules, etc.).Ensui= te, cliquez sur =AB=A0Terminer et livrer=A0=BB.Voici le r=E9capitulatif du projet=A0:

but there are lot of =* . I know that =20 is a space, but here there are others that I don't know what they mean.

If I add quoted_printable_decode():

$body = quoted_printable_decode($body);

I get:

Pour le r�cup�rer, il suffit de le t�l�charger, de le r�ceptionner puis de l�ouvrir. Une fois votre traduction termin�e, n�oubliez pas de sauvegarder vos paires de langues et d�effectuer une v�rification g�n�rale (statuts des segments, balises, nombres, espaces, majuscules, etc.). Ensuite, cliquez sur ��Terminer et livrer��. Voici le r�capitulatif du projet�:

I added imap_qprint() and utf8_decode and nothing improved...

Before decode that messages I need to send a "clean" copy of those, without some information, and if I can get those on plain format it will help me to do it much faster and easier.

And If i need to delete some words of the body how can I do?


Solution

  • Try

    $body = utf8_encode(quoted_printable_decode($body));
    

    Edit: As of PHP 8.2 utf8_encode() and utf8_decode() are deprecated. You should use mb_convert_encoding() instead:

    $body = mb_convert_encoding(quoted_printable_decode($body), 'UTF-8', 'ISO-8859-1');