From ece5c91a2f084ac70df34c369da7302ef6f8e6c8 Mon Sep 17 00:00:00 2001 From: barbushin Date: Sat, 11 Nov 2017 10:10:41 +0800 Subject: [PATCH] Fix fatal error of imap_mime_header_decode closes #202 --- src/PhpImap/Mailbox.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/PhpImap/Mailbox.php b/src/PhpImap/Mailbox.php index bbd7ca1f..e63ecb3f 100644 --- a/src/PhpImap/Mailbox.php +++ b/src/PhpImap/Mailbox.php @@ -703,14 +703,13 @@ protected function initMailPart(IncomingMail $mail, $partStructure, $partNum, $m } } - protected function decodeMimeStr($string, $charset = 'utf-8') { + protected function decodeMimeStr($string, $toCharset = 'utf-8') { $newString = ''; - $elements = imap_mime_header_decode($string); - for($i = 0; $i < count($elements); $i++) { - if($elements[$i]->charset == 'default') { - $elements[$i]->charset = 'iso-8859-1'; + foreach(imap_mime_header_decode($string) as $element) { + if(isset($element->text)) { + $fromCharset = !isset($element->charset) || $element->charset == 'default' ? 'iso-8859-1' : $element->charset; + $newString .= $this->convertStringEncoding($element->text, $fromCharset, $toCharset); } - $newString .= $this->convertStringEncoding($elements[$i]->text, $elements[$i]->charset, $charset); } return $newString; }