Reputation: 59
I need to decode the subject of some mails. I have this code
$subject = mimie_text_decode($header->Subject);
function mimie_text_decode($string){
$string = htmlspecialchars(chop($string));
$elements = imap_mime_header_decode($string);
if(is_array($elements)){
for ($i=0; $i<count($elements); $i++) {
$charset = $elements[$i]->charset;
$txt .= $elements[$i]->text;
}
} else {
$txt = $string;
}
if($txt == ''){
$txt = 'No_name';
}
return $txt;
}
When my subject is some like this ?UTF-8?Q?C=C3=BAspide?=
It works correctly, but if my subject is not UTF-8 and is like this one ?Windows-1252?Q?Pro=F3ba?=
it does not show the characters with accents, it eliminate everything that has accents, ie only shows the words until an accent appears. If I have this word "Más" it only shows "M"
What can be the solution?
Thanks
Upvotes: 2
Views: 670
Reputation: 4037
Your code works for me, but the encoded subjects you write should start by =?.
Try your code with =?Windows-1252?Q?Pro=F3ba?=
Windows-1252 it's another encoding created by Microsoft very similar to ISO-8859-15 [1]
If don't works for you adding this = character as the first element of the string passed to mimie_text_decode tell us which version of php are you using.
[1] http://en.wikipedia.org/wiki/Windows-1252
Upvotes: 1