Files
twenty/packages
Sonarly Claude Code 72286c9d7f fix: handle all MIME structures and HTML fallback in Gmail body parser
https://sonarly.com/issue/28939?type=bug

The Gmail message import `getBodyData` function only extracts body text from two specific MIME payload structures, causing ~6.7% of imported messages (predominantly from non-Gmail senders like Yandex, SES, Android mail) to be stored with empty body text.

Fix: Rewrote `getBodyData` in `get-body-data.util.ts` to fix three failure modes that caused empty message bodies for non-Gmail senders:

1. **Single-part messages**: Added check for `payload.body.data` when no `parts` array exists. Previously, simple text-only emails (common from basic SMTP servers) were silently dropped.

2. **Recursive MIME traversal**: Replaced the fixed 2-level lookup (`parts[0]` → `parts[0].parts`) with a recursive `findPartByMimeType` function that searches all parts at any nesting depth. This handles Yandex-style `multipart/mixed > multipart/related > multipart/alternative > text/plain` structures.

3. **HTML fallback**: When no `text/plain` part exists (common with Amazon SES, some Outlook senders), the function now falls back to `text/html`. The return type was changed to `{ data, mimeType }` so the consumer can convert HTML to plain text.

Updated `parse-gmail-message.util.ts` to handle the new return type: when the body comes from `text/html`, it's converted to plain text using `html-to-text` (same library and options as the existing IMAP driver's `ImapMessageTextExtractorService`).
2026-04-20 10:40:31 +00:00
..
2026-04-20 09:29:25 +02:00
2026-04-20 08:43:02 +00:00
2026-04-16 09:47:44 +00:00