Skip to content

Commit

Permalink
- Fix character set conversion fails on systems where iconv doesn't a…
Browse files Browse the repository at this point in the history
…ccept //IGNORE (#1486375)
  • Loading branch information
alecpl committed Jan 31, 2010
1 parent e7dde1f commit f52e7a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG RoundCube Webmail
===========================

- Fix character set conversion fails on systems where iconv doesn't accept //IGNORE (#1486375)
- Login preformance: Create default folders on first login only
- Import contacts into the selected address book (by Phil Weir)
- Add support for MDB2's 'sqlsrv' driver (#1486395)
Expand Down
37 changes: 33 additions & 4 deletions program/include/main.inc
Expand Up @@ -169,6 +169,18 @@ function rcmail_cache_gc()
}


/**
* Catch an error and throw an exception.
*
* @param int Level of the error
* @param string Error message
*/
function rcube_error_handler($errno, $errstr)
{
throw new ErrorException($errstr, 0, $errno);
}


/**
* Convert a string from one charset to another.
* Uses mbstring and iconv functions if possible
Expand All @@ -180,6 +192,7 @@ function rcmail_cache_gc()
*/
function rcube_charset_convert($str, $from, $to=NULL)
{
static $iconv_options = null;
static $mbstring_loaded = null;
static $mbstring_list = null;
static $convert_warning = false;
Expand All @@ -195,20 +208,36 @@ function rcube_charset_convert($str, $from, $to=NULL)

// convert charset using iconv module
if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7') {
$_iconv = @iconv($from, $to . '//IGNORE', $str);
if ($iconv_options === null) {
// transliterate characters not available in output charset
$iconv_options = '//TRANSLIT';
if (iconv('', $iconv_options, '') === false) {
// iconv implementation does not support options
$iconv_options = '';
}
}
// throw an exception if iconv reports an illegal character in input
// it means that input string has been truncated
set_error_handler('rcube_error_handler', E_NOTICE);
try {
$_iconv = iconv($from, $to . $iconv_options, $str);
} catch (ErrorException $e) {
$_iconv = false;
}
restore_error_handler();
if ($_iconv !== false) {
return $_iconv;
return $_iconv;
}
}

if (is_null($mbstring_loaded))
if ($mbstring_loaded === null)
$mbstring_loaded = extension_loaded('mbstring');

// convert charset using mbstring module
if ($mbstring_loaded) {
$aliases['WINDOWS-1257'] = 'ISO-8859-13';

if (is_null($mbstring_list)) {
if ($mbstring_list === null) {
$mbstring_list = mb_list_encodings();
$mbstring_list = array_map('strtoupper', $mbstring_list);
}
Expand Down

0 comments on commit f52e7a0

Please sign in to comment.