Source for file imap_utf7_local.php
Documentation is available at imap_utf7_local.php
* functions/imap_utf7_local.php - utf7-imap functions
* This implements all functions that do imap UTF7 conversions.
* Before 1.3.2 functions were stored in imap_utf7_decode_local.php and
* imap_utf7_encode_local.php files.
* @copyright 1999-2020 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: imap_utf7_local.php 14845 2020-01-07 08:09:34Z pdontthink $
* Function that uses php mbstring functions to convert from and to utf7-imap charset
* Since 1.5.1 list of supported charsets depends sq_mb_list_encoding function.
* Before that it was hardcoded to iso-8859-x, utf-8 and iso-2022-jp.
* @param string $str folder name
* @param string $to_encoding name of resulting charset
* @param string $from_encoding name of original charset
* @param string $default_charset default charset used by translation.
* @return string encoded folder name or ''
* encode folder name to utf7-imap
* If mbstring functions do not support charset used by translation, falls back to iso-8859-1
* @param string $s folder name
* @return string utf7-imap encoded folder name
if (isset
($languages[$squirrelmail_language]['XTRA_CODE']) &&
function_exists($languages[$squirrelmail_language]['XTRA_CODE'].
'_utf7_imap_encode')) {
return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] .
'_utf7_imap_encode', $s);
if ($s ==
'') //If empty, don't bother
if ((strtolower($default_charset) !=
'iso-8859-1') &&
($default_charset !=
'')) {
// Later code works only for ISO-8859-1
$b64_s =
''; // buffer for substring to be base64-encoded
$utf7_s =
''; // imap-utf7-encoded string
for ($i =
0; $i <
strlen($s); $i++
) {
if ((($ord_c >=
0x20) and ($ord_c <=
0x25)) or
(($ord_c >=
0x27) and ($ord_c <=
0x7e))) {
} elseif ($ord_c ==
0x26) {
$utf7_s =
$utf7_s .
'&-';
$b64_s =
$b64_s .
chr(0) .
$c;
* converts folder name from utf7-imap to charset used by translation
* If mbstring functions do not support charset used by translation, falls back to iso-8859-1
* @param string $s folder name in utf7-imap
* @return string folder name in charset used by translation
if (isset
($languages[$squirrelmail_language]['XTRA_CODE']) &&
function_exists($languages[$squirrelmail_language]['XTRA_CODE'] .
'_utf7_imap_decode')) {
return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] .
'_utf7_imap_decode', $s);
if ($s ==
'') //If empty, don't bother
if ((strtolower($default_charset) !=
'iso-8859-1') &&
($default_charset !=
'')) {
// Later code works only for ISO-8859-1
for ($i =
0, $len =
strlen($s); $i <
$len; $i++
) {
$iso_8859_1_s =
$iso_8859_1_s .
'&';
$iso_8859_1_s =
$iso_8859_1_s .
$iso_8859_1_s =
$iso_8859_1_s .
$c;
* Converts string to base64
* @param string $s string
* @return string base64 encoded string
$B64Chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,';
$p =
0; // phase: 1 / 2 / 3 / 1 / 2 / 3...
$e =
''; // base64-encoded string
for ($i =
0; $i <
strlen($s); $i++
) {
$e =
$e .
substr($B64Chars, ((ord($c) & 252) >>
2), 1);
$e =
$e .
$B64Chars[($t <<
4) +
((ord($c) & 240) >>
4)];
$e =
$e .
$B64Chars[($t <<
2) +
((ord($c) & 192) >>
6)];
$e =
$e .
$B64Chars[ord($c) & 63];
$e =
$e .
$B64Chars[$t <<
4];
$e =
$e .
$B64Chars[$t <<
2];
* Converts string from base64
* @param string $s base64 encoded string
* @return string decoded string
'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,
'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,
'0' =>
52, '1' =>
53, '2' =>
54, '3' =>
55, '4' =>
56, '5' =>
57,
'6' =>
58, '7' =>
59, '8' =>
60, '9' =>
61, '+' =>
62, ',' =>
63
$unicodeNullByteToggle =
0;
for ($i =
0, $len =
strlen($s); $i <
$len; $i++
) {
if ($unicodeNullByteToggle) {
$d =
$d .
chr(($t <<
2) +
(($B64Values[$c] & 48) >>
4));
$unicodeNullByteToggle =
0;
$unicodeNullByteToggle =
1;
$t =
($B64Values[$c] & 15);
if ($unicodeNullByteToggle) {
$d =
$d .
chr(($t <<
4) +
(($B64Values[$c] & 60) >>
2));
$unicodeNullByteToggle =
0;
$unicodeNullByteToggle =
1;
$t =
($B64Values[$c] & 3);
if ($unicodeNullByteToggle) {
$d =
$d .
chr(($t <<
6) +
$B64Values[$c]);
$unicodeNullByteToggle =
0;
$unicodeNullByteToggle =
1;
$t =
($B64Values[$c] & 3);
Documentation generated on Mon, 13 Jan 2020 04:22:50 +0100 by phpDocumentor 1.4.3