Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ public function testCharsetSupportedAsAnAlias()
$Parser = new Parser();
$Parser->setPath($file);
$this->assertEquals('<foo@bar.de>', $Parser->getHeader('from'));
$this->assertStringContainsString('次の受信者またはグル?プへの配信に失?', $Parser->getMessageBody('text'));
$this->assertStringContainsString('次の受信者またはグループへの配信に失敗しました:', $Parser->getMessageBody('text'));
}

public function testCharsetNotSupportedByMBString()
Expand Down
Loading