Fix case-insensitive charset detection for ISO-2022-JP - #13641
Fix case-insensitive charset detection for ISO-2022-JP#13641neconohitomi wants to merge 1 commit into
Conversation
| $normalizedCharset = $this->normalizeCharset($charset); | ||
| try { | ||
| if (in_array($normalizedCharset, $this->mbEncodings(), true)) { | ||
| if (in_array(strtoupper($charset), array_map('strtoupper', $this->mbEncodings()), true)) { |
There was a problem hiding this comment.
Please move array_map(strtoupper) into the mbEncodings function.
| $normalizedCharset = $this->normalizeCharset($charset); | ||
| try { | ||
| if (in_array($normalizedCharset, $this->mbEncodings(), true)) { | ||
| if (in_array(strtoupper($charset), array_map('strtoupper', $this->mbEncodings()), true)) { |
There was a problem hiding this comment.
strtoupper($charset) should be done in normalizedCharset. At best by altering the map to also use uppercase and flip lowerCharset to upperCharset and return that version as fallback.
|
Good finding, Thanks for your pr 👍 |
|
The commit message needs a DCO signoff and the Assisted-By trailer. It's often enough to point your Agent https://github.com/nextcloud/mail/blob/main/AGENTS.md#commit-message-format and https://github.com/nextcloud/mail/pull/13641/checks?check_run_id=101341532634 to resolve it. |
Thanks for the review and for pointing out that the current commit is missing the required DCO I used an AI agent (ChatGPT) while preparing this PR, and this makes me wonder about the following situation. I would appreciate your advice. According to What would be the preferred way to fix the DCO/ I can prepare the required fixup commit if that is the preferred approach. |
🤖 AI (if applicable)
Summary
Fixes ISO-2022-JP email conversion when the charset is provided in lowercase.
Problem
Some emails declare their charset as
ISO-2022-JP, but Horde can return the charset as lowercase (iso-2022-jp).Converterpreviously checked the charset againstmb_list_encodings()using a case-sensitive comparison. As a result,iso-2022-jpwas not recognized as an mbstring encoding and the conversion fell back toiconv().On the affected Alpine/libiconv environment,
iconv()fails to convert these ISO-2022-JP messages, resulting in garbled email content.Fix
Make the charset comparison case-insensitive when checking the available mbstring encodings.
The existing charset normalization and conversion logic are otherwise unchanged.
Tests
Added a regression test covering lowercase
iso-2022-jp.Tested with:
ConverterTest: 15 tests, 30 assertions — OKFixes #13472