From 05ad71a83ffa3a4eee380013e586b8c1ec937839 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 18:53:14 -0600 Subject: [PATCH] Compromise between mb_convert_encoding and iconv --- src/Fetch/Message.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 76f6c6d..fb5b580 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -168,6 +168,14 @@ class Message * @var string */ public static $charset = 'UTF-8'; + + /** + * This value defines the flag set for encoding if the mb_convert_encoding + * function can't be found. In this case iconv encoding will be used. + * + * @var string + */ + public static $charset = '//TRANSLIT'; /** * This constructor takes in the uid for the message and the Imap class representing the mailbox the @@ -437,8 +445,12 @@ class Message $messageBody = self::decode($messageBody, $structure->encoding); - if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) - $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); + if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { + if (function_exists('mb_convert_encoding')) { + $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); + } + $messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); + } if (strtolower($structure->subtype) === 'plain' || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative')) { if (isset($this->plaintextMessage)) {