From ce4944cfe7c40019d37c81ed684f9ea0a13ceb4c Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Mon, 25 Aug 2014 18:18:37 +0400 Subject: [PATCH 1/2] decoding cyrillic headers encoded in win-1251 and koi8-r --- src/Fetch/Message.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 6a0b8c6..1e0d9d4 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -220,6 +220,7 @@ protected function loadMessage() return false; $this->subject = isset($messageOverview->subject) ? $messageOverview->subject : null; + $this->subject = self::decodeHeader($this->subject); $this->date = strtotime($messageOverview->date); $this->size = $messageOverview->size; @@ -521,6 +522,30 @@ public static function decode($data, $encoding) } } + public static function decodeHeader($header, $outEncoding = null) + { + if($header === null) { + return null; + } + + if (!$outEncoding) { + $outEncoding = self::$charset; + } + + $header = imap_mime_header_decode($header); + + $decoded = ''; + for ($i = 0; $i < count($header); $i++) { + if ($header[$i]->charset != 'default') { + $decoded .= iconv($header[$i]->charset, $outEncoding, $header[$i]->text); + } else { + $decoded .= $header[$i]->text; + } + } + + return $decoded; + } + /** * This function returns the body type that an imap integer maps to. * @@ -592,7 +617,7 @@ protected function processAddressObject($addresses) $currentAddress = array(); $currentAddress['address'] = $address->mailbox . '@' . $address->host; if (isset($address->personal)) - $currentAddress['name'] = $address->personal; + $currentAddress['name'] = self::decodeHeader($address->personal); $outputAddresses[] = $currentAddress; } From 2bd393ae0c01c718e018aceb8e2bb5aff5bf8759 Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Tue, 26 Aug 2014 11:16:02 +0400 Subject: [PATCH 2/2] fix cs --- 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 1e0d9d4..e026170 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -524,7 +524,7 @@ public static function decode($data, $encoding) public static function decodeHeader($header, $outEncoding = null) { - if($header === null) { + if ($header === null) { return null; }