Skip iconv for problematic ISO-2022-JP strings (#5668)

We sometimes get broken character encodings such as:
Subject: =?iso-2022-jp?B?GyRCLWo7M3l1OSk2SBsoQgo=?=
This actually is not a strict ISO-2022-JP string, but a CP50220 string
that is a variant of ISO-2022-JP with extended characters proposed by
Microsoft. Iconv can not handle these encodings well.
pull/5690/head
Shin Kojima 8 years ago committed by Aleksander Machniak
parent f2ab7ec929
commit 0b385dc946

@ -201,7 +201,9 @@ class rcube_charset
} }
// convert charset using iconv module // convert charset using iconv module
if ($iconv_options !== false && $from != 'UTF7-IMAP' && $to != 'UTF7-IMAP') { if ($iconv_options !== false && $from != 'UTF7-IMAP' && $to != 'UTF7-IMAP'
&& $from !== 'ISO-2022-JP'
) {
// throw an exception if iconv reports an illegal character in input // throw an exception if iconv reports an illegal character in input
// 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);
@ -227,6 +229,7 @@ class rcube_charset
$aliases = array( $aliases = array(
'WINDOWS-1257' => 'ISO-8859-13', 'WINDOWS-1257' => 'ISO-8859-13',
'US-ASCII' => 'ASCII', 'US-ASCII' => 'ASCII',
'ISO-2022-JP' => 'ISO-2022-JP-MS',
); );
$mb_from = $aliases[$from] ?: $from; $mb_from = $aliases[$from] ?: $from;

@ -70,6 +70,7 @@ class Framework_Charset extends PHPUnit_Framework_TestCase
array('aż', 'a', 'UTF-8', 'US-ASCII'), array('aż', 'a', 'UTF-8', 'US-ASCII'),
array('&BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки', 'UTF7-IMAP', 'UTF-8'), array('&BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки', 'UTF7-IMAP', 'UTF-8'),
array('Рассылки', '&BCAEMARBBEEESwQ7BDoEOA-', 'UTF-8', 'UTF7-IMAP'), array('Рассылки', '&BCAEMARBBEEESwQ7BDoEOA-', 'UTF-8', 'UTF7-IMAP'),
array(base64_decode('GyRCLWo7M3l1OSk2SBsoQg=='), '㈱山﨑工業', 'ISO-2022-JP', 'UTF-8'),
); );
} }
@ -178,7 +179,7 @@ class Framework_Charset extends PHPUnit_Framework_TestCase
function data_detect_with_lang() function data_detect_with_lang()
{ {
return array( return array(
array('顯示名稱,主要', 'zh_TW', 'BIG-5'), array(base64_decode('xeOl3KZXutkspUStbg=='), 'zh_TW', 'BIG-5'),
); );
} }

Loading…
Cancel
Save