From 38dd385cb8d07e5a4caa7a5e8b6fb3de2fbc7f13 Mon Sep 17 00:00:00 2001 From: Bernhard Breytenbach Date: Wed, 17 Sep 2014 21:56:59 +0200 Subject: [PATCH] Catch exceptions from mb_convert_encoding and default to iconv --- src/Fetch/Message.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index dc58566..a7476f2 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -10,6 +10,7 @@ */ namespace Fetch; +use Exception; /** * This library is a wrapper around the Imap library functions included in php. This class represents a single email @@ -463,10 +464,21 @@ class Message $messageBody = self::decode($messageBody, $structure->encoding); if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { + $mb_converted = false; if (function_exists('mb_convert_encoding')) { - $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); - } else { - $messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); + try { + $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); + $mb_converted = true; + } catch (Exception $e) { + // @TODO Handle exception + } + } + if ( ! $mb_converted) { + try { + $messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); + } catch (Exception $e) { + // @TODO Handle exception + } } }