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
Branches
Tags
No related merge requests found
...@@ -43,10 +43,10 @@ class Format { ...@@ -43,10 +43,10 @@ class Format {
// Cleanup - incorrect, bogus, or ambiguous charsets // Cleanup - incorrect, bogus, or ambiguous charsets
if($charset && in_array(strtolower(trim($charset)), 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'; $charset = 'ISO-8859-1';
if (strcasecmp($charset, $encoding) === 0) if ($charset && strcasecmp($charset, $encoding) === 0)
return $text; return $text;
$original = $text; $original = $text;
......
...@@ -304,12 +304,16 @@ class MailFetcher { ...@@ -304,12 +304,16 @@ class MailFetcher {
$text=$this->decode($text, $struct->encoding); $text=$this->decode($text, $struct->encoding);
$charset=null; $charset=null;
if($encoding) { //Convert text to desired mime encoding... if ($encoding) { //Convert text to desired mime encoding...
if($struct->ifparameters) { if ($struct->ifparameters && $struct->parameters) {
if(!strcasecmp($struct->parameters[0]->attribute,'CHARSET') && strcasecmp($struct->parameters[0]->value,'US-ASCII')) foreach ($struct->parameters as $p) {
$charset=trim($struct->parameters[0]->value); 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; return $text;
} }
......
...@@ -177,8 +177,9 @@ class Mail_Parse { ...@@ -177,8 +177,9 @@ class Mail_Parse {
if($ctype && strcasecmp($ctype,$ctypepart)==0) { if($ctype && strcasecmp($ctype,$ctypepart)==0) {
$content = $struct->body; $content = $struct->body;
//Encode to desired encoding - ONLY if charset is known?? //Encode to desired encoding - ONLY if charset is known??
if(isset($struct->ctype_parameters['charset']) && strcasecmp($struct->ctype_parameters['charset'], $this->charset)) if (isset($struct->ctype_parameters['charset']))
$content = Format::encode($content, $struct->ctype_parameters['charset'], $this->charset); $content = Format::encode($content,
$struct->ctype_parameters['charset'], $this->charset);
return $content; return $content;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment