|
|
|
@ -171,8 +171,7 @@ class rcube_charset
|
|
|
|
|
public static function convert($str, $from, $to = null)
|
|
|
|
|
{
|
|
|
|
|
static $iconv_options = null;
|
|
|
|
|
static $mbstring_list = null;
|
|
|
|
|
static $mbstring_sch = null;
|
|
|
|
|
static $mbstring_sc = null;
|
|
|
|
|
|
|
|
|
|
$to = empty($to) ? RCUBE_CHARSET : strtoupper($to);
|
|
|
|
|
$from = self::parse_charset($from);
|
|
|
|
@ -219,30 +218,20 @@ class rcube_charset
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($mbstring_list === null) {
|
|
|
|
|
if (extension_loaded('mbstring')) {
|
|
|
|
|
$mbstring_sch = mb_substitute_character();
|
|
|
|
|
$mbstring_list = mb_list_encodings();
|
|
|
|
|
$mbstring_list = array_map('strtoupper', $mbstring_list);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$mbstring_list = false;
|
|
|
|
|
}
|
|
|
|
|
if ($mbstring_sc === null) {
|
|
|
|
|
$mbstring_sc = extension_loaded('mbstring') ? mb_substitute_character() : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// convert charset using mbstring module
|
|
|
|
|
if ($mbstring_list !== false) {
|
|
|
|
|
$aliases['WINDOWS-1257'] = 'ISO-8859-13';
|
|
|
|
|
// it happens that mbstring supports ASCII but not US-ASCII
|
|
|
|
|
if (($from == 'US-ASCII' || $to == 'US-ASCII') && !in_array('US-ASCII', $mbstring_list)) {
|
|
|
|
|
$aliases['US-ASCII'] = 'ASCII';
|
|
|
|
|
}
|
|
|
|
|
if ($mbstring_sc !== false) {
|
|
|
|
|
$aliases = array(
|
|
|
|
|
'WINDOWS-1257' => 'ISO-8859-13',
|
|
|
|
|
'US-ASCII' => 'ASCII',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$mb_from = $aliases[$from] ?: $from;
|
|
|
|
|
$mb_to = $aliases[$to] ?: $to;
|
|
|
|
|
|
|
|
|
|
// return if encoding found, string matches encoding and convert succeeded
|
|
|
|
|
if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list)) {
|
|
|
|
|
// Do the same as //IGNORE with iconv
|
|
|
|
|
mb_substitute_character('none');
|
|
|
|
|
|
|
|
|
@ -257,13 +246,12 @@ class rcube_charset
|
|
|
|
|
}
|
|
|
|
|
restore_error_handler();
|
|
|
|
|
|
|
|
|
|
mb_substitute_character($mbstring_sch);
|
|
|
|
|
mb_substitute_character($mbstring_sc);
|
|
|
|
|
|
|
|
|
|
if ($out !== false) {
|
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// convert charset using bundled classes/functions
|
|
|
|
|
if ($to == 'UTF-8') {
|
|
|
|
|