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
*/
static public function parseHeaders($text)
{
- $headers = new Horde_Mime_Headers();
$currheader = $currtext = null;
$mime = self::mimeParamFields();
+ $to_process = array();
require_once 'Horde/String.php';
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, ':');
$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;
}
* messages. */
const RFC_EOL = "\r\n";
- /* The default MIME character set. */
- const DEFAULT_CHARSET = 'us-ascii';
-
/* The default MIME disposition. */
const DEFAULT_DISPOSITION = 'inline';
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'.
*
/* 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'])) {