ISO-2022-JP emails are garbled in Mail 5.10.12 [Minimal fix available]
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia da lib/IMAP/Charset/Converter.php e segui Converter::convert() per il charset iso-2022-jp in minuscolo. Riproduci il confronto di mb_list_encodings() e verifica il percorso di conversione con i dati del messaggio ISO-2022-JP forniti. L’attività è completata quando l’email giapponese interessata viene visualizzata correttamente senza l’errore di conversione di iconv.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Steps to reproduce
-
Set up Nextcloud Server 34.0.0 with Nextcloud Mail 5.10.12.
-
Use a PHP environment with
mbstringandiconvenabled. -
Receive an email encoded as ISO-2022-JP, for example:
Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit -
Open the email using Nextcloud Mail.
-
Observe that the Japanese text is garbled or replaced with
?.
The issue can be reproduced with emails sent by Cybozu MailWise 5.4.7.
Expected behavior
The ISO-2022-JP encoded email should be correctly decoded and displayed as UTF-8 Japanese text.
Actual behavior
Japanese text in ISO-2022-JP emails is displayed incorrectly, with characters being garbled or replaced with ?.
The issue does not occur when the same message body is manually converted using PHP's mb_convert_encoding().
Mail app version
5.10.12
Nextcloud version
docker nextcloud:34.0.0-fpm-alpine
Mailserver or service
Cybozu MailWise 5.4.7
Operating system
uname -a Linux iris 7.0.0-28-generic #28~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 15:50:57 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
PHP engine version
PHP 8.3
Nextcloud memory caching
No response
Web server
Nginx
Database
MariaDB
Additional info
Environment
- Nextcloud Server: 34.0.0
- Nextcloud Mail: 5.10.12
- PHP: Docker image based on Alpine Linux
- PHP
mbstring: enabled - PHP
iconv: enabled - iconv implementation:
libiconv - libiconv version: 1.18
Investigation
The issue was traced to:
lib/IMAP/Charset/Converter.php
The relevant code is:
if (in_array($charset, mb_list_encodings(), true)) {
$converted = mb_convert_encoding($data, 'UTF-8', $charset);
} else {
$converted = iconv($charset, 'UTF-8', $data);
}
For the affected messages, Horde provides the charset as:
iso-2022-jp
However, in this PHP environment:
in_array("iso-2022-jp", mb_list_encodings(), true)
→ false
in_array("ISO-2022-JP", mb_list_encodings(), true)
→ true
Because the comparison is case-sensitive, iso-2022-jp is not recognized as an encoding supported by mbstring, and the code falls back to iconv().
Conversion results
The original ISO-2022-JP message body was tested directly.
Using mb_convert_encoding():
$r = mb_convert_encoding($s, "UTF-8", "ISO-2022-JP");
produces the correct Japanese text.
Using iconv():
$r = iconv("ISO-2022-JP", "UTF-8", $s);
produces:
Notice: iconv(): Detected an illegal character in input string
and returns false.
The data passed to Converter::convert() was also inspected. The affected plain-text part contained the expected ISO-2022-JP escape sequence:
1b 24 42
(ESC $ B), confirming that the message body itself is valid ISO-2022-JP data at that point.
Root cause
The issue appears to be caused by the case-sensitive comparison of the MIME charset name with the encoding names returned by mb_list_encodings().
The processing path is:
MIME charset: iso-2022-jp
↓
mb_list_encodings() comparison
↓
case-sensitive mismatch
↓
fallback to iconv()
↓
libiconv: "Detected an illegal character in input string"
↓
conversion failure / garbled text
Workaround / minimal patch
The following minimal change fixes the issue in the affected environment:
if (in_array(strtoupper($charset), array_map('strtoupper', mb_list_encodings()), true)) {
$converted = mb_convert_encoding($data, 'UTF-8', $charset);
} else {
$converted = iconv($charset, 'UTF-8', $data);
}
After applying this change, the affected ISO-2022-JP emails are displayed correctly.
This also confirms that the problem is not caused by corrupted email data or an inability of PHP's mbstring extension to decode ISO-2022-JP.
Request
Please consider making charset matching case-insensitive so that MIME charset names such as iso-2022-jp are correctly recognized as encodings supported by mbstring.
If appropriate, please also consider backporting the fix to supported maintenance versions.
- Lingua principale
- JavaScript
- Stelle
- 1k
- Fork
- 348
- Merge medio
- 1g 22h
- PR unite (30g)
- 66
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nextcloud/mail
-
0. to triage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
1. to develop enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nextcloud/mail#13703 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
1. to develop technical debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
0. to triage bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
When clicking on the sender’s email address in a received message, it currently opens a mailto: link.Forse già presa @kra-mo l’ha presa 2 giorni fa. Aperta0. to triage enhancement needs info
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
nextcloud/mail#13717 · 1 commento · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di nextcloud/mail
Issue simili
-
factory-active factory-automatic harness/codex task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
vercel/ai#21582 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
ux
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
rr-djk/rr-djuikoo.com#53 ·
I maintainer di solito rispondono entro 1 giorno
-
Add shacl12-inference-rulesApertanew spec review
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
w3c/browser-specs#2666 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
thim81/openapi-format#238 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
decentespresso/dye2#13 ·