Aleksander Machniak
2012-09-12 295efea5c114378f9c5509659badb18ff16b0642
program/include/rcube_charset.php
@@ -8,7 +8,10 @@
 | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
 | Copyright (C) 2011-2012, Kolab Systems AG                             |
 | Copyright (C) 2000 Edmund Grimley Evans <edmundo@rano.org>            |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Provide charset conversion functionality                            |
@@ -75,7 +78,7 @@
     * @param  int    Level of the error
     * @param  string Error message
     */
    public function error_handler($errno, $errstr)
    public static function error_handler($errno, $errstr)
    {
        throw new ErrorException($errstr, 0, $errno);
    }
@@ -86,7 +89,7 @@
     * Sometimes charset string is malformed, there are also charset aliases 
     * but we need strict names for charset conversion (specially utf8 class)
     *
     * @param  string Input charset name
     * @param string $input Input charset name
     *
     * @return string The validated charset name
     */
@@ -179,8 +182,14 @@
        static $mbstring_list   = null;
        static $conv            = null;
        $to   = empty($to) ? strtoupper(RCMAIL_CHARSET) : self::parse($to);
        $to   = empty($to) ? strtoupper(RCMAIL_CHARSET) : $to;
        $from = self::parse($from);
        // It is a common case when UTF-16 charset is used with US-ASCII content (#1488654)
        // In that case we can just skip the conversion (use UTF-8)
        if ($from == 'UTF-16' && !preg_match('/[^\x00-\x7F]/', $str)) {
            $from = 'UTF-8';
        }
        if ($from == $to || empty($str) || empty($from)) {
            return $str;
@@ -269,7 +278,7 @@
        if ($from == 'UTF-8') {
            // @TODO: we need a function for UTF-7 (RFC2152) conversion
            if ($to == 'UTF7-IMAP' || $to == 'UTF-7') {
                if ($_str = utf8_to_utf7imap($str)) {
                if ($_str = self::utf8_to_utf7imap($str)) {
                    return $_str;
                }
            }