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
4 changes: 2 additions & 2 deletions lib/IMAP/Charset/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function normalizeCharset(string $charset): string {
$charset = trim($charset);
$lowerCharset = strtolower($charset);

return self::CHARSET_MAP[$lowerCharset] ?? $charset;
return self::CHARSET_MAP[$lowerCharset] ?? strtoupper($charset);
}

/**
Expand All @@ -45,7 +45,7 @@ private function mbEncodings(): array {
/** @var list<string>|null $encodings */
static $encodings = null;
if ($encodings === null) {
$encodings = mb_list_encodings();
$encodings = array_map('strtoupper', mb_list_encodings());
}

return $encodings;
Expand Down
13 changes: 11 additions & 2 deletions tests/Unit/IMAP/Charset/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ public function dataProviderMimeParts(): array {
$iso88591MimePart_noCharset = new Horde_Mime_Part();
$iso88591MimePart_noCharset->setContents('ื‘ื” ื‘ื“ืฃ ืœื—ื‘ืจ ืžืžื•ื ืจื›ื™ื”, ื‘ืงืจ ื‘ื’ืจืกื” ื•ืืžื ื•ืช ื“ืช');
// Japanese
$iso2022jpText = 'ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ';
$iso2022jpBytes = mb_convert_encoding($iso2022jpText, 'ISO-2022-JP', 'UTF-8');

$iso2022jpMimePart = new Horde_Mime_Part();
$iso2022jpMimePart->setType('text/plain');
$iso2022jpMimePart->setCharset('ISO-2022-JP');
$iso2022jpMimePart->setContents(mb_convert_encoding('ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ', 'ISO-2022-JP', 'UTF-8'));
$iso2022jpMimePart->setContents($iso2022jpBytes);

$iso2022jpLowerMimePart = new Horde_Mime_Part();
$iso2022jpLowerMimePart->setType('text/plain');
$iso2022jpLowerMimePart->setCharset('iso-2022-jp');
$iso2022jpLowerMimePart->setContents($iso2022jpBytes);
// Korean (Outlook) - all ks_c_5601 spellings map to UHC (CP949). Encode
// with iconv to avoid depending on mbstring's UHC support, and cover the
// case-insensitive charset spellings.
Expand All @@ -84,7 +92,8 @@ public function dataProviderMimeParts(): array {
[$utfMimePart, '๐Ÿ˜Š'],
[$utfMimeStreamPart, '๐Ÿ’ฆ'],
[$iso88591MimePart, 'รœmlaut'],
[$iso2022jpMimePart, 'ๅค–ใ›ๅœ’ๆŸปใƒชใƒ„ใƒใƒฏ้กŒ'],
[$iso2022jpMimePart, $iso2022jpText],
[$iso2022jpLowerMimePart, $iso2022jpText],
[$iso88591MimePart_noCharset, 'ื‘ื” ื‘ื“ืฃ ืœื—ื‘ืจ ืžืžื•ื ืจื›ื™ื”, ื‘ืงืจ ื‘ื’ืจืกื” ื•ืืžื ื•ืช ื“ืช'],
], $koreanCases, [
[$windowsMimePart, 'ู‚ุงู… ุฒู‡ุงุก ุฃูˆุฑุงู‚ู‡ู… ู…ุง,'],
Expand Down