From: kink Date: Mon, 28 Oct 2002 13:00:44 +0000 (+0000) Subject: Merge utf7_decode_local and utf7_encode_local into one file. X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=334a77f8f7c38de19fdcab6cf33e3bde10163166 Merge utf7_decode_local and utf7_encode_local into one file. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4048 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index f8402f8c..f5ded326 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -10,8 +10,8 @@ * * $Id$ */ -require_once(SM_PATH . 'functions/imap_utf7_encode_local.php'); -require_once(SM_PATH . 'functions/imap_utf7_decode_local.php'); +require_once(SM_PATH . 'functions/imap_utf7_local.php'); + global $boxesnew; class mailboxes { diff --git a/functions/imap_utf7_decode_local.php b/functions/imap_utf7_decode_local.php deleted file mode 100644 index 044b5781..00000000 --- a/functions/imap_utf7_decode_local.php +++ /dev/null @@ -1,86 +0,0 @@ - 0, "B" => 1, "C" => 2, "D" => 3, "E" => 4, "F" => 5, - "G" => 6, "H" => 7, "I" => 8, "J" => 9, "K" => 10, "L" => 11, - "M" => 12, "N" => 13, "O" => 14, "P" => 15, "Q" => 16, "R" => 17, - "S" => 18, "T" => 19, "U" => 20, "V" => 21, "W" => 22, "X" => 23, - "Y" => 24, "Z" => 25, - "a" => 26, "b" => 27, "c" => 28, "d" => 29, "e" => 30, "f" => 31, - "g" => 32, "h" => 33, "i" => 34, "j" => 35, "k" => 36, "l" => 37, - "m" => 38, "n" => 39, "o" => 40, "p" => 41, "q" => 42, "r" => 43, - "s" => 44, "t" => 45, "u" => 46, "v" => 47, "w" => 48, "x" => 49, - "y" => 50, "z" => 51, - "0" => 52, "1" => 53, "2" => 54, "3" => 55, "4" => 56, "5" => 57, - "6" => 58, "7" => 59, "8" => 60, "9" => 61, "+" => 62, "," => 63 - ); - $p = 0; - $d = ''; - $unicodeNullByteToggle = 0; - for ($i = 0; $i < strlen($s); $i++) { - $c = $s[$i]; - if ($p == 0) { - $t = $B64Values[$c]; - $p = 1; - } elseif ($p == 1) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 2) + (($B64Values[$c] & 48) >> 4)); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 15); - $p = 2; - } elseif ($p == 2) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 4) + (($B64Values[$c] & 60) >> 2)); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 3); - $p = 3; - } elseif ($p == 3) { - if ($unicodeNullByteToggle) { - $d = $d . chr(($t << 6) + $B64Values[$c]); - $unicodeNullByteToggle = 0; - } else { - $unicodeNullByteToggle = 1; - } - $t = ($B64Values[$c] & 3); - $p = 0; - } - } - return $d; -} - -function imap_utf7_decode_local($s) { - $b64_s = ''; - $iso_8859_1_s = ''; - for ($i = 0; $i < strlen($s); $i++) { - $c = $s[$i]; - if (strlen($b64_s) > 0) { - if ($c == '-') { - if ($b64_s == '&') { - $iso_8859_1_s = $iso_8859_1_s . '&'; - } else { - $iso_8859_1_s = $iso_8859_1_s . - decodeBASE64(substr($b64_s, 1)); - } - $b64_s = ''; - } else { - $b64_s = $b64_s . $c; - } - } else { - if ($c == '&') { - $b64_s = '&'; - } else { - $iso_8859_1_s = $iso_8859_1_s . $c; - } - } - } - return $iso_8859_1_s; -} - -?> diff --git a/functions/imap_utf7_encode_local.php b/functions/imap_utf7_encode_local.php deleted file mode 100644 index 020fcda7..00000000 --- a/functions/imap_utf7_encode_local.php +++ /dev/null @@ -1,68 +0,0 @@ -> 2), 1); - $t = (ord($c) & 3); - $p = 1; - } elseif ($p == 1) { - $e = $e . $B64Chars[($t << 4) + ((ord($c) & 240) >> 4)]; - $t = (ord($c) & 15); - $p = 2; - } elseif ($p == 2) { - $e = $e . $B64Chars[($t << 2) + ((ord($c) & 192) >> 6)]; - $e = $e . $B64Chars[ord($c) & 63]; - $p = 0; - } - } - // - // flush buffer - // - if ($p == 1) { - $e = $e . $B64Chars[$t << 4]; - } elseif ($p == 2) { - $e = $e . $B64Chars[$t << 2]; - } - return $e; -} - -function imap_utf7_encode_local($s) { - $b64_s = ''; // buffer for substring to be base64-encoded - $utf7_s = ''; // imap-utf7-encoded string - for ($i = 0; $i < strlen($s); $i++) { - $c = $s[$i]; - $ord_c = ord($c); - if ((($ord_c >= 0x20) and ($ord_c <= 0x25)) or - (($ord_c >= 0x27) and ($ord_c <= 0x7e))) { - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) .'-'; - $b64_s = ''; - } - $utf7_s = $utf7_s . $c; - } elseif ($ord_c == 0x26) { - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; - $b64_s = ''; - } - $utf7_s = $utf7_s . '&-'; - } else { - $b64_s = $b64_s . chr(0) . $c; - } - } - // - // flush buffer - // - if ($b64_s) { - $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; - $b64_s = ''; - } - return $utf7_s; -} - -?> diff --git a/functions/imap_utf7_local.php b/functions/imap_utf7_local.php new file mode 100644 index 00000000..9515f21d --- /dev/null +++ b/functions/imap_utf7_local.php @@ -0,0 +1,162 @@ += 0x20) and ($ord_c <= 0x25)) or + (($ord_c >= 0x27) and ($ord_c <= 0x7e))) { + if ($b64_s) { + $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) .'-'; + $b64_s = ''; + } + $utf7_s = $utf7_s . $c; + } elseif ($ord_c == 0x26) { + if ($b64_s) { + $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; + $b64_s = ''; + } + $utf7_s = $utf7_s . '&-'; + } else { + $b64_s = $b64_s . chr(0) . $c; + } + } + // + // flush buffer + // + if ($b64_s) { + $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-'; + $b64_s = ''; + } + return $utf7_s; +} + +function imap_utf7_decode_local($s) { + $b64_s = ''; + $iso_8859_1_s = ''; + for ($i = 0, $len = strlen($s); $i < $len; $i++) { + $c = $s[$i]; + if (strlen($b64_s) > 0) { + if ($c == '-') { + if ($b64_s == '&') { + $iso_8859_1_s = $iso_8859_1_s . '&'; + } else { + $iso_8859_1_s = $iso_8859_1_s . + decodeBASE64(substr($b64_s, 1)); + } + $b64_s = ''; + } else { + $b64_s = $b64_s . $c; + } + } else { + if ($c == '&') { + $b64_s = '&'; + } else { + $iso_8859_1_s = $iso_8859_1_s . $c; + } + } + } + return $iso_8859_1_s; +} + +function encodeBASE64($s) { + $B64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,'; + $p = 0; // phase: 1 / 2 / 3 / 1 / 2 / 3... + $e = ''; // base64-encoded string + //foreach($s as $c) { + for ($i = 0; $i < strlen($s); $i++) { + $c = $s[$i]; + if ($p == 0) { + $e = $e . substr($B64Chars, ((ord($c) & 252) >> 2), 1); + $t = (ord($c) & 3); + $p = 1; + } elseif ($p == 1) { + $e = $e . $B64Chars[($t << 4) + ((ord($c) & 240) >> 4)]; + $t = (ord($c) & 15); + $p = 2; + } elseif ($p == 2) { + $e = $e . $B64Chars[($t << 2) + ((ord($c) & 192) >> 6)]; + $e = $e . $B64Chars[ord($c) & 63]; + $p = 0; + } + } + // + // flush buffer + // + if ($p == 1) { + $e = $e . $B64Chars[$t << 4]; + } elseif ($p == 2) { + $e = $e . $B64Chars[$t << 2]; + } + return $e; +} + +function decodeBASE64($s) { + $B64Values = array( + 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, + 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, + 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, + 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, + 'Y' => 24, 'Z' => 25, + 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31, + 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37, + 'm' => 38, 'n' => 39, 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43, + 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 'w' => 48, 'x' => 49, + 'y' => 50, 'z' => 51, + '0' => 52, '1' => 53, '2' => 54, '3' => 55, '4' => 56, '5' => 57, + '6' => 58, '7' => 59, '8' => 60, '9' => 61, '+' => 62, ',' => 63 + ); + $p = 0; + $d = ''; + $unicodeNullByteToggle = 0; + for ($i = 0, $len = strlen($s); $i < $len; $i++) { + $c = $s[$i]; + if ($p == 0) { + $t = $B64Values[$c]; + $p = 1; + } elseif ($p == 1) { + if ($unicodeNullByteToggle) { + $d = $d . chr(($t << 2) + (($B64Values[$c] & 48) >> 4)); + $unicodeNullByteToggle = 0; + } else { + $unicodeNullByteToggle = 1; + } + $t = ($B64Values[$c] & 15); + $p = 2; + } elseif ($p == 2) { + if ($unicodeNullByteToggle) { + $d = $d . chr(($t << 4) + (($B64Values[$c] & 60) >> 2)); + $unicodeNullByteToggle = 0; + } else { + $unicodeNullByteToggle = 1; + } + $t = ($B64Values[$c] & 3); + $p = 3; + } elseif ($p == 3) { + if ($unicodeNullByteToggle) { + $d = $d . chr(($t << 6) + $B64Values[$c]); + $unicodeNullByteToggle = 0; + } else { + $unicodeNullByteToggle = 1; + } + $t = ($B64Values[$c] & 3); + $p = 0; + } + } + return $d; +} + +?> diff --git a/src/folders.php b/src/folders.php index 07b636f4..83e513e7 100644 --- a/src/folders.php +++ b/src/folders.php @@ -18,7 +18,6 @@ define('SM_PATH','../'); /* SquirrelMail required files. */ require_once(SM_PATH . 'include/validate.php'); -require_once(SM_PATH . 'functions/imap_utf7_decode_local.php'); require_once(SM_PATH . 'functions/imap.php'); require_once(SM_PATH . 'functions/plugin.php'); require_once(SM_PATH . 'functions/html.php'); diff --git a/src/folders_delete.php b/src/folders_delete.php index dbd915b2..b1ba8137 100644 --- a/src/folders_delete.php +++ b/src/folders_delete.php @@ -61,7 +61,7 @@ if(!isset($_POST['confirmed'])) { ) . html_tag( 'tr' ) . html_tag( 'td', '', 'center', $color[4] ) . - sprintf(_("Are you sure you want to delete %s?"), $mailbox). + sprintf(_("Are you sure you want to delete %s?"), imap_utf7_decode_local($mailbox)). '

'. '\n" .