From: tokul Date: Fri, 2 Jan 2004 09:28:32 +0000 (+0000) Subject: adding phpdoc blocks for encodeHeader and decodeHeader X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=9f7f68c32952edf1ec9bbdbb2ee2bb4507ae1636 adding phpdoc blocks for encodeHeader and decodeHeader adding support for header decoding in compose using space html code instead of non-breaking space code. Some charsets does not support nbsp and it also causes problems in browsers that don't change nbsp to regural space in POST forms. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6355 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/mime.php b/functions/mime.php index f7c3379d..32bdcb22 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -585,12 +585,20 @@ function decodeBody($body, $encoding) { return $body; } -/* +/** + * Decodes headers + * * This functions decode strings that is encoded according to * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text). * Patched by Christian Schmidt 23/03/2002 + * + * @param string $string header string that has to be made readable + * @param boolean $utfencode change message in order to be readable on user's charset. defaults to true + * @param boolean $htmlsave preserve spaces and sanitize html special characters. defaults to true + * @param boolean $decide decide if string can be utfencoded. defaults to false + * @return string decoded header string */ -function decodeHeader ($string, $utfencode=true,$htmlsave=true) { +function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) { global $languages, $squirrelmail_language; if (is_array($string)) { $string = implode("\n", $string); @@ -623,7 +631,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { /* if the last chunk isn't an encoded string then put back the space, otherwise don't */ if ($iLastMatch !== $j) { if ($htmlsave) { - $ret .= ' '; + $ret .= ' '; } else { $ret .= ' '; } @@ -642,6 +650,13 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { $replace = str_replace('_', ' ', $res[4]); $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))', $replace); + /* decide about valid decoding */ + if ($decide && is_conversion_safe($res[2])) { + $utfencode=true; + $can_be_decoded=true; + } else { + $can_be_decoded=false; + } /* Only encode into entities by default. Some places * don't need the encoding, like the compose form. */ @@ -662,7 +677,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { } if (!$encoded) { if ($htmlsave) { - $ret .= ' '; + $ret .= ' '; } else { $ret .= ' '; } @@ -678,7 +693,7 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { /* remove the first added space */ if ($ret) { if ($htmlsave) { - $ret = substr($ret,6); + $ret = substr($ret,5); } else { $ret = substr($ret,1); } @@ -687,10 +702,15 @@ function decodeHeader ($string, $utfencode=true,$htmlsave=true) { return $ret; } -/* +/** + * Encodes header as quoted-printable + * * 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. + * + * @param string $string header string, that has to be encoded + * @return string quoted-printable encoded string */ function encodeHeader ($string) { global $default_charset, $languages, $squirrelmail_language; @@ -699,9 +719,10 @@ function encodeHeader ($string) { function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { return $languages[$squirrelmail_language]['XTRA_CODE']('encodeheader', $string); } - if (strtolower($default_charset) == 'iso-8859-1') { - $string = str_replace("\240",' ',$string); - } + // instead of removing nbsp here, we don't add it in decodeHeader + // if (strtolower($default_charset) == 'iso-8859-1') { + // $string = str_replace("\240",' ',$string); + //} // Encode only if the string contains 8-bit characters or =? $j = strlen($string);