diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index e382678..3d21de2 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 (!$this->isMbstringEncodingSupported($parameters['charset'])) { if ($structure->encoding === 0) { $parameters['charset'] = 'US-ASCII'; } else { @@ -575,6 +575,26 @@ protected function processStructure($structure, $partIdentifier = null) } } + /** + * Checks if $encoding is supported by mbstring extension + * + * @param string $encoding + * + * @return bool + */ + private function isMbstringEncodingSupported($encoding) + { + static $list = null; + + if ($list === null) { + $list = \array_map(function ($encoding) { + return \strtolower($encoding); + }, \mb_list_encodings()); + } + + return \in_array(\strtolower($encoding), $list, true); + } + /** * This function takes in the message data and encoding type and returns the decoded data. *