diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 6a0b8c6..e026170 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; }