adding workaround for encoding of long multibyte headers. Saves my head from
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 31 Jul 2005 13:18:24 +0000 (13:18 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 31 Jul 2005 13:18:24 +0000 (13:18 +0000)
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
functions/mime.php
functions/strings.php

index 4cac9969bda494b5c9f8b1ab2a968667237ae54d..0cde993530ea1bed8a64f8a4741a40f47feab35b 100644 (file)
--- 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
 -------------------------------
index 98acbd543b9e13e02507ed7c7a2ef59daad0ce10..48a410a3c4492aac6bef17db995767a348fcfd2a 100644 (file)
@@ -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;
index 22f61f1b0459a4dc710c5c9eb0d4995d12a24aa8..f964d0df3a83e373f0c8fe22596ddf613e150a8e 100644 (file)
@@ -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<strlen($string); $i++) {
+        if (ord($string[$i]) > 127) $count++;
+    }
+    return $count;
+}
 $PHP_SELF = php_self();
 ?>
\ No newline at end of file