From 05ad71a83ffa3a4eee380013e586b8c1ec937839 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 18:53:14 -0600 Subject: [PATCH 1/4] 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)) { From b8b426c04573d12da1be0f154eb962ac21c1ea84 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 18:58:03 -0600 Subject: [PATCH 2/4] Second $charset should of been $charsetFlag --- src/Fetch/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index fb5b580..26812a6 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -175,7 +175,7 @@ class Message * * @var string */ - public static $charset = '//TRANSLIT'; + public static $charsetFlag = '//TRANSLIT'; /** * This constructor takes in the uid for the message and the Imap class representing the mailbox the From b6874c4a4984ef8b8f40c759248830ba9b25b60f Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 19:03:18 -0600 Subject: [PATCH 3/4] whitespace --- src/Fetch/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 26812a6..97a4ae7 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -175,7 +175,7 @@ class Message * * @var string */ - public static $charsetFlag = '//TRANSLIT'; + public static $charsetFlag = '//TRANSLIT'; /** * This constructor takes in the uid for the message and the Imap class representing the mailbox the From 9e49db2dd075a0319529fe2498c3199a8f6194c8 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 19:12:31 -0600 Subject: [PATCH 4/4] picky travis, added else statement --- src/Fetch/Message.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 97a4ae7..57caccf 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -448,8 +448,9 @@ class Message if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { 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); } - $messageBody = iconv($parameters['charset'], self::$charset . self::$charsetFlag, $messageBody); } if (strtolower($structure->subtype) === 'plain' || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative')) {