diff --git a/src/MailCollector.php b/src/MailCollector.php index e2d95c09692..3211e25a772 100644 --- a/src/MailCollector.php +++ b/src/MailCollector.php @@ -2382,7 +2382,13 @@ public function getDecodedContent(Part $part) } $charset = $content_type->getParameter('charset'); - if ($charset !== null && strtoupper($charset) != 'UTF-8') { + + // If charset is not specified, and not UTF-8, force fallback default encoding + if ($charset === null) { + $charset = mb_check_encoding($contents, 'UTF-8') ? 'UTF-8' : 'ISO-8859-1'; + } + + if (strtoupper($charset) != 'UTF-8') { /* mbstring functions do not handle the 'ks_c_5601-1987' & * 'ks_c_5601-1989' charsets. However, these charsets are used, for * example, by various versions of Outlook to send Korean characters. diff --git a/tests/emails-tests/47-missing-charset.eml b/tests/emails-tests/47-missing-charset.eml new file mode 100644 index 00000000000..c8f05291a8a --- /dev/null +++ b/tests/emails-tests/47-missing-charset.eml @@ -0,0 +1,14 @@ +From normal@glpi-project.org Mon Oct 21 10:00:00 2025 +From: normal@glpi-project.org +To: unittests@glpi-project.org +Subject: 47 - Missing charset parameter +MIME-Version: 1.0 +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable +Date: Mon, 21 Oct 2025 10:00:00 +0000 +Message-ID: + +ATTENTION: Ne cliquez pas sur les liens ou n'ouvrez pas les pi=E8ces jointe= +s si vous n'=EAtes pas s=FBr du contenu. + + diff --git a/tests/imap/MailCollectorTest.php b/tests/imap/MailCollectorTest.php index 9a58260e577..6153b7c5333 100644 --- a/tests/imap/MailCollectorTest.php +++ b/tests/imap/MailCollectorTest.php @@ -857,6 +857,7 @@ public function testCollect() '42 - Missing Content Type', '43 - Korean encoding issue', '44 - Hebrew encoding issue', + '47 - Missing charset parameter', ], ], // Mails having "normal" user as observer @@ -882,6 +883,8 @@ public function testCollect() Best regards, PLAINTEXT, + // Email without charset parameter (47-missing-charset.eml) - tests ISO-8859-1 to UTF-8 fallback + '47 - Missing charset parameter' => 'ATTENTION: Ne cliquez pas sur les liens ou n\'ouvrez pas les pièces jointes si vous n\'êtes pas sûr du contenu.', // HTML on multi-part email 'Re: [GLPI #0038927] Update - Issues with new Windows 10 machine' => <<This message have reply to header, requester should be get from this header.

@@ -1493,4 +1496,5 @@ public function testCleanContent( $result = $mailcollector->cleanContent($original); $this->assertEquals($expected, $result); } + }