Skip to content

Commit

Permalink
Catch exceptions from mb_convert_encoding and default to iconv
Browse files Browse the repository at this point in the history
  • Loading branch information
Xethron committed Sep 17, 2014
1 parent b96c24a commit 38dd385
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Fetch/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -463,10 +464,21 @@ protected function processStructure($structure, $partIdentifier = null)
$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
}
}
}

Expand Down

0 comments on commit 38dd385

Please sign in to comment.