From 0b385dc94667f6037c0b99c6dd272dd93246e25f Mon Sep 17 00:00:00 2001 From: Shin Kojima Date: Mon, 6 Mar 2017 16:22:55 +0800 Subject: [PATCH] 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. --- program/lib/Roundcube/rcube_charset.php | 5 ++++- tests/Framework/Charset.php | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/program/lib/Roundcube/rcube_charset.php b/program/lib/Roundcube/rcube_charset.php index 18893ea64..2f87b8266 100644 --- a/program/lib/Roundcube/rcube_charset.php +++ b/program/lib/Roundcube/rcube_charset.php @@ -201,7 +201,9 @@ class rcube_charset } // 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 // it means that input string has been truncated set_error_handler(array('rcube_charset', 'error_handler'), E_NOTICE); @@ -227,6 +229,7 @@ class rcube_charset $aliases = array( 'WINDOWS-1257' => 'ISO-8859-13', 'US-ASCII' => 'ASCII', + 'ISO-2022-JP' => 'ISO-2022-JP-MS', ); $mb_from = $aliases[$from] ?: $from; diff --git a/tests/Framework/Charset.php b/tests/Framework/Charset.php index 752ddf43e..f36b7b969 100644 --- a/tests/Framework/Charset.php +++ b/tests/Framework/Charset.php @@ -70,6 +70,7 @@ class Framework_Charset extends PHPUnit_Framework_TestCase array('aż', 'a', 'UTF-8', 'US-ASCII'), array('&BCAEMARBBEEESwQ7BDoEOA-', 'Рассылки', 'UTF7-IMAP', 'UTF-8'), 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() { return array( - array('ܦW,Dn', 'zh_TW', 'BIG-5'), + array(base64_decode('xeOl3KZXutkspUStbg=='), 'zh_TW', 'BIG-5'), ); }