From 7b8d1c1a5d030dc8559a63f486ff86cdef5a93ab Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Wed, 24 Jan 2018 15:43:28 +1000 Subject: [PATCH 1/4] Update Message.php --- src/Fetch/Message.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index e382678..32a965e 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -11,6 +11,8 @@ namespace Fetch; +use function strtolower; + /** * This library is a wrapper around the Imap library functions included in php. This class represents a single email * message as retrieved from the Imap. @@ -233,7 +235,7 @@ protected function loadMessage() return false; - $this->subject = MIME::decode($messageOverview->subject, self::$charset); + $this->subject = isset($messageOverview->subject) ? imap_utf8($messageOverview->subject) : null; $this->date = strtotime($messageOverview->date); $this->size = $messageOverview->size; @@ -523,7 +525,7 @@ protected function processStructure($structure, $partIdentifier = null) if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) { $mb_converted = false; if (function_exists('mb_convert_encoding')) { - if (!in_array($parameters['charset'], mb_list_encodings())) { + if (!$this->isMbstringEncodingSupported($parameters['charset'])) { if ($structure->encoding === 0) { $parameters['charset'] = 'US-ASCII'; } else { @@ -575,6 +577,24 @@ protected function processStructure($structure, $partIdentifier = null) } } + /** + * @param string $encoding + * + * @return bool + */ + private function isMbstringEncodingSupported($encoding) + { + static $list = null; + + if ($list === null) { + $list = array_map(function ($encoding) { + return strtolower($encoding); + }, mb_list_encodings()); + } + + return in_array($encoding, $list, true); + } + /** * This function takes in the message data and encoding type and returns the decoded data. * @@ -674,7 +694,7 @@ protected function processAddressObject($addresses) $currentAddress = array(); $currentAddress['address'] = $address->mailbox . '@' . $address->host; if (isset($address->personal)) { - $currentAddress['name'] = MIME::decode($address->personal, self::$charset); + $currentAddress['name'] = $address->personal; } $outputAddresses[] = $currentAddress; } From 17d26375ae06aa29281b15fd423628f502b41382 Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Wed, 24 Jan 2018 15:45:28 +1000 Subject: [PATCH 2/4] Update Message.php --- src/Fetch/Message.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 32a965e..d2be990 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -11,8 +11,6 @@ namespace Fetch; -use function strtolower; - /** * This library is a wrapper around the Imap library functions included in php. This class represents a single email * message as retrieved from the Imap. @@ -235,7 +233,7 @@ protected function loadMessage() return false; - $this->subject = isset($messageOverview->subject) ? imap_utf8($messageOverview->subject) : null; + $this->subject = MIME::decode($messageOverview->subject, self::$charset); $this->date = strtotime($messageOverview->date); $this->size = $messageOverview->size; @@ -587,12 +585,12 @@ private function isMbstringEncodingSupported($encoding) static $list = null; if ($list === null) { - $list = array_map(function ($encoding) { - return strtolower($encoding); - }, mb_list_encodings()); + $list = \array_map(function ($encoding) { + return \strtolower($encoding); + }, \mb_list_encodings()); } - return in_array($encoding, $list, true); + return \in_array($encoding, $list, true); } /** @@ -694,7 +692,7 @@ protected function processAddressObject($addresses) $currentAddress = array(); $currentAddress['address'] = $address->mailbox . '@' . $address->host; if (isset($address->personal)) { - $currentAddress['name'] = $address->personal; + $currentAddress['name'] = MIME::decode($address->personal, self::$charset); } $outputAddresses[] = $currentAddress; } From 7375f2ae2b8d78c2c4619e1f02d19de3f4db1d84 Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Wed, 24 Jan 2018 15:46:20 +1000 Subject: [PATCH 3/4] Update Message.php --- src/Fetch/Message.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index d2be990..95e6e09 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -576,6 +576,8 @@ protected function processStructure($structure, $partIdentifier = null) } /** + * Checks if $encoding is supported by mbstring extension + * * @param string $encoding * * @return bool From 7aa35948e26b1ef2ec8fc9df28a9e6a7b482c300 Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Wed, 24 Jan 2018 19:06:05 +1000 Subject: [PATCH 4/4] Update Message.php --- 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 95e6e09..3d21de2 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -592,7 +592,7 @@ private function isMbstringEncodingSupported($encoding) }, \mb_list_encodings()); } - return \in_array($encoding, $list, true); + return \in_array(\strtolower($encoding), $list, true); } /**