fix: fetch IMAP body parts individually to avoid malformed MIME#291
Conversation
|
Thanks. The embedded-MIME issue is real and Blocker: Perf regression: the blanket re-fetch. The old code re-fetched a part only when it came back missing or zero-length. This re-fetches every text part and every inline image individually on every body view, even when batching worked. That's N extra IMAP round-trips per open, which hurts connection-limited providers like PurelyMail. Please restore the Recursion guard. Split the AI commit. Net: keep |
9a6d0a7 to
cfdeaf1
Compare
|
Updated, thanks for the review. For #291 I force-pushed the branch so it now contains only the IMAP/MIME-related commits:
I also split the unrelated AI language change into a separate PR: #297. |
cfdeaf1 to
56ab35a
Compare
|
One more follow-up from testing against an existing cached malformed body: I amended the review-fix commit to make the cached-body path detect MIME-wrapper HTML ( The cached HTML path now also re-runs |
ae53f6b to
973b490
Compare
973b490 to
36dd4f2
Compare
|
Final follow-up after testing against the reproducible malformed message on my instance. What fixed the rendering was the direct fetch for text parts, not To reduce the perf hit from the original PR, inline images are no longer blanket re-fetched individually. They keep the batched value unless the returned image payload looks like text/html / quoted-printable garbage; only those suspicious inline image parts are retried directly, and still-text-looking image payloads are skipped instead of being embedded as broken This keeps the PR focused on the IMAP/MIME issue while addressing the blocker and avoiding the broad inline-image re-fetch. |
|
Thanks for the updates. Blockers 1, 3, and 4 are resolved. 2 is not: Blocker 2 isn't fixed for text parts. The comment says the re-fetch is back to fallback-only, but the text-part loop (imapManager.js ~3991) still re-fetches every part unconditionally and overwrites the batched value — no Please gate it on the actual malformation, not on the batched value existing. Note Two smaller things while you're in there:
Re-review once the text re-fetch is gated. |
|
One more item to fold into the same round, found while re-reading the inline-image path. New regression: empty inline images are no longer retried. The inline-image retry is now gated on To keep everything in one place, the full list before I re-review:
Thanks for sticking with this. The core |
Fix malformed IMAP body rendering by fetching body parts individually
Some IMAP servers can return malformed sibling payloads when MailFlow uses speculative/batched BODY part fetches for multipart/related messages. In the observed case, batch fetching returned HTML/QP content where an inline image payload was expected, causing the UI to render MIME/quoted-printable artifacts such as
=D0..., escaped tags, replacement characters, and brokendata:imageURLs.This change keeps the existing speculative fetch path, but treats it as an optimization only:
This prevents malformed batched BODY responses from being cached or rendered while preserving the existing fallback behavior.
Tested with a self-hosted MailFlow Docker deployment against a Postfix/Dovecot IMAP server where
BODY[2.1]individually returned valid HTML while batched/speculative BODY fetch produced corrupted HTML/image payloads.