Skip to content

Commit 6e6df94

Browse files
authored
Support Microsoft charset values (#271)
Close #270
1 parent 26b8181 commit 6e6df94

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Message/Transcoder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ final class Transcoder
1414
* @see https://encoding.spec.whatwg.org/#encodings
1515
* @see https://dxr.mozilla.org/mozilla-central/source/dom/encoding/labelsencodings.properties
1616
* @see https://dxr.mozilla.org/mozilla1.9.1/source/intl/uconv/src/charsetalias.properties
17+
* @see https://msdn.microsoft.com/en-us/library/cc194829.aspx
1718
*/
1819
private static $charsetAliases = [
20+
'128' => 'Shift_JIS',
21+
'129' => 'EUC-KR',
22+
'134' => 'GB2312',
23+
'136' => 'Big5',
24+
'161' => 'windows-1253',
25+
'162' => 'windows-1254',
26+
'177' => 'windows-1255',
27+
'178' => 'windows-1256',
28+
'186' => 'windows-1257',
29+
'204' => 'windows-1251',
30+
'222' => 'windows-874',
31+
'238' => 'windows-1250',
1932
'5601' => 'EUC-KR',
2033
'646' => 'us-ascii',
2134
'850' => 'IBM850',

tests/MessageTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ public function testCharsetAlias()
195195
$this->assertSame($text, \rtrim($message->getBodyText()));
196196
}
197197

198+
public function testMicrosoftCharsetAlias()
199+
{
200+
$charset = '134';
201+
$charsetAlias = 'GB2312';
202+
$text = '电佛';
203+
204+
$this->createTestMessage(
205+
$this->mailbox,
206+
$charset,
207+
\mb_convert_encoding($text, $charsetAlias, 'UTF-8'),
208+
null,
209+
$charsetAlias,
210+
$charset
211+
);
212+
213+
$message = $this->mailbox->getMessage(1);
214+
215+
$this->assertSame($text, \rtrim($message->getBodyText()));
216+
}
217+
198218
public function testUnsupportedCharset()
199219
{
200220
$charset = \uniqid('NAN_CHARSET_');

0 commit comments

Comments
 (0)