From 91f0f1135604c077a6aceae7c6b1196b99c215ae Mon Sep 17 00:00:00 2001 From: Valentin Salmeron Date: Wed, 25 Jan 2023 14:48:11 +0100 Subject: [PATCH 1/2] Update ParserTest.php --- tests/ParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 9b663adb4..a670315c6 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1900,7 +1900,7 @@ public function testCharsetSupportedAsAnAlias() $Parser = new Parser(); $Parser->setPath($file); $this->assertEquals('', $Parser->getHeader('from')); - $this->assertStringContainsString('次の受信者またはグル?プへの配信に失?', $Parser->getMessageBody('text')); + $this->assertStringContainsString('次の受信者またはグループへの配信に失敗しました:', $Parser->getMessageBody('text')); } public function testCharsetNotSupportedByMBString() From 4796abd288d1d62ddae01a57c946761b1717021b Mon Sep 17 00:00:00 2001 From: Valentin Salmeron Date: Wed, 25 Jan 2023 14:49:38 +0100 Subject: [PATCH 2/2] Update Charset.php --- src/Charset.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Charset.php b/src/Charset.php index cd219f226..6063bc5f6 100644 --- a/src/Charset.php +++ b/src/Charset.php @@ -320,6 +320,23 @@ public function decodeCharset($encodedString, $charset) if ($charset == 'utf-8' || $charset == 'us-ascii') { return $encodedString; } + + // Handle gb2312 from Windows-based software products + if ($charset === 'gb2312') { + // Disable E_NOTICE errors to ignore E_NOTICE possibly triggered by iconv() + $currentErrorReporting = error_reporting(); + error_reporting($currentErrorReporting & ~E_NOTICE); + + $result = iconv($charset, 'utf-8', $encodedString); + + error_reporting($currentErrorReporting); + + if ($result) { + return $result; + } + + $charset = 'gbk'; // If decoding from gb2312 failed, use gbk instead + } if (function_exists('mb_convert_encoding')) { if ($charset == 'iso-2022-jp') {