Reintroduce default charset feature.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Dec 2008 20:03:36 +0000 (13:03 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Dec 2008 20:03:36 +0000 (13:03 -0700)
framework/Mime/lib/Horde/Mime/Headers.php
framework/Mime/lib/Horde/Mime/Part.php

index 2622fa1..043390f 100644 (file)
 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;
     }
index 38aa7f5..629ee84 100644 (file)
@@ -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'])) {