From 33966a5c192dde8894724161b6cb1eead87444d0 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 16 Dec 2008 13:03:36 -0700 Subject: [PATCH] Reintroduce default charset feature. --- framework/Mime/lib/Horde/Mime/Headers.php | 27 +++++++++++++++++++++++---- framework/Mime/lib/Horde/Mime/Part.php | 18 +++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/framework/Mime/lib/Horde/Mime/Headers.php b/framework/Mime/lib/Horde/Mime/Headers.php index 2622fa19a..043390fc6 100644 --- a/framework/Mime/lib/Horde/Mime/Headers.php +++ b/framework/Mime/lib/Horde/Mime/Headers.php @@ -14,6 +14,14 @@ class Horde_Mime_Headers { /** + * The default charset to use when parsing text parts with no charset + * information. + * + * @var string + */ + static public $defaultCharset = 'us-ascii'; + + /** * The internal headers array. * * @var array @@ -516,9 +524,9 @@ class Horde_Mime_Headers */ static public function parseHeaders($text) { - $headers = new Horde_Mime_Headers(); $currheader = $currtext = null; $mime = self::mimeParamFields(); + $to_process = array(); require_once 'Horde/String.php'; @@ -534,9 +542,9 @@ class Horde_Mime_Headers if (!is_null($currheader)) { if (in_array(String::lower($currheader), $mime)) { $res = Horde_Mime::decodeParam($currheader . ': ' . $currtext); - $headers->addHeader($currheader, $res['val'], array('decode' => true, 'params' => $res['params'])); + $to_process[] = array($currheader, $res['val'], array('decode' => true, 'params' => $res['params'])); } else { - $headers->addHeader($currheader, $currtext, array('decode' => true)); + $to_process[] = array($currheader, $currtext, array('decode' => true)); } } $pos = strpos($val, ':'); @@ -544,7 +552,18 @@ class Horde_Mime_Headers $currtext = ltrim(substr($val, $pos + 1)); } } - $headers->addHeader($currheader, $currtext, array('decode' => true)); + $to_process[] = array($currheader, $currtext, array('decode' => true)); + + $headers = new Horde_Mime_Headers(); + $eightbit_check = (self::$defaultCharset != 'us-ascii'); + + reset($to_process); + while (list(,$val) = each($to_process)) { + if ($eightbit_check && Horde_Mime::is8bit($val[1])) { + $val[1] = String::convertCharset($val[1], self::$defaultCharset); + } + $headers->addHeader($val[0], $val[1], $val[2]); + } return $headers; } diff --git a/framework/Mime/lib/Horde/Mime/Part.php b/framework/Mime/lib/Horde/Mime/Part.php index 38aa7f5fc..629ee840e 100644 --- a/framework/Mime/lib/Horde/Mime/Part.php +++ b/framework/Mime/lib/Horde/Mime/Part.php @@ -25,9 +25,6 @@ class Horde_Mime_Part * messages. */ const RFC_EOL = "\r\n"; - /* The default MIME character set. */ - const DEFAULT_CHARSET = 'us-ascii'; - /* The default MIME disposition. */ const DEFAULT_DISPOSITION = 'inline'; @@ -35,6 +32,14 @@ class Horde_Mime_Part const DEFAULT_ENCODING = '7bit'; /** + * The default charset to use when parsing text parts with no charset + * information. + * + * @var string + */ + static public $defaultCharset = 'us-ascii'; + + /** * The type (ex.: text) of this part. * Per RFC 2045, the default is 'application'. * @@ -1499,10 +1504,9 @@ class Horde_Mime_Part /* Set the default character set. */ if (($data['subtype'] == 'text') && - (String::lower($ob->getCharset()) == 'us-ascii') && - isset($GLOBALS['mime_structure']['default_charset'])) { - /* @todo - switch to using static variable for this. */ - //$ob->setCharset($GLOBALS['mime_structure']['default_charset']); + (self::$defaultCharset != 'us-ascii') && + (String::lower($ob->getCharset()) == 'us-ascii')) { + $ob->setCharset(self::$defaultCharset); } if (isset($data['description'])) { -- 2.11.0