From 0d53f0f9ceea57812af3978f7e3d00acf35fcb70 Mon Sep 17 00:00:00 2001 From: stekkel Date: Sat, 1 Mar 2003 20:50:58 +0000 Subject: [PATCH] To much encoding. Now we only encode what's needed. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4575 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 82 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index ca43a355..f8570959 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -552,15 +552,16 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { $string = $languages[$squirrelmail_language]['XTRA_CODE']('decodeheader', $string); + return $string; } - $i = 0; $aString = explode(' ',$string); foreach ($aString as $chunk) { $encoded = false; $aString[$i] = ''; while (preg_match('/^(.*)=\?([^?]*)\?(Q|B)\?([^?]*)\?=(.*)$/Ui',$chunk,$res)) { - $aString[$i] .= $res[1]; + //$aString[$i] .= $res[1]; + //echo "match ". $res[5] . "
"; $encoding = ucfirst($res[3]); switch ($encoding) { @@ -569,7 +570,6 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { $aString[$i] .= charset_decode($res[2],$replace); break; case 'Q': - $replace = str_replace('_', ' ', $res[4]); $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))', $replace); @@ -598,11 +598,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { } ++$i; } - if (!$htmlsave) { - return implode(' ',$aString); - } else { - return implode(' ',$aString); - } + return implode(' ',$aString); } /* @@ -624,61 +620,97 @@ function encodeHeader ($string) { $max_l = 75 - strlen($default_charset) - 7; $aRet = array(); $ret = ''; - $cur_l = 0; + $enc = false; + $cur_l = $iOffset = 0; for($i = 0; $i < $j; ++$i) { switch($string{$i}) { case '=': $cur_l+=3; if ($cur_l > $max_l) { - $aRet[] = "=?$default_charset?Q?$ret?="; - $cur_l = 3; - $ret = ''; - } + if ($enc) { + $aRet[] = "=?$default_charset?Q?$ret?="; + $enc = false; + } else { + $aRet[] = substr($string,$iOffset,$i-$iOffset+1); + } + $iOffset = $i+1; + $cur_l = 3; + $ret = ''; + } $ret .= '=3D'; break; case '?': $cur_l+=3; if ($cur_l > $max_l) { - $aRet[] = "=?$default_charset?Q?$ret?="; - $cur_l = 3; - $ret = ''; - } + if ($enc) { + $aRet[] = "=?$default_charset?Q?$ret?="; + $enc = false; + } else { + $aRet[] = substr($string,$iOffset,$i-$iOffset+1); + } + $iOffset = $i+1; + $cur_l = 3; + $ret = ''; + } $ret .= '=3F'; break; case '_': $cur_l+=3; if ($cur_l > $max_l) { - $aRet[] = "=?$default_charset?Q?$ret?="; - $cur_l = 3; + if ($enc) { + $aRet[] = "=?$default_charset?Q?$ret?="; + $enc = false; + } else { + $aRet[] = substr($string,$iOffset,$i-$iOffset+1); + } + $iOffset = $i+1; + $cur_l = 3; $ret = ''; - } + } $ret .= '=5F'; break; case ' ': $cur_l++; if ($cur_l > $max_l) { - $aRet[] = "=?$default_charset?Q?$ret?="; - $cur_l = 1; - $ret = ''; + if ($enc) { + $aRet[] = "=?$default_charset?Q?$ret?="; + $enc = false; + } else { + $aRet[] = substr($string,$iOffset,$i-$iOffset+1); + } + $iOffset = $i+1; + $cur_l = 1; + $ret = ''; } $ret .= '_'; break; default: $k = ord($string{$i}); if ($k > 126) { + $enc = true; $s = sprintf("=%02X", $k); $cur_l += strlen($s); if ($cur_l > $max_l) { $aRet[] = "=?$default_charset?Q?$ret?="; $cur_l = strlen($s); $ret = ''; + $l = false; + $enc = false; + $iOffset = $i+1; } $ret .= $s; $l = TRUE; } else { $cur_l++; if ($cur_l > $max_l) { - $aRet[] = "=?$default_charset?Q?$ret?="; + if ($enc) { + $aRet[] = "=?$default_charset?Q?$ret?="; + $enc = false; + } else { + $aRet[] = substr($ret,$iOffset,$i-$iOffset+1); + } + $iOffset = $i+1; + $l = false; $cur_l = 1; $ret = ''; } @@ -688,7 +720,7 @@ function encodeHeader ($string) { } } - if ($l) { + if ($enc) { $string = implode('',$aRet) . "=?$default_charset?Q?$ret?="; } -- 2.25.1