From a24cf7107fcb7abcdd251c5c64978e6a1fbda75b Mon Sep 17 00:00:00 2001 From: tokul Date: Sun, 31 Jul 2005 13:18:24 +0000 Subject: [PATCH] adding workaround for encoding of long multibyte headers. Saves my head from debugging of encodeHeader. adding information about made changes to changelog. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9854 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 7 +++++++ functions/mime.php | 22 ++++++++++++++++++---- functions/strings.php | 13 +++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4cac9969..0cde9935 100644 --- a/ChangeLog +++ b/ChangeLog @@ -404,6 +404,13 @@ Version 1.5.1 -- CVS E_NOTICE level warnings in php 5.0.4 and later (#1206474). [php5] - Added extra checks in SquirrelMail charset_encode() function in case somebody removed html to us-ascii conversion library (#1239782). + - Fixed invalid reference in src/download.php. E_NOTICE level warnings + could corrupt attachments in php 4.4.0. + - Added internal dgettext() and dngettext() functions. + - Added display of attachments on printer friendly page. + - Added workarounds for encoding of long multibyte headers (#1246305) + and sq_count8bit() function. + - Added custom error handling class and related functions. Version 1.5.0 - 2 February 2004 ------------------------------- diff --git a/functions/mime.php b/functions/mime.php index 98acbd54..48a410a3 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -781,11 +781,16 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) { } /** - * Encodes header as quoted-printable + * Encodes header * - * Encode a string according to RFC 1522 for use in headers if it - * contains 8-bit characters or anything that looks like it should - * be encoded. + * Function uses XTRA_CODE _encodeheader function, if such function exists. + * + * mb_encode_mimeheader is used, if function is present, 50% or more bytes + * are 8bit and multibyte character set is used. + * + * Function uses Q encoding by default and encodes a string according to RFC + * 1522 for use in headers if it contains 8-bit characters or anything that + * looks like it should be encoded. * * @param string $string header string, that has to be encoded * @return string quoted-printable encoded string @@ -798,6 +803,15 @@ function encodeHeader ($string) { return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encodeheader', $string); } + // Use B encoding for multibyte charsets + $mb_charsets = array('utf-8','big-5','gb2313','euc-kr'); + if (function_exists('mb_encode_mimeheader') && + in_array($default_charset,$mb_charsets) && + in_array($default_charset,sq_mb_list_encodings()) && + sq_count8bit($string)>=(strlen($string)/2)) { + return mb_encode_mimeheader($string,$default_charset,'B',"\r\n"); + } + // Encode only if the string contains 8-bit characters or =? $j = strlen($string); $max_l = 75 - strlen($default_charset) - 7; diff --git a/functions/strings.php b/functions/strings.php index 22f61f1b..f964d0df 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -1311,5 +1311,18 @@ function sq_strtoupper($string,$charset='auto') { // use vanilla string functions as last option return strtoupper($string); } + +/** + * Counts 8bit bytes in string + * @param string $string tested string + * @return integer number of 8bit bytes + */ +function sq_count8bit($string) { + $count=0; + for ($i=0; $i 127) $count++; + } + return $count; +} $PHP_SELF = php_self(); ?> \ No newline at end of file -- 2.25.1