php-imap
php-imap copied to clipboard
Base64 encoded text/plain mail incorrectly decoded in LegacyProtocol
Describe the bug
If using pop3 to retrieve base64 encoded text-emails, in this case from a Tobit David MailServer, the output is decoded wrong.
$content = $this->decodeString($part->content, $part->encoding);
is decoding the complete email, including headers, instead of only the content which results in unreadable characters.
Given the following raw-message:
From: "TEST Sender" [email protected] Subject: ACMP-Fehler: Switch nicht erreichbar, Kunde: XXX DEV To: "Alarmarchiv PGSS" [email protected], "Ticketsystem" [email protected] X-Delivered-To: [email protected] Date: 09 Mar 2023 11:05:30 +0000 Priority: normal X-Priority: 3 (Normal) Importance: normal X-David-Sym: 0 X-David-Flags: 0 Message-ID: [email protected] MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64
QUNNUC1GZWhsZXI6IFN3aXRjaCAKIlhYWCIgaXN0IG5pY2h0IGVycmVpY2hiYXIgYmVpIApYWFgg UytDOgrDnGJlcndhY2h1bmdzYXJ0OiBQaW5nClVSTDogCklQLUFkcmVzc2U6IDAwMC4wMDAuMDAw LjAwMHwKCk5ldHphZHJlc3NlOiAKQmVzY2hyZWlidW5nOiBQT0UtVW50ZXJ2ZXJ0ZWlsZXIgaW4g SGFsbGUgZsO8ciBIYWxsZW50ZWxlZm9uCkhlcnN0ZWxsZXI6IFp5WGVsCkRhdHVtL1VocnplaXQ6 IDA5LjAzLjIwMjMgMTI6MDU6MjYKTGV0enRlciBLb250YWt0OiAyNS4wNy4yMDIyIDE1OjM4OjE0 ClRlYW12aWV3ZXItSUQ6IHh4eAp3ZWl0ZXJlIEluZm9ybWF0aW9uZW46IC0tLQo=
im getting following output

Used config
$this->client = $this->manager->make([
'host' => '127.0.0.1',
'port' => '110',
'encryption' => false
'validate_cert' => false,
'username' => 'user',
'password' => 'user',
'protocol' => 'pop3',
])
Code to Reproduce The troubling code section which produces the reported bug.
/** @var Folder $inbox */
$inbox = $this->client->getFolderByName('INBOX');
$messages = $inbox->messages()->unseen()->get();
Expected behavior Get only the base64 encoded content decoded instead of the full raw-message including headers
Desktop / Server (please complete the following information):
- OS: Debian 11
- PHP: 8.1.8
- Version: 4.1.2
- Provider: Tobit David
We can confirm the issue: https://github.com/freescout-help-desk/freescout/issues/4181
Here is the fix: https://github.com/freescout-help-desk/freescout/commit/ca1a7d0900f2453814b13eebee034d41e0e04a1f#diff-6fff174ecb04705a27bdac6f991804b0ec6dbacfc4980e64214d17e112160c2eR192
The thing is that imap_fetchbody() with POP3 protocol returns not just body but also headers.
Here is the proper fix: https://github.com/freescout-help-desk/freescout/blob/dist/overrides/webklex/php-imap/src/Connection/Protocols/LegacyProtocol.php#L232
Hi @DaWulli @freescout-help , thanks for the report and the suggested fixes. However I'm struggling to reproduce the issue myself. Is this still reproducible with v6.0? If so, can you please share a dummy or a test case? :)
Best regards & happy coding,