Here's another solution:
Instead of removil the utf8_decode() lines I added the following function:
PHP Code:
function translate_dfb($txt){
$txt = str_replace("á", "á", $txt);
$txt = str_replace("Á", "Á", $txt);
$txt = str_replace("à", "à", $txt);
$txt = str_replace("À", "À", $txt);
$txt = str_replace("é", "é", $txt);
$txt = str_replace("É", "É", $txt);
$txt = str_replace("è", "è", $txt);
$txt = str_replace("È", "È", $txt);
$txt = str_replace("í", "í", $txt);
$txt = str_replace("Í", "Í", $txt);
$txt = str_replace("ì", "ì", $txt);
$txt = str_replace("Ì", "Ì", $txt);
$txt = str_replace("ó", "ó", $txt);
$txt = str_replace("Ó", "Ó", $txt);
$txt = str_replace("ò", "ò", $txt);
$txt = str_replace("Ò", "Ò", $txt);
$txt = str_replace("ú", "ú", $txt);
$txt = str_replace("Ú", "Ú", $txt);
$txt = str_replace("ù", "ù", $txt);
$txt = str_replace("Ù", "Ù", $txt);
$txt = str_replace("ñ", "ñ", $txt);
$txt = str_replace("Ñ", "Ñ", $txt);
return $txt;
}
It should be called before thr utf8_decode():
PHP Code:
$file = $str;
$file = translate_dfb($file);
$file = utf8_decode($file); // cleanses encoding safely
However, when an e-mail is sent (at least with Mozilla/Thunderbird) the ISO encoding is used like this:
"vénde esto pues"
Subject: =?ISO-8859-1?Q?v=E9nde_esto_pues?=
Since the first word is in ISO it is correctly translated by the
imap_mime_header_decode() function
However, if the subject begins with a word without accents:
"que onda cómo estás tu"
Subject: que onda =?ISO-8859-1?Q?c=F3mo_est=E1s_tu?=
The subject is composed by "default" text and by "ISO-8859-1" text, therefore the function imap_mime_header_decode() will decode it in two elements of an array.
Sugar does use only the First array:
PHP Code:
$email->name = $subjectDecoded[0]->text;
in this case the words: "que onda". The rest of the subject is stored in the next element of the array. So by adding the following lines both pieces are put together as one Subject:
PHP Code:
if (isset($subjectDecoded[1]->text) && !empty($subjectDecoded[1]->text)) {
$email->name .= $subjectDecoded[1]->text;
}
Bookmarks