From 04b5a5ed33c62cbf38e2a77a03d19360d51206dc Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 09:55:34 -0600 Subject: [PATCH 01/10] Check to see if message is already encoded in utf8 Adding requirement to if statement to check if message matches UTF-8 encoding via regex. This will prevent encoding errors when converting UTF-8 to UTF-8. --- 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 06ffc7c..537b0ea 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -437,7 +437,7 @@ class Message $messageBody = self::decode($messageBody, $structure->encoding); - if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) + if (!empty($parameters['charset']) && !preg_match('/utf-?8/i', $parameters['charset']) && $parameters['charset'] !== self::$charset) $messageBody = iconv($parameters['charset'], self::$charset, $messageBody); if (strtolower($structure->subtype) === 'plain' || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative')) { From f08630cde9250c63af7a47522c4bca431a593ecc Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 13:51:27 -0600 Subject: [PATCH 02/10] Switch to mb_convert_encoding Changing from iconv to mb_convert_encoding. $charset = 'UTF-8//TRANSLIT' is no longer needed. 'UTF-8' set as default and user may change value to whatever they wish :) --- src/Fetch/Message.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 537b0ea..76f6c6d 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -167,7 +167,7 @@ class Message * * @var string */ - public static $charset = 'UTF-8//TRANSLIT'; + public static $charset = 'UTF-8'; /** * This constructor takes in the uid for the message and the Imap class representing the mailbox the @@ -437,8 +437,8 @@ class Message $messageBody = self::decode($messageBody, $structure->encoding); - if (!empty($parameters['charset']) && !preg_match('/utf-?8/i', $parameters['charset']) && $parameters['charset'] !== self::$charset) - $messageBody = iconv($parameters['charset'], self::$charset, $messageBody); + if (!empty($parameters['charset']) && $parameters['charset'] !== self::$charset) + $messageBody = mb_convert_encoding($messageBody, self::$charset, $parameters['charset']); if (strtolower($structure->subtype) === 'plain' || ($structure->type == 1 && strtolower($structure->subtype) !== 'alternative')) { if (isset($this->plaintextMessage)) { From 05ad71a83ffa3a4eee380013e586b8c1ec937839 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Thu, 12 Jun 2014 18:53:14 -0600 Subject: [PATCH 03/10] 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 04/10] 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 05/10] 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 06/10] 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')) { From 1790a917f4f789a19e8ecb9008ca0c992166a5d9 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 13 Jun 2014 09:00:22 -0600 Subject: [PATCH 07/10] bug fixes --- src/Fetch/Message.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 57caccf..5807ba4 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -168,11 +168,11 @@ 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 $charsetFlag = '//TRANSLIT'; @@ -360,7 +360,6 @@ class Message if (!in_array($type, $addressTypes) || !isset($this->$type) || count($this->$type) < 1) return false; - if (!$asString) { if ($type == 'from') return $this->from[0]; From d4d7f367ba5420678d140f500aa3374a1f7544d8 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Fri, 13 Jun 2014 09:05:35 -0600 Subject: [PATCH 08/10] Updated message for $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 57caccf..0ba7e9d 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -171,7 +171,7 @@ class Message /** * 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. + * function can't be found, and in this case iconv encoding will be used. * * @var string */ From c6c80ac45b0707e3dc73725e9d72e70928fb2283 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 13 Jun 2014 09:11:12 -0600 Subject: [PATCH 09/10] variable and message fix --- 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 d3f4faf..3b40620 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -176,7 +176,7 @@ class Message * ======= * function can't be found, and in this case iconv encoding will be used. - * + * >>>>>>> d4d7f367ba5420678d140f500aa3374a1f7544d8 * @var string */ From fa5ce2ddba8038b271e3e4307f794cf162e587d5 Mon Sep 17 00:00:00 2001 From: Alex Kavon Date: Fri, 13 Jun 2014 09:23:30 -0600 Subject: [PATCH 10/10] head conflicts fix --- src/Fetch/Message.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 3b40620..98c8048 100644 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -171,13 +171,8 @@ class Message /** * This value defines the flag set for encoding if the mb_convert_encoding -<<<<<<< HEAD - * function can't be found. In this case iconv encoding will be used. - * -======= * function can't be found, and in this case iconv encoding will be used. * ->>>>>>> d4d7f367ba5420678d140f500aa3374a1f7544d8 * @var string */ public static $charsetFlag = '//TRANSLIT';