c2c9ae538d97f1239848477a1e4c28cea8775b26
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This implements all functions that do general imap functions.
14 function imap_utf7_encode_local($s) {
15 global $languages, $squirrelmail_language;
17 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
18 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
19 return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_encode', $s);
22 $b64_s = ''; // buffer for substring to be base64-encoded
23 $utf7_s = ''; // imap-utf7-encoded string
24 for ($i = 0; $i < strlen($s); $i++
) {
27 if ((($ord_c >= 0x20) and ($ord_c <= 0x25)) or
28 (($ord_c >= 0x27) and ($ord_c <= 0x7e))) {
30 $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) .'-';
33 $utf7_s = $utf7_s . $c;
34 } elseif ($ord_c == 0x26) {
36 $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-';
39 $utf7_s = $utf7_s . '&-';
41 $b64_s = $b64_s . chr(0) . $c;
48 $utf7_s = $utf7_s . '&' . encodeBASE64($b64_s) . '-';
54 function imap_utf7_decode_local($s) {
55 global $languages, $squirrelmail_language;
57 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
58 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
59 return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_decode', $s);
64 for ($i = 0, $len = strlen($s); $i < $len; $i++
) {
66 if (strlen($b64_s) > 0) {
69 $iso_8859_1_s = $iso_8859_1_s . '&';
71 $iso_8859_1_s = $iso_8859_1_s .
72 decodeBASE64(substr($b64_s, 1));
82 $iso_8859_1_s = $iso_8859_1_s . $c;
89 function encodeBASE64($s) {
90 $B64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,';
91 $p = 0; // phase: 1 / 2 / 3 / 1 / 2 / 3...
92 $e = ''; // base64-encoded string
94 for ($i = 0; $i < strlen($s); $i++
) {
97 $e = $e . substr($B64Chars, ((ord($c) & 252) >> 2), 1);
101 $e = $e . $B64Chars[($t << 4) +
((ord($c) & 240) >> 4)];
105 $e = $e . $B64Chars[($t << 2) +
((ord($c) & 192) >> 6)];
106 $e = $e . $B64Chars[ord($c) & 63];
114 $e = $e . $B64Chars[$t << 4];
116 $e = $e . $B64Chars[$t << 2];
121 function decodeBASE64($s) {
123 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5,
124 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11,
125 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17,
126 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23,
127 'Y' => 24, 'Z' => 25,
128 'a' => 26, 'b' => 27, 'c' => 28, 'd' => 29, 'e' => 30, 'f' => 31,
129 'g' => 32, 'h' => 33, 'i' => 34, 'j' => 35, 'k' => 36, 'l' => 37,
130 'm' => 38, 'n' => 39, 'o' => 40, 'p' => 41, 'q' => 42, 'r' => 43,
131 's' => 44, 't' => 45, 'u' => 46, 'v' => 47, 'w' => 48, 'x' => 49,
132 'y' => 50, 'z' => 51,
133 '0' => 52, '1' => 53, '2' => 54, '3' => 55, '4' => 56, '5' => 57,
134 '6' => 58, '7' => 59, '8' => 60, '9' => 61, '+' => 62, ',' => 63
138 $unicodeNullByteToggle = 0;
139 for ($i = 0, $len = strlen($s); $i < $len; $i++
) {
145 if ($unicodeNullByteToggle) {
146 $d = $d . chr(($t << 2) +
(($B64Values[$c] & 48) >> 4));
147 $unicodeNullByteToggle = 0;
149 $unicodeNullByteToggle = 1;
151 $t = ($B64Values[$c] & 15);
154 if ($unicodeNullByteToggle) {
155 $d = $d . chr(($t << 4) +
(($B64Values[$c] & 60) >> 2));
156 $unicodeNullByteToggle = 0;
158 $unicodeNullByteToggle = 1;
160 $t = ($B64Values[$c] & 3);
163 if ($unicodeNullByteToggle) {
164 $d = $d . chr(($t << 6) +
$B64Values[$c]);
165 $unicodeNullByteToggle = 0;
167 $unicodeNullByteToggle = 1;
169 $t = ($B64Values[$c] & 3);