diff --git a/include/class.format.php b/include/class.format.php index f016896deb39cfefb05b43bf4913bb06feb6fe84..6a878f6f272267431c659f793cf2547ddeb631e5 100644 --- a/include/class.format.php +++ b/include/class.format.php @@ -43,10 +43,10 @@ class Format { // Cleanup - incorrect, bogus, or ambiguous charsets if($charset && in_array(strtolower(trim($charset)), - array('default','x-user-defined','iso'))) + array('default','x-user-defined','iso','us-ascii'))) $charset = 'ISO-8859-1'; - if (strcasecmp($charset, $encoding) === 0) + if ($charset && strcasecmp($charset, $encoding) === 0) return $text; $original = $text; diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 2e5089a5742e0ac9dc3b097dfbf5ef1780df32df..82da3e7f4024f155ddbdf8c79f5b1fc5fa9e8174 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -304,12 +304,16 @@ class MailFetcher { $text=$this->decode($text, $struct->encoding); $charset=null; - if($encoding) { //Convert text to desired mime encoding... - if($struct->ifparameters) { - if(!strcasecmp($struct->parameters[0]->attribute,'CHARSET') && strcasecmp($struct->parameters[0]->value,'US-ASCII')) - $charset=trim($struct->parameters[0]->value); + if ($encoding) { //Convert text to desired mime encoding... + if ($struct->ifparameters && $struct->parameters) { + foreach ($struct->parameters as $p) { + if (!strcasecmp($p->attribute, 'charset')) { + $charset = trim($p->value); + break; + } + } } - $text=$this->mime_encode($text, $charset, $encoding); + $text = $this->mime_encode($text, $charset, $encoding); } return $text; } diff --git a/include/class.mailparse.php b/include/class.mailparse.php index 039a48b74be371ed1def64f502cad0db16c8506e..6a9cd1a8965cb4b81b575aba393707732057ea79 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -177,8 +177,9 @@ class Mail_Parse { if($ctype && strcasecmp($ctype,$ctypepart)==0) { $content = $struct->body; //Encode to desired encoding - ONLY if charset is known?? - if(isset($struct->ctype_parameters['charset']) && strcasecmp($struct->ctype_parameters['charset'], $this->charset)) - $content = Format::encode($content, $struct->ctype_parameters['charset'], $this->charset); + if (isset($struct->ctype_parameters['charset'])) + $content = Format::encode($content, + $struct->ctype_parameters['charset'], $this->charset); return $content; }