diff --git a/src/Fetch/MIME.php b/src/Fetch/MIME.php index b63d72b..8f0c328 100644 --- a/src/Fetch/MIME.php +++ b/src/Fetch/MIME.php @@ -36,7 +36,9 @@ public static function decode($text, $targetCharset = 'utf-8') 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); } diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index e382678..ed897c2 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -523,7 +523,7 @@ protected function processStructure($structure, $partIdentifier = null) if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { $mb_converted = false; if (function_exists('mb_convert_encoding')) { - if (!in_array($parameters['charset'], mb_list_encodings())) { + if (!in_array(strtolower($parameters['charset']), array_map("strtolower", mb_list_encodings()))) { if ($structure->encoding === 0) { $parameters['charset'] = 'US-ASCII'; } else { @@ -531,11 +531,11 @@ protected function processStructure($structure, $partIdentifier = null) } } - $messageBody = @mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); + $messageBody = @mb_convert_encoding($messageBody, self::$charset, strtoupper($parameters['charset'])); $mb_converted = true; } if (!$mb_converted) { - $messageBodyConv = @iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); + $messageBodyConv = @iconv(strtoupper($parameters['charset']), self::$charset . self::$charsetFlag, $messageBody); if ($messageBodyConv !== false) { $messageBody = $messageBodyConv;