From 79e07c7eab3d394723d62116db58d0f8782d841e Mon Sep 17 00:00:00 2001 From: philippe_mingo Date: Sun, 24 Mar 2002 08:09:35 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2628 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 8 ++++++ functions/mime.php | 57 +++++++++++++++++--------------------- functions/strings.php | 8 ------ 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index f6c8d42a..ed38a964 100755 --- a/functions/imap_mailbox.php +++ b/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 diff --git a/functions/mime.php b/functions/mime.php index 14b3eae2..45f385b0 100644 --- a/functions/mime.php +++ b/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 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 ); } /* diff --git a/functions/strings.php b/functions/strings.php index ac70ae62..7f8f5b0e 100644 --- a/functions/strings.php +++ b/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; -- 2.25.1