diff --git a/src/Charset.php b/src/Charset.php index 0824f947f..d57908e1f 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') { diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 8c59d724a..6aefb778a 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()