20 if (!defined(
'SM_PATH')) define(
'SM_PATH',
'../');
23 require_once(
SM_PATH .
'functions/global.php');
51 static $domains_already_seen = array();
57 if (empty($domain_name)) $domain_name =
'squirrelmail';
62 if (!
$use_gettext && in_array($domain_name, $domains_already_seen)) {
67 $domains_already_seen[] = $domain_name;
69 if (empty($directory)) $directory =
SM_PATH .
'locale/';
97 if (empty($dir)) $dir =
SM_PATH .
'locale/';
102 if (function_exists(
'bind_textdomain_codeset')
103 && isset(
$languages[$sm_notAlias][
'CHARSET'])) {
106 if ($sm_notAlias ==
'ja_JP') {
107 bind_textdomain_codeset (
$domain,
'EUC-JP');
132 if (is_string($locale)) {
134 $ret = setlocale($category,$locale);
139 while ( !
$ret && $index<count($locale)) {
140 $ret=setlocale($category,$locale[$index]);
145 $ret=setlocale($category,$locale);
149 if (preg_match(
"/^.*\/.*\/.*\/.*\/.*\/.*$/",
$ret)) {
187 if (! $save_html) $string = htmlspecialchars ($string);
197 global $aggressive_decoding;
198 $aggressive_decoding =
false;
201 $decodefile=
SM_PATH .
'functions/decode/' . $decode .
'.php';
202 if ($decode !=
'index' && file_exists($decodefile)) {
203 include_once($decodefile);
204 $ret = call_user_func(
'charset_decode_'.$decode, $string, $save_html);
224 $encodefile=
SM_PATH .
'functions/encode/' . $encode .
'.php';
225 if ($encode !=
'index' && file_exists($encodefile)) {
226 include_once($encodefile);
227 $ret = call_user_func(
'charset_encode_'.$encode, $string);
228 }
elseif(file_exists(
SM_PATH .
'functions/encode/us_ascii.php')) {
231 include_once(
SM_PATH .
'functions/encode/us_ascii.php');
246 if (! $htmlencode ) {
247 $ret = str_replace(array(
'&',
'>',
'<',
'"'),array(
'&',
'>',
'<',
'"'),
$ret);
332 static $SetupAlready = 0;
340 $SetupAlready = TRUE;
356 isset($accept_lang)) {
360 $sm_language = substr($accept_lang, 0, 2);
370 if ((!$sm_language||$default) &&
377 if (! $sm_language) $sm_language=
'en_US';
379 $sm_notAlias = $sm_language;
385 $sm_notAlias=
"en_US";
388 while (isset(
$languages[$sm_notAlias][
'ALIAS'])) {
389 $sm_notAlias =
$languages[$sm_notAlias][
'ALIAS'];
392 if ( isset($sm_language) &&
394 $sm_language !=
'' &&
395 isset(
$languages[$sm_notAlias][
'CHARSET']) ) {
398 if (function_exists(
'bind_textdomain_codeset')) {
399 if ($sm_notAlias ==
'ja_JP') {
400 bind_textdomain_codeset (
"squirrelmail",
'EUC-JP');
402 bind_textdomain_codeset (
"squirrelmail",
$languages[$sm_notAlias][
'CHARSET'] );
407 if (isset(
$languages[$sm_notAlias][
'LOCALE'])){
408 $longlocale=
$languages[$sm_notAlias][
'LOCALE'];
410 $longlocale=$sm_notAlias;
418 if (! is_bool($retlocale)) {
419 $longlocale=$retlocale;
420 }
elseif (is_array($longlocale)) {
423 $longlocale=$sm_notAlias;
426 if ( !((
bool)ini_get(
'safe_mode')) &&
427 getenv(
'LC_ALL' ) != $longlocale ) {
428 putenv(
"LC_ALL=$longlocale" );
429 putenv(
"LANG=$longlocale" );
430 putenv(
"LANGUAGE=$longlocale" );
431 putenv(
"LC_NUMERIC=C" );
432 if ($sm_notAlias==
'tr_TR') putenv(
"LC_CTYPE=C" );
437 setlocale(LC_NUMERIC,
'C');
440 if ($sm_notAlias==
'tr_TR') setlocale(LC_CTYPE,
'C');
444 header (
'Content-Type: text/html; charset=EUC-JP');
445 if (!function_exists(
'mb_internal_encoding')) {
454 echo
_(
"You need to have PHP installed with the multibyte string function enabled (using configure option --enable-mbstring).");
460 if (function_exists(
'mb_language')) {
461 mb_language(
'Japanese');
463 mb_internal_encoding(
'EUC-JP');
464 mb_http_output(
'pass');
468 header(
'Content-Type: text/html; charset=' .
$languages[$sm_notAlias][
'CHARSET'] );
486 function_exists(
'mb_internal_encoding') &&
488 (
int)ini_get(
'mbstring.func_overload')!=0) {
489 mb_internal_encoding(
'pass');
547 $input_charset = strtolower($input_charset);
557 if ( $input_charset ==
"iso-8859-5" ||
558 $input_charset ==
"koi8-r" ||
559 $input_charset ==
"koi8-u" ) {
565 if ( $input_charset ==
"iso-8859-13" ||
566 $input_charset ==
"iso-8859-4" ) {
572 if ( $input_charset ==
"iso-8859-13" ||
573 $input_charset ==
"windows-1257" ) {
579 if ( $input_charset ==
"windows-1251" ||
580 $input_charset ==
"koi8-r" ||
581 $input_charset ==
"koi8-u" ) {
587 if ( $input_charset ==
"iso-8859-4" ||
588 $input_charset ==
"windows-1257" ) {
594 if ( $input_charset ==
"windows-1251" ||
595 $input_charset ==
"iso-8859-5" ||
596 $input_charset ==
"koi8-u" ) {
602 if ( $input_charset ==
"windows-1251" ||
603 $input_charset ==
"iso-8859-5" ||
604 $input_charset ==
"koi8-r" ) {
619 $ret = func_get_arg(1);
620 if (function_exists(
'mb_detect_encoding')) {
621 switch (func_get_arg(0)) {
623 $detect_encoding = @mb_detect_encoding(
$ret);
624 if ($detect_encoding ==
'JIS' ||
625 $detect_encoding ==
'EUC-JP' ||
626 $detect_encoding ==
'SJIS' ||
627 $detect_encoding ==
'UTF-8') {
629 $ret = mb_convert_kana(mb_convert_encoding(
$ret,
'EUC-JP',
'AUTO'),
"KV");
633 $detect_encoding = @mb_detect_encoding(
$ret);
634 if ($detect_encoding ==
'JIS' ||
635 $detect_encoding ==
'EUC-JP' ||
636 $detect_encoding ==
'SJIS' ||
637 $detect_encoding ==
'UTF-8') {
639 $ret = mb_convert_encoding(mb_convert_kana(
$ret,
"KV"),
'JIS',
'AUTO');
643 $width = func_get_arg(2);
644 $ret = mb_strimwidth(
$ret, 0, $width,
'...');
678 if (preg_match(
'/=\?([^?]+)\?(q|b)\?([^?]+)\?=/i',
$ret))
680 $ret = @mb_convert_encoding(
$ret,
'EUC-JP',
'AUTO');
682 case 'downloadfilename':
683 $useragent = func_get_arg(2);
684 if (strstr($useragent,
'Windows') !==
false ||
685 strstr($useragent,
'Mac_') !==
false) {
686 $ret = mb_convert_encoding(
$ret,
'SJIS',
'AUTO');
688 $ret = mb_convert_encoding(
$ret,
'EUC-JP',
'AUTO');
692 $no_begin =
"\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
693 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
694 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
695 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
696 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
697 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
698 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
699 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
700 $no_end =
"\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
701 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
702 $wrap = func_get_arg(2);
704 if (strlen(
$ret) >= $wrap &&
705 substr(
$ret, 0, 1) !=
'>' &&
706 strpos(
$ret,
'http://') === FALSE &&
707 strpos(
$ret,
'https://') === FALSE &&
708 strpos(
$ret,
'ftp://') === FALSE) {
715 while ($ptr < strlen(
$ret) - 1) {
716 $l = mb_strcut(
$ret, $ptr, $wrap);
720 $l = mb_strcut(
$ret, $ptr, 2);
721 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
724 $l = mb_strcut(
$ret, $ptr, 1);
727 if ($ptr < strlen(
$ret) - 1)
733 case 'utf7-imap_encode':
734 $ret = mb_convert_encoding(
$ret,
'UTF7-IMAP',
'EUC-JP');
736 case 'utf7-imap_decode':
737 $ret = mb_convert_encoding(
$ret,
'EUC-JP',
'UTF7-IMAP');
751 $ret = func_get_arg(1);
752 if (func_get_arg(0) ==
'downloadfilename') {
753 $ret = str_replace(
"\x0D\x0A",
'',
$ret);
754 for ($i=0;$i<strlen(
$ret);$i++) {
755 if (
$ret[$i] >=
"\xA1" &&
$ret[$i] <=
"\xFE") {
758 }
else if ((
$ret[$i] >=
'a' &&
$ret[$i] <=
'z') ||
759 (
$ret[$i] >=
'A' &&
$ret[$i] <=
'Z') ||
760 (
$ret[$i] ==
'.') || (
$ret[$i] ==
'-')) {
807 $languages[
'bn_BD'][
'ALTNAME'] =
'বাংলা';
809 $languages[
'bn_BD'][
'LOCALE'] = array(
'bn_BD.UTF-8',
'bn_BD.UTF8',
'bn_BD',
'bn.UTF-8',
'bn.UTF8',
'bn');
814 $languages[
'bn_IN'][
'LOCALE'] = array(
'bn_IN.UTF-8',
'bn_IN.UTF8');
818 $languages[
'ca_ES'][
'LOCALE'] = array(
'ca_ES.ISO8859-1',
'ca_ES.ISO-8859-1',
'ca_ES');
824 $languages[
'cs_CZ'][
'LOCALE'] = array(
'cs_CZ.UTF-8',
'cs_CZ.UTF8',
'cs_CZ');
829 $languages[
'cy_GB'][
'LOCALE'] = array(
'cy_GB.ISO8859-1',
'cy_GB.ISO-8859-1',
'cy_GB');
834 $languages[
'da_DK'][
'LOCALE'] = array(
'da_DK.ISO8859-1',
'da_DK.ISO-8859-1',
'da_DK');
840 $languages[
'de_DE'][
'LOCALE'] = array(
'de_DE.ISO8859-1',
'de_DE.ISO-8859-1',
'de_DE');
845 $languages[
'el_GR'][
'LOCALE'] = array(
'el_GR.ISO8859-7',
'el_GR.ISO-8859-7',
'el_GR');
864 $languages[
'es_ES'][
'LOCALE'] = array(
'es_ES.ISO8859-1',
'es_ES.ISO-8859-1',
'es_ES');
869 $languages[
'et_EE'][
'LOCALE'] = array(
'et_EE.ISO8859-15',
'et_EE.ISO-8859-15',
'et_EE');
874 $languages[
'eu_ES'][
'LOCALE'] = array(
'eu_ES.ISO8859-1',
'eu_ES.ISO-8859-1',
'eu_ES');
879 $languages[
'fi_FI'][
'LOCALE'] = array(
'fi_FI.ISO8859-1',
'fi_FI.ISO-8859-1',
'fi_FI');
884 $languages[
'fo_FO'][
'LOCALE'] = array(
'fo_FO.ISO8859-1',
'fo_FO.ISO-8859-1',
'fo_FO');
889 $languages[
'fr_FR'][
'LOCALE'] = array(
'fr_FR.ISO8859-1',
'fr_FR.ISO-8859-1',
'fr_FR');
894 $languages[
'fy'][
'LOCALE'] = array(
'fy.UTF-8',
'fy.UTF8',
'fy_NL.UTF-8',
'fy_NL.UTF8');
898 $languages[
'hr_HR'][
'LOCALE'] = array(
'hr_HR.ISO8859-2',
'hr_HR.ISO-8859-2',
'hr_HR');
904 $languages[
'hu_HU'][
'LOCALE'] = array(
'hu_HU.UTF-8',
'hu_HU.UTF8',
'hu_HU');
909 $languages[
'id_ID'][
'LOCALE'] = array(
'id_ID.ISO8859-1',
'id_ID.ISO-8859-1',
'id_ID');
914 $languages[
'is_IS'][
'LOCALE'] = array(
'is_IS.ISO8859-1',
'is_IS.ISO-8859-1',
'is_IS');
920 $languages[
'it_IT'][
'LOCALE'] = array(
'it_IT.UTF-8',
'it_IT-UTF8',
'it_IT');
930 $languages[
'ka'][
'LOCALE'] = array(
'ka_GE.UTF-8',
'ka_GE.UTF8',
'ka_GE',
'ka');
934 $languages[
'km'][
'ALTNAME'] =
'ខ្មែរ';
936 $languages[
'km'][
'LOCALE'] = array(
'km.UTF-8',
'km.UTF8',
'km_KH.UTF-8',
'km_KH.UTF8',
'km',
'km_KH');
948 $languages[
'lv_LV'][
'LOCALE'] = array(
'lv_LV.UTF-8',
'lv_LV.UTF8');
953 $languages[
'lt_LT'][
'LOCALE'] = array(
'lt_LT.UTF-8',
'lt_LT.UTF8');
958 $languages[
'mk'][
'LOCALE'] = array(
'mk.UTF-8',
'mk.UTF8',
'mk_MK.UTF-8',
'mk_MK.UTF8');
962 $languages[
'ms_MY'][
'LOCALE'] = array(
'ms_MY.ISO8859-1',
'ms_MY.ISO-8859-1',
'ms_MY');
967 $languages[
'nl_NL'][
'LOCALE'] = array(
'nl_NL.ISO8859-1',
'nl_NL.ISO-8859-1',
'nl_NL');
972 $languages[
'nb_NO'][
'LOCALE'] = array(
'nb_NO.UTF-8',
'nb_NO.UTF8',
'nb_NO');
977 $languages[
'nn_NO'][
'LOCALE'] = array(
'nn_NO.ISO8859-1',
'nn_NO.ISO-8859-1',
'nn_NO');
981 $languages[
'pl_PL'][
'LOCALE'] = array(
'pl_PL.ISO8859-2',
'pl_PL.ISO-8859-2',
'pl_PL');
986 $languages[
'pt_PT'][
'LOCALE'] = array(
'pt_PT.ISO8859-1',
'pt_PT.ISO-8859-1',
'pt_PT');
991 $languages[
'pt_BR'][
'LOCALE'] = array(
'pt_BR.ISO8859-1',
'pt_BR.ISO-8859-1',
'pt_BR');
995 $languages[
'ro_RO'][
'LOCALE'] = array(
'ro_RO.UTF-8',
'ro_RO.UTF8',
'ro_RO');
1000 $languages[
'ru_RU'][
'LOCALE'] = array(
'ru_RU.UTF-8',
'ru_RU.UTF8');
1021 $languages[
'sk_SK'][
'LOCALE'] = array(
'sk_SK.UTF-8',
'sk_SK.UTF8',
'sk_SK');
1026 $languages[
'sl_SI'][
'LOCALE'] = array(
'sl_SI.ISO8859-2',
'sl_SI.ISO-8859-2',
'sl_SI');
1031 $languages[
'sr_YU'][
'LOCALE'] = array(
'sr_YU.ISO8859-2',
'sr_YU.ISO-8859-2',
'sr_YU');
1036 $languages[
'sv_SE'][
'LOCALE'] = array(
'sv_SE.UTF-8',
'sv_SE.UTF8',
'sv_SE');
1040 $languages[
'ta_LK'][
'ALTNAME'] =
'தமிழ்';
1042 $languages[
'ta_LK'][
'LOCALE'] = array(
'ta_LK.UTF-8',
'ta_LK.UTF8',
'ta_LK',
'ta.UTF-8',
'ta.UTF8',
'ta');
1063 $languages[
'tr_TR'][
'LOCALE'] = array(
'tr_TR.ISO8859-9',
'tr_TR.ISO-8859-9',
'tr_TR');
1068 $languages[
'zh_TW'][
'LOCALE'] = array(
'zh_TW.UTF-8',
'zh_TW.UTF8');
1078 $languages[
'uk_UA'][
'LOCALE'] = array(
'uk_UA.UTF-8',
'uk_UA.UTF8',
'uk_UA',
'uk');
1094 $languages[
'fa_IR'][
'LOCALE'] = array(
'fa_IR.UTF-8',
'fa_IR.UTF8');
1108 if (function_exists(
'_')) {
1111 if (function_exists(
'bindtextdomain')) {
1114 if (function_exists(
'textdomain')) {
1125 include_once(
SM_PATH .
'functions/gettext.php');