php-imap icon indicating copy to clipboard operation
php-imap copied to clipboard

Wrong handling of Content-Transfer-Encoding: binary

Open gpelz-graph-it opened this issue 9 months ago • 0 comments

Describe the bug According to RFC 1341 a message flagged as 'Content-Transfer-Encoding: binary' should not be converted but kept 'as is'.

Problem is:

        switch ($encoding) {
            case IMAP::MESSAGE_ENC_BINARY:
                if (extension_loaded('imap')) {
                    return base64_decode(\imap_binary($value));
                }
                return base64_decode($value);

source: MessageDecoder always applies base64_decode on the content.

This is wrong, and produces broken output.

This is a multi-part message in MIME format.
------=_Part_72_1430376836.1740153200721
Content-Type: text/html; charset=iso-8859-15
Content-Transfer-Encoding: binary

<body> <div style="font-size: 10pt; font-family: Arial, sans-serif; width:600px">       <div style="padding-bottom=15pt">Sehr geehrte Damen und Herren,</div>   <br>    <div style="padding-bottom=5pt">vielen Dank f&uuml;r Ihre Bestellung, bitte beachten Sie das Pr&uuml;fzeugnis im Anhang.</div></body>

------=_Part_72_1430376836.1740153200721
Content-Type: application/pdf; name=Pruefzeugnis_PZ-2025-0075307.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=Pruefzeugnis_PZ-2025-0075307.pdf
Content-ID: <Pruefzeugnis_PZ-2025-0075307.pdf>
...

will result in a broken output.

nrv+)^~ȳ{])'ښ)rƧ'aM)دܥzv)-RzykڙޮدnbrZuا&o^6ZȆz^[imztyÖ¬>Wz'ÈŠxZ݊ۡ

Would be nice if this could be fixed to comply with RFC 1341.

gpelz-graph-it avatar Feb 25 '25 05:02 gpelz-graph-it