Merge pull request #88 from Xethron/catch-mb_convert_encoding-exceptions

Catch mb convert encoding exceptions
This commit is contained in:
Robert Hafner 2014-09-24 23:44:51 -07:00
commit 501d5d0974

View File

@ -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
@ -465,10 +466,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
}
}
}