Skip to content

Commit

Permalink
Fix fatal error of imap_mime_header_decode
Browse files Browse the repository at this point in the history
closes #202
  • Loading branch information
barbushin committed Nov 11, 2017
1 parent 64e91cc commit ece5c91
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ece5c91

Please sign in to comment.