/* Decodes a string to the internal encoding from the given charset */
function charset_decode ($charset, $string) {
- global $languages, $squirrelmail_language;
+ global $languages, $squirrelmail_language, $default_charset;
if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
$string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
}
+ $charset = strtolower($charset);
+
+ set_my_charset();
+
+ // Variables that allow to use functions without function_exist() calls
+ $use_php_recode=false;
+ $use_php_iconv=false;
+
+ // Don't do conversion if charset is the same.
+ if ( $charset == strtolower($default_charset) )
+ return htmlspecialchars($string);
+
+ // catch iso-8859-8-i thing
+ if ( $charset == "iso-8859-8-i" )
+ $charset = "iso-8859-8";
+
+ /*
+ * Recode converts html special characters automatically if you use
+ * 'charset..html' decoding. There is no documented way to put -d option
+ * into php recode function call.
+ */
+ if ( $use_php_recode ) {
+ if ( $default_charset == "utf-8" ) {
+ // other charsets can be converted to utf-8 without loss.
+ // and output string is smaller
+ $string = recode_string($charset . "..utf-8",$string);
+ return htmlspecialchars($string);
+ } else {
+ $string = recode_string($charset . "..html",$string);
+ // recode does not convert single quote, htmlspecialchars does.
+ $string = str_replace("'", ''', $string);
+ return $string;
+ }
+ }
+
+ // iconv functions does not have html target and can be used only with utf-8
+ if ( $use_php_iconv && $default_charset=='utf-8') {
+ $string = iconv($charset,$default_charset,$string);
+ return htmlspecialchars($string);
+ }
+
+ // If we don't use recode and iconv, we'll do it old way.
+
/* All HTML special characters are 7 bit and can be replaced first */
$string = htmlspecialchars ($string);
- $charset = strtolower($charset);
-
- set_my_charset() ;
-
/* controls cpu and memory intensive decoding cycles */
$agresive_decoding = false;
} else if ($charset == 'windows-1258') {
include_once(SM_PATH . 'functions/decode/cp1258.php');
$ret = charset_decode_cp1258 ($string);
+ } else if ($charset == 'x-mac-roman') {
+ include_once(SM_PATH . 'functions/decode/cp10000.php');
+ $ret = charset_decode_cp10000 ($string);
+ } else if ($charset == 'x-mac-greek') {
+ include_once(SM_PATH . 'functions/decode/cp10006.php');
+ $ret = charset_decode_cp10006 ($string);
+ } else if ($charset == 'x-mac-cyrillic') {
+ include_once(SM_PATH . 'functions/decode/cp10007.php');
+ $ret = charset_decode_cp10007 ($string);
+ } else if ($charset == 'x-mac-ukrainian') {
+ include_once(SM_PATH . 'functions/decode/cp10017.php');
+ $ret = charset_decode_cp10017 ($string);
+ } else if ($charset == 'x-mac-centraleurroman') {
+ include_once(SM_PATH . 'functions/decode/cp10029.php');
+ $ret = charset_decode_cp10029 ($string);
+ } else if ($charset == 'x-mac-icelandic') {
+ include_once(SM_PATH . 'functions/decode/cp10079.php');
+ $ret = charset_decode_cp10079 ($string);
+ } else if ($charset == 'x-mac-turkish') {
+ include_once(SM_PATH . 'functions/decode/cp10081.php');
+ $ret = charset_decode_cp10081 ($string);
+ } else if ($charset == 'ibm855') {
+ include_once(SM_PATH . 'functions/decode/cp855.php');
+ $ret = charset_decode_cp855 ($string);
+ } else if ($charset == 'ibm866') {
+ include_once(SM_PATH . 'functions/decode/cp866.php');
+ $ret = charset_decode_cp866 ($string);
+ } else if ($charset == 'tis-620') {
+ include_once(SM_PATH . 'functions/decode/tis620.php');
+ $ret = charset_decode_tis620 ($string);
} else if ($charset == 'big5' and $agresive_decoding ) {
include_once(SM_PATH . 'functions/decode/big5.php');
$ret = charset_decode_big5 ($string);
$sm_language = $squirrelmail_default_language;
}
$sm_notAlias = $sm_language;
+
+ // Catching removed translation
+ // System reverts to English translation if user prefs contain translation
+ // that is not available in $languages array (admin removed directory
+ // with that translation)
+ if (!isset($languages[$sm_notAlias])) {
+ $sm_notAlias="en_US";
+ }
+
while (isset($languages[$sm_notAlias]['ALIAS'])) {
$sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
}
if (!$my_language) {
$my_language = $squirrelmail_default_language ;
}
+ // Catch removed translation
+ if (!isset($languages[$my_language])) {
+ $my_language="en_US";
+ }
while (isset($languages[$my_language]['ALIAS'])) {
$my_language = $languages[$my_language]['ALIAS'];
}
$languages['nl_NL']['CHARSET'] = 'iso-8859-1';
$languages['nl']['ALIAS'] = 'nl_NL';
}
+if ( file_exists( SM_PATH . 'locale/ms_MY') ) {
+ $languages['ms_MY']['NAME'] = 'Bahasa Melayu';
+ $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
+ $languages['my']['ALIAS'] = 'ms_MY';
+}
+
if ( file_exists( SM_PATH . 'locale/no_NO') ) {
$languages['no_NO']['NAME'] = 'Norwegian (Bokmål)';
$languages['no_NO']['CHARSET'] = 'iso-8859-1';
}
if ( file_exists( SM_PATH . 'locale/ru_RU') ) {
$languages['ru_RU']['NAME'] = 'Russian';
- $languages['ru_RU']['CHARSET'] = 'koi8-r';
- $languages['ru_RU']['LOCALE'] = 'ru_RU.KOI8-R';
+ $languages['ru_RU']['CHARSET'] = 'utf-8';
+ $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
$languages['ru']['ALIAS'] = 'ru_RU';
}
if ( file_exists( SM_PATH . 'locale/sr_YU') ) {
}
if ( file_exists( SM_PATH . 'locale/lt_LT') ) {
$languages['lt_LT']['NAME'] = 'Lithuanian';
- $languages['lt_LT']['CHARSET'] = 'iso-8859-4';
- $languages['lt_LT']['LOCALE'] = 'lt_LT.ISO-8859-4';
+ $languages['lt_LT']['CHARSET'] = 'utf-8';
+ $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
$languages['lt']['ALIAS'] = 'lt_LT';
}
if ( file_exists( SM_PATH . 'locale/sl_SI') ) {
// return space instead of non-braking space.
return str_replace($nbsp,' ',$string);
}
-?>
\ No newline at end of file
+?>