function imap_utf7_encode_local($s) { global $languages, $squirrelmail_language; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_encode', $s); } if ($s == '') { //If empty, don't bother return ''; } global $default_charset; set_my_charset(); //must be called before using $default_charset if (strtolower($default_charset) != 'iso-8859-1' && $default_charset != '') { $utf7_s = sqimap_mb_convert_encoding($s, 'UTF7-IMAP', $default_charset, $default_charset); if ($utf7_s != '') { return $utf7_s; } } // 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++) { $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; }
/** * imap_general.php * * Copyright (c) 1999-2003 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * This implements all functions that do general imap functions. * * $Id $ */ function imap_utf7_encode_local($s) { global $languages, $squirrelmail_language; if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_encode', $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; }