Browse Source

adding workaround for encoding of long multibyte headers. Saves my head from
debugging of encodeHeader.

adding information about made changes to changelog.

tokul 20 years ago
parent
commit
5375447f43
3 changed files with 38 additions and 4 deletions
  1. 7 0
      ChangeLog
  2. 18 4
      functions/mime.php
  3. 13 0
      functions/strings.php

+ 7 - 0
ChangeLog

@@ -404,6 +404,13 @@ Version 1.5.1 -- CVS
     E_NOTICE level warnings in php 5.0.4 and later (#1206474). [php5]
     E_NOTICE level warnings in php 5.0.4 and later (#1206474). [php5]
   - Added extra checks in SquirrelMail charset_encode() function in case
   - Added extra checks in SquirrelMail charset_encode() function in case
     somebody removed html to us-ascii conversion library (#1239782).
     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
 Version 1.5.0 - 2 February 2004
 -------------------------------
 -------------------------------

+ 18 - 4
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
  * @param string $string header string, that has to be encoded
  * @return string quoted-printable encoded string
  * @return string quoted-printable encoded string
@@ -798,6 +803,15 @@ function encodeHeader ($string) {
         return  call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_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 =?
     // Encode only if the string contains 8-bit characters or =?
     $j = strlen($string);
     $j = strlen($string);
     $max_l = 75 - strlen($default_charset) - 7;
     $max_l = 75 - strlen($default_charset) - 7;

+ 13 - 0
functions/strings.php

@@ -1311,5 +1311,18 @@ function sq_strtoupper($string,$charset='auto') {
     // use vanilla string functions as last option
     // use vanilla string functions as last option
     return strtoupper($string);
     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();
 $PHP_SELF = php_self();
 ?>
 ?>