Log charset conversion warning only when no function was found, not when the string was invalid

pull/300/head
Aleksander Machniak 9 years ago
parent 7d71c48952
commit 83345af059

@ -207,14 +207,14 @@ class rcube_charset
// it means that input string has been truncated // it means that input string has been truncated
set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE); set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE);
try { try {
$_iconv = iconv($from, $to . $iconv_options, $str); $out = iconv($from, $to . $iconv_options, $str);
} catch (ErrorException $e) { } catch (ErrorException $e) {
$_iconv = false; $out = false;
} }
restore_error_handler(); restore_error_handler();
if ($_iconv !== false) { if ($out !== false) {
return $_iconv; return $out;
} }
} }
@ -258,37 +258,35 @@ class rcube_charset
// convert charset using bundled classes/functions // convert charset using bundled classes/functions
if ($to == 'UTF-8') { if ($to == 'UTF-8') {
if ($from == 'UTF7-IMAP') { if ($from == 'UTF7-IMAP') {
if ($_str = self::utf7imap_to_utf8($str)) { if ($out = self::utf7imap_to_utf8($str)) {
return $_str; return $out;
} }
} }
else if ($from == 'UTF-7') { else if ($from == 'UTF-7') {
if ($_str = self::utf7_to_utf8($str)) { if ($out = self::utf7_to_utf8($str)) {
return $_str; return $out;
} }
} }
else if ($from == 'ISO-8859-1' && function_exists('utf8_encode')) { else if ($from == 'ISO-8859-1' && function_exists('utf8_encode')) {
return utf8_encode($str); return utf8_encode($str);
} }
else {
trigger_error("No suitable function found for UTF-8 encoding");
}
} }
// encode string for output // encode string for output
if ($from == 'UTF-8') { if ($from == 'UTF-8') {
// @TODO: we need a function for UTF-7 (RFC2152) conversion // @TODO: we need a function for UTF-7 (RFC2152) conversion
if ($to == 'UTF7-IMAP' || $to == 'UTF-7') { if ($to == 'UTF7-IMAP' || $to == 'UTF-7') {
if ($_str = self::utf8_to_utf7imap($str)) { if ($out = self::utf8_to_utf7imap($str)) {
return $_str; return $out;
} }
} }
else if ($to == 'ISO-8859-1' && function_exists('utf8_decode')) { else if ($to == 'ISO-8859-1' && function_exists('utf8_decode')) {
return utf8_decode($str); return utf8_decode($str);
} }
else { }
trigger_error("No suitable function found for UTF-8 decoding");
} if (!isset($out)) {
trigger_error("No suitable function found for '$from' to '$to' conversion");
} }
// return original string // return original string

Loading…
Cancel
Save