Quellcode durchsuchen

Non-ascii characters caused problems with SVN function and were replaced
with a ? by SourceForge.net in your original log message, which follows:
Asunto: [SM-DEVEL] Bug in mime.php:decodeHeader()
De: Christian Schmidt <christian@ostenfeld.dk>
Fecha: S?b, 23 de Marzo de 2002, 14:48

Currently, the decodeHeader decodes headers containing several
encoded-words incorrectly. E.g. the header "=?iso-8859-1?Q?=C9?= and
=?iso-8859-1?Q?=E9?=" is decoded into "? and ?" and not into "? and ?"
as expected.

Also, it currently does not ignore white-space between consecutive
encoded-words as it should.

philippe_mingo vor 23 Jahren
Ursprung
Commit
13cfb682e6
3 geänderte Dateien mit 34 neuen und 39 gelöschten Zeilen
  1. 8 0
      functions/imap_mailbox.php
  2. 26 31
      functions/mime.php
  3. 0 8
      functions/strings.php

+ 8 - 0
functions/imap_mailbox.php

@@ -13,6 +13,14 @@
 
 global $boxesnew;
 
+function find_mailbox_name ($mailbox) {
+    if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
+        return $regs[1];
+    ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
+    return $regs[1];
+    
+}
+
 /**
  * If $haystack is a full mailbox name, and $needle is the mailbox
  * separator character, returns the second last part of the full

+ 26 - 31
functions/mime.php

@@ -925,42 +925,37 @@ function decodeBody($body, $encoding) {
 /*
  * This functions decode strings that is encoded according to
  * RFC1522 (MIME Part Two: Message Header Extensions for Non-ASCII Text).
+ * Patched by Christian Schmidt <christian@ostenfeld.dk>  23/03/2002
  */
 function decodeHeader ($string, $utfencode=true) {
+    if (is_array($string)) {
+        $string = implode("\n", $string);
+    }
+    $i = 0;
+    while (preg_match('/^(.{' . $i . '})(.*)=\?([^?]*)\?(Q|B)\?([^?]*)\?=/Ui', 
+                      $string, $res)) {
+        $prefix = $res[1];
+        // Ignore white-space between consecutive encoded-words
+        if (strspn($res[2], " \t") != strlen($res[2])) {
+            $prefix .= $res[2];
+        }
 
-if ( is_array( $string ) ) {
-    $string = implode("\n", $string );
-}
-
-if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=',
-            $string, $res)) {
-    if (ucfirst($res[2]) == 'B') {
-        $replace = base64_decode($res[3]);
-    } else {
-        $replace = str_replace('_', ' ', $res[3]);
-        // Convert lowercase Quoted Printable to uppercase for
-        // quoted_printable_decode to understand it.
-        while (ereg("(=(([0-9][abcdef])|([abcdef][0-9])|([abcdef][abcdef])))",
-               $replace, $res)) {
-            $replace = str_replace($res[1], strtoupper($res[1]), $replace);
+        if (ucfirst($res[4]) == 'B') {
+            $replace = base64_decode($res[5]);
+        } else {
+            $replace = str_replace('_', ' ', $res[5]);
+            $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))', 
+                                    $replace);
+            /* Only encode into entities by default. Some places
+               don't need the encoding, like the compose form. */
+            if ($utfencode) {
+                $replace = charset_decode($res[3], $replace);
+            }
         }
-        $replace = quoted_printable_decode($replace);
-    }
-    /* Only encode into entities by default. Some places
-        don't need the encoding, like the compose form. */
-    if ($utfencode){
-        $replace = charset_decode ($res[1], $replace);
+        $string = $prefix . $replace . substr($string, strlen($res[0]));
+        $i = strlen($prefix) + strlen($replace);
     }
-
-    // Remove the name of the character set.
-    $string = eregi_replace ('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=',
-              $replace, $string);
-
-    // In case there should be more encoding in the string: recurse
-    $string = decodeHeader($string);
-}
-
-return ($string);
+    return( $string );
 }
 
 /*

+ 0 - 8
functions/strings.php

@@ -72,14 +72,6 @@ function getLineOfAddrs($array) {
     return( $to_line );
 }
 
-function find_mailbox_name ($mailbox) {
-    if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
-        return $regs[1];
-    ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
-    return $regs[1];
-    
-}
-
 function php_self () {
     global $PHP_SELF, $HTTP_SERVER_VARS;