[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squirrelmail-cvs
Subject:    [SM-CVS] CVS: squirrelmail/functions mime.php,1.346,1.347 strings.php,1.231,1.232
From:       Tomas Kuliavas <tokul () users ! sourceforge ! net>
Date:       2005-07-31 13:18:29
Message-ID: E1DzDi1-0000Mn-Ss () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]

Update of /cvsroot/squirrelmail/squirrelmail/functions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv991/functions

Modified Files:
	mime.php strings.php 
Log Message:
adding workaround for encoding of long multibyte headers. Saves my head from
debugging of encodeHeader.

adding information about made changes to changelog.


Index: mime.php
===================================================================
RCS file: /cvsroot/squirrelmail/squirrelmail/functions/mime.php,v
retrieving revision 1.346
retrieving revision 1.347
diff -u -w -r1.346 -r1.347
--- mime.php	17 Jun 2005 20:02:25 -0000	1.346
+++ mime.php	31 Jul 2005 13:18:24 -0000	1.347
@@ -781,11 +781,16 @@
 }
 
 /**
- * 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 @@
         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: strings.php
===================================================================
RCS file: /cvsroot/squirrelmail/squirrelmail/functions/strings.php,v
retrieving revision 1.231
retrieving revision 1.232
diff -u -w -r1.231 -r1.232
--- strings.php	3 Jul 2005 09:55:10 -0000	1.231
+++ strings.php	31 Jul 2005 13:18:24 -0000	1.232
@@ -1311,5 +1311,18 @@
     // 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



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
--
squirrelmail-cvs mailing list
List Address: squirrelmail-cvs@lists.sourceforge.net
List Info: https://lists.sourceforge.net/lists/listinfo/squirrelmail-cvs
http://squirrelmail.org/cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic