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
8 changes: 7 additions & 1 deletion src/MailCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions tests/emails-tests/47-missing-charset.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
From [email protected] Mon Oct 21 10:00:00 2025
From: [email protected]
To: [email protected]
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: <[email protected]>

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.


4 changes: 4 additions & 0 deletions tests/imap/MailCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' => <<<HTML
<p>This message have reply to header, requester should be get from this header.</p>
Expand Down Expand Up @@ -1493,4 +1496,5 @@ public function testCleanContent(
$result = $mailcollector->cleanContent($original);
$this->assertEquals($expected, $result);
}

}