Skip to content
Snippets Groups Projects
Commit a786b0b2 authored by Jared Hancock's avatar Jared Hancock
Browse files

Support incorrectly labeled us-ascii charsets

Some email clients (names omitted to protect the innocent) advertise the
encoding as us-ascii when iso-8859-1 was really implied. This patch allows
the two charsets to be interchangable.
parent bd0169ba
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment