Aleksander Machniak
2014-11-07 a7a778c157426f12f176648802a51c5e5397a81a
program/lib/Roundcube/rcube_charset.php
@@ -654,7 +654,6 @@
        if ($string[0] == "\0" && $string[1] != "\0" && $string[2] == "\0" && $string[3] != "\0") return 'UTF-16BE';
        if ($string[0] != "\0" && $string[1] == "\0" && $string[2] != "\0" && $string[3] == "\0") return 'UTF-16LE';
        if (function_exists('mb_detect_encoding')) {
            if (empty($language)) {
                $rcube    = rcube::get_instance();
                $language = $rcube->get_user_language();
@@ -682,8 +681,20 @@
            case 'tr_TR':
                $prio = array('UTF-8', 'ISO-8859-9', 'WINDOWS-1254');
                break;
        }
            default:
        // mb_detect_encoding() is not reliable for some charsets (#1490135)
        // use mb_check_encoding() to make charset priority lists really working
        if ($prio && function_exists('mb_check_encoding')) {
            foreach ($prio as $encoding) {
                if (mb_check_encoding($string, $encoding)) {
                    return $encoding;
                }
            }
        }
        if (function_exists('mb_detect_encoding')) {
            if (!$prio) {
                $prio = array('UTF-8', 'SJIS', 'GB2312',
                    'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4',
                    'ISO-8859-5', 'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9',
@@ -695,7 +706,9 @@
            $encodings = array_unique(array_merge($prio, mb_list_encodings()));
            return mb_detect_encoding($string, $encodings);
            if ($encoding = mb_detect_encoding($string, $encodings)) {
                return $encoding;
            }
        }
        // No match, check for UTF-8