Skip to content

Commit 39e1f5f

Browse files
committed
Fix case-insensitive charset detection
1 parent a01c645 commit 39e1f5f

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

โ€Žlib/IMAP/Charset/Converter.phpโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function convert(Horde_Mime_Part $p): string {
7474
if ($charset !== null) {
7575
$normalizedCharset = $this->normalizeCharset($charset);
7676
try {
77-
if (in_array($normalizedCharset, $this->mbEncodings(), true)) {
77+
if (in_array(strtoupper($charset), array_map('strtoupper', $this->mbEncodings()), true)) {
7878
$converted = mb_convert_encoding($data, 'UTF-8', $normalizedCharset);
7979
} else {
8080
$converted = @iconv($normalizedCharset, 'UTF-8', $data);

โ€Žtests/Unit/IMAP/Charset/ConverterTest.phpโ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ public function dataProviderMimeParts(): array {
5656
$iso88591MimePart_noCharset = new Horde_Mime_Part();
5757
$iso88591MimePart_noCharset->setContents('ื‘ื” ื‘ื“ืฃ ืœื—ื‘ืจ ืžืžื•ื ืจื›ื™ื”, ื‘ืงืจ ื‘ื’ืจืกื” ื•ืืžื ื•ืช ื“ืช');
5858
// Japanese
59+
$iso2022jpText = 'ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ';
60+
$iso2022jpBytes = mb_convert_encoding($iso2022jpText, 'ISO-2022-JP', 'UTF-8');
61+
5962
$iso2022jpMimePart = new Horde_Mime_Part();
6063
$iso2022jpMimePart->setType('text/plain');
6164
$iso2022jpMimePart->setCharset('ISO-2022-JP');
62-
$iso2022jpMimePart->setContents(mb_convert_encoding('ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ', 'ISO-2022-JP', 'UTF-8'));
65+
$iso2022jpMimePart->setContents($iso2022jpBytes);
66+
67+
$iso2022jpLowerMimePart = new Horde_Mime_Part();
68+
$iso2022jpLowerMimePart->setType('text/plain');
69+
$iso2022jpLowerMimePart->setCharset('iso-2022-jp');
70+
$iso2022jpLowerMimePart->setContents($iso2022jpBytes);
6371
// Korean (Outlook) - all ks_c_5601 spellings map to UHC (CP949). Encode
6472
// with iconv to avoid depending on mbstring's UHC support, and cover the
6573
// case-insensitive charset spellings.
@@ -84,7 +92,8 @@ public function dataProviderMimeParts(): array {
8492
[$utfMimePart, '๐Ÿ˜Š'],
8593
[$utfMimeStreamPart, '๐Ÿ’ฆ'],
8694
[$iso88591MimePart, 'รœmlaut'],
87-
[$iso2022jpMimePart, 'ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ'],
95+
[$iso2022jpMimePart, $iso2022jpText],
96+
[$iso2022jpLowerMimePart, $iso2022jpText],
8897
[$iso88591MimePart_noCharset, 'ื‘ื” ื‘ื“ืฃ ืœื—ื‘ืจ ืžืžื•ื ืจื›ื™ื”, ื‘ืงืจ ื‘ื’ืจืกื” ื•ืืžื ื•ืช ื“ืช'],
8998
], $koreanCases, [
9099
[$windowsMimePart, 'ู‚ุงู… ุฒู‡ุงุก ุฃูˆุฑุงู‚ู‡ู… ู…ุง,'],

0 commit comments

Comments
ย (0)