Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNKNOWN-CTE Invalid data in MIME part #1186

Closed
nicofrand opened this issue Jun 20, 2023 · 8 comments
Closed

UNKNOWN-CTE Invalid data in MIME part #1186

nicofrand opened this issue Jun 20, 2023 · 8 comments
Labels
enhancement New feature or request workaround

Comments

@nicofrand
Copy link

Describe the bug

Hi,

when trying to download an attachment from an email I sometimes get a blank page and an error in the logs: UNKNOWN-CTE Invalid data in MIME part.

The attachment icon and filename are correct and it only happens for some attachments.

I tried with Roundcube and I could download the attachment just fine. This might come from my configuration but I am unable to debug more. Could you help?

To Reproduce
Steps to reproduce the behavior:

  1. Open the email with attachment (should be a PDF)
  2. Click on the attachment
  3. The link opened is blank

Expected behavior

The PDF file is shown/downloaded.

Please complete the following information:

  • Browser: Firefox beta
  • IMAP daemon: dovecot (I believe)
  • PHP version: 8.2
  • SnappyMail Version: 2.28.1
  • Mode: Yunohost

Debug/logging information

[2023-06-20 08:59:32.026][a84a4773] IMAP[WARNING]: MailSo\Imap\Exceptions\NegativeResponseException: UNKNOWN-CTE Invalid data in MIME part in /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/ResponseCollection.php:46
Stack trace:
#0 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/ImapClient.php(583): MailSo\Imap\ResponseCollection->validate()
#1 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/Commands/Messages.php(112): MailSo\Imap\ImapClient->yieldUntaggedResponses()
#2 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/Commands/Messages.php(129): MailSo\Imap\ImapClient->FetchIterate()
#3 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Mail/MailClient.php(242): MailSo\Imap\ImapClient->Fetch()
#4 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Actions/Raw.php(149): MailSo\Mail\MailClient->MessageMimeStream()
#5 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Actions/Raw.php(38): RainLoop\Actions->rawSmart()
#6 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/ServiceActions.php(344): RainLoop\Actions->RawDownload()
#7 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Service.php(133): RainLoop\ServiceActions->ServiceRaw()
#8 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Service.php(14): RainLoop\Service::RunResult()
#9 /var/www/snappymail/snappymail/v/2.28.1/include.php(143): RainLoop\Service::Handle()
#10 /var/www/snappymail/index.php(11): include('...')
#11 {main}
[2023-06-20 08:59:32.026][a84a4773] [ERROR]: UNKNOWN-CTE Invalid data in MIME part
[2023-06-20 08:59:32.026][a84a4773] PATHS[ERROR]: Array
(
    [0] => Raw
    [1] => 0
    [2] => Download
    [3] => eyJmb2x-----------REDACTED--------------------
)

Additional context

The app installed in YunoHost through the yunohost snappymail package.
Add any other context about the problem here.

Here are the raw response headers from Roundcube (not installed on my server):

HTTP/2 200 OK
cache-control: private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0
content-disposition: inline; filename="Renouvellement_de_votre_offre_energie.pdf"
content-type: application/pdf
expires: Tue, 20 Jun 2023 09:12:21 GMT
last-modified: Tue, 20 Jun 2023 09:12:21 GMT
pragma: no-cache
referrer-policy: same-origin
server: Caddy
x-dns-prefetch-control: off
x-frame-options: sameorigin
x-powered-by: PHP/7.4.7
date: Tue, 20 Jun 2023 09:12:22 GMT
X-Firefox-Spdy: h2
@the-djmaze
Copy link
Owner

CTE (common table expression) is mostly an SQL error.
It seems your IMAP server relies on database/other storage.

Do you have more details about the IMAP setup?

@nicofrand
Copy link
Author

I use Mailden.net to host my emails (even though Yunohost provides such a service and I might have related apps on my server) so I don't know about the IMAP setup (sorry if I was not clear in the description about that, I don't know if an IMAP daemon is used as a client or server).

The roundcube client I used is the one provided by Mailden too, and I don't have any issue with it.

Is there a command I can launch to debug further, instead of the UI?

@nicofrand
Copy link
Author

Based on https://datatracker.ietf.org/doc/rfc9051/ I don't think CTE relates to database but more to Content-Transfer-Encoding though.

@the-djmaze
Copy link
Owner

To get more info you can enable debug mode in application.ini
https://github.com/the-djmaze/snappymail/wiki/FAQ#how-do-i-enable-logging

@nicofrand
Copy link
Author

Would the logs below help to understand the mime issue?

[2023-06-22 11:54:10.238][48e662f3] IMAP[INFO]: Start connection to "ssl://box.mailden.net:993"
[2023-06-22 11:54:10.264][48e662f3] IMAP[INFO]: Connect (success)
[2023-06-22 11:54:10.264][48e662f3] IMAP[DEBUG]: 0.026429176330566 (raw connection)
[2023-06-22 11:54:10.266][48e662f3] IMAP[INFO]: < * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN] Mailden's IMAP ready. JeSuisCharlie\r\n
[2023-06-22 11:54:10.266][48e662f3] IMAP[DEBUG]: 0.028342008590698 (*)
[2023-06-22 11:54:10.266][48e662f3] IMAP[INFO]: > TAG1 AUTHENTICATE PLAIN *******\r\n
[2023-06-22 11:54:10.277][48e662f3] IMAP[INFO]: < TAG1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE BINARY MOVE NOTIFY] Logged in\r\n
[2023-06-22 11:54:10.277][48e662f3] IMAP[DEBUG]: 0.010935068130493 (TAG1)
[2023-06-22 11:54:10.278][48e662f3] IMAP[INFO]: > TAG2 EXAMINE "Archive/Administratif"\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * OK [PERMANENTFLAGS ()] Read-only mailbox.\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * 65 EXISTS\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * 0 RECENT\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * OK [UIDVALIDITY 1484035900] UIDs valid\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * OK [UIDNEXT 67] Predicted next UID\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < * OK [HIGHESTMODSEQ 28] Highest\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[INFO]: < TAG2 OK [READ-ONLY] Examine completed (0.000 secs).\r\n
[2023-06-22 11:54:10.281][48e662f3] IMAP[DEBUG]: 0.0038468837738037 (TAG2)
[2023-06-22 11:54:10.282][48e662f3] IMAP[INFO]: > TAG3 UID FETCH 62 (UID RFC822.SIZE BODY.PEEK[2.MIME])\r\n
[2023-06-22 11:54:10.315][48e662f3] IMAP[INFO]: < * 61 FETCH (UID 62 RFC822.SIZE 140941 BODY[2.MIME] {156}\r\n
[2023-06-22 11:54:10.316][48e662f3] IMAP[INFO]: < )\r\n
[2023-06-22 11:54:10.316][48e662f3] IMAP[INFO]: < TAG3 OK Fetch completed.\r\n
[2023-06-22 11:54:10.316][48e662f3] IMAP[DEBUG]: 0.034214019775391 (TAG3)
[2023-06-22 11:54:10.318][48e662f3] IMAP[INFO]: > TAG4 UID FETCH 62 (UID RFC822.SIZE BINARY.PEEK[2])\r\n
[2023-06-22 11:54:10.352][48e662f3] IMAP[INFO]: < * 61 FETCH (UID 62 RFC822.SIZE 140941)\r\n
[2023-06-22 11:54:10.352][48e662f3] IMAP[INFO]: < TAG4 NO [UNKNOWN-CTE] Invalid data in MIME part\r\n
[2023-06-22 11:54:10.352][48e662f3] IMAP[DEBUG]: 0.03368091583252 (TAG4)
[2023-06-22 11:54:10.354][48e662f3] IMAP[WARNING]: MailSo\Imap\Exceptions\NegativeResponseException: UNKNOWN-CTE Invalid data in MIME part in /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/ResponseCollection.php:46
Stack trace:
#0 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/ImapClient.php(583): MailSo\Imap\ResponseCollection->validate()
#1 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/Commands/Messages.php(112): MailSo\Imap\ImapClient->yieldUntaggedResponses()
#2 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Imap/Commands/Messages.php(129): MailSo\Imap\ImapClient->FetchIterate()
#3 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/MailSo/Mail/MailClient.php(242): MailSo\Imap\ImapClient->Fetch()
#4 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Actions/Raw.php(149): MailSo\Mail\MailClient->MessageMimeStream()
#5 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Actions/Raw.php(38): RainLoop\Actions->rawSmart()
#6 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/ServiceActions.php(344): RainLoop\Actions->RawDownload()
#7 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Service.php(133): RainLoop\ServiceActions->ServiceRaw()
#8 /var/www/snappymail/snappymail/v/2.28.1/app/libraries/RainLoop/Service.php(14): RainLoop\Service::RunResult()
#9 /var/www/snappymail/snappymail/v/2.28.1/include.php(143): RainLoop\Service::Handle()
#10 /var/www/snappymail/index.php(11): include('...')
#11 {main}
[2023-06-22 11:54:10.354][48e662f3] [ERROR]: UNKNOWN-CTE Invalid data in MIME part
[2023-06-22 11:54:10.355][48e662f3] PATHS[ERROR]: Array
(
    [0] => Raw
    [1] => 0
    [2] => Download
    [3] => eyJmb2x-----------REDACTED--------------------
)

[2023-06-22 11:54:10.355][48e662f3] IMAP[INFO]: > TAG5 LOGOUT\r\n
[2023-06-22 11:54:10.357][48e662f3] IMAP[INFO]: < * BYE Logging out\r\n
[2023-06-22 11:54:10.357][48e662f3] IMAP[INFO]: < TAG5 OK Logout completed.\r\n
[2023-06-22 11:54:10.357][48e662f3] IMAP[DEBUG]: 0.0027658939361572 (TAG5)
[2023-06-22 11:54:10.358][48e662f3] IMAP[INFO]: Disconnected from "ssl://box.mailden.net:993" (success)

As I said, using Roundcube I can perfectly download the file.
Maybe there is an imap command I can launch to check its mime type?
Or maybe snappymail could be more permissive?

@the-djmaze
Copy link
Owner

YES!

IMAP[INFO]: > TAG4 UID FETCH 62 (UID RFC822.SIZE BINARY.PEEK[2])\r\n
IMAP[INFO]: < * 61 FETCH (UID 62 RFC822.SIZE 140941)\r\n
IMAP[INFO]: < TAG4 NO [UNKNOWN-CTE] Invalid data in MIME part\r\n

Open snappymail/v/N.N.N/app/libraries/MailSo/Imap/ImapClient.php
Around line 320 add a line that disables BINARY.

			if ($this->Settings->disable_list_status) {
				$aList = \array_diff($aList, ['LIST-STATUS']);
			}
			// Disable BINARY for issue #1186
			$aList = \array_diff($aList, ['BINARY']);
			if (8 > PHP_INT_SIZE) {
				$aList = \array_diff($aList, ['CONDSTORE']);
			}

For whatever reason your IMAP server can't decode the attachment and send it binary.
If the above change works, i will make it an option in the Admin -> Domains -> Domain

@nicofrand
Copy link
Author

That worked!

Should I contact my email provider? Would you know by any chance which details I should provide for them to fix the attachment decoding?

@nicofrand
Copy link
Author

FWIW Roundcube seems to also have a workaround for this kind of emails: roundcube/roundcubemail#6383

@the-djmaze the-djmaze added enhancement New feature or request workaround labels Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround
Projects
None yet
Development

No branches or pull requests

2 participants