diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 67bb1bf..a135ca2 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -480,18 +480,22 @@ class Message if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { $mb_converted = false; if (function_exists('mb_convert_encoding')) { - try { - $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); - $mb_converted = true; - } catch (Exception $e) { - // @TODO Handle exception + if (!in_array($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; } if (!$mb_converted) { - try { - $messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); - } catch (Exception $e) { - // @TODO Handle exception + $messageBodyConv = @iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); + + if ($messageBodyConv !== false) { + $messageBody = $messageBodyConv; } } }