-
-
Notifications
You must be signed in to change notification settings - Fork 157
Open
Description
I found a bug on "processStructure" in the class Message
Some charsets are not declared with caps, which can lead to improper check by the function in_array on mb_list_encodings()... This can be corrected using strtoupper :
if (function_exists('mb_convert_encoding')) {
if (!in_array(strtoupper($parameters['charset']), mb_list_encodings())) {
if ($structure->encoding === 0) {
$parameters['charset'] = 'US-ASCII';
} else {
$parameters['charset'] = 'UTF-8';
}
}
$messageBody = @mb_convert_encoding($messageBody, self::$charset, $parameters['charset']);
$mb_converted = true;
}
I found an improvement on "decode" in the class MIME... Sometimes the charset in subjects are badly declared and wrongly interpreted as ASCII, and conversion can be handled doing like this :
public static function decode($text, $targetCharset = 'UTF-8')
{
if (null === $text) {
return null;
}
$result = '';
foreach (imap_mime_header_decode($text) as $word) {
$ch = 'default' === $word->charset ? 'ascii' : $word->charset;
if ($ch==="ascii" && ($c=strtoupper(mb_detect_encoding($word->text)))!==strtoupper($ch)) {
$ch=$c;
}
$result .= iconv($ch, $targetCharset, $word->text);
}
return $result;
}
Metadata
Metadata
Assignees
Labels
No labels