Skip to content

Commit

Permalink
bug: Decode mailbox when parsing an email address
Browse files Browse the repository at this point in the history
This addresses cases where incoming emails doesn't include charset and
mailbox may include non-ascii characters.
  • Loading branch information
protich authored and Jared Hancock committed Oct 13, 2014
1 parent 43c50ba commit fbd0b88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions include/class.format.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ function mimedecode($text, $encoding='UTF-8') {
$str.= Format::encode($part->text, $part->charset, $encoding);

$text = $str;
} elseif(function_exists('iconv_mime_decode')) {
} elseif($text[0] == '=' && function_exists('iconv_mime_decode')) {
$text = iconv_mime_decode($text, 0, $encoding);
} elseif(!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
} elseif(!strcasecmp($encoding, 'utf-8')
&& function_exists('imap_utf8')) {
$text = imap_utf8($text);
}

Expand Down
8 changes: 7 additions & 1 deletion include/class.mailparse.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,18 @@ function parseAddressList($address){

$parsed = Mail_RFC822::parseAddressList($address, null, null,false);

if(PEAR::isError($parsed))
if (PEAR::isError($parsed))
return array();

// Decode name and mailbox
foreach ($parsed as $p) {
$p->personal = Format::mimedecode($p->personal, $this->charset);
// Some mail clients may send ISO-8859-1 strings without proper encoding.
// Also, handle the more sane case where the mailbox is properly encoded
// against RFC2047
$p->mailbox = Format::mimedecode($p->mailbox, $this->charset);
}

return $parsed;
}

Expand Down

0 comments on commit fbd0b88

Please sign in to comment.