Skip to content

fix(parser): handle RTF-only message bodies without crashing - #5

Merged
tinawu0603 merged 1 commit into
masterfrom
tinawu/fix-rtf-binary-nullstrip
Jun 8, 2026
Merged

fix(parser): handle RTF-only message bodies without crashing#5
tinawu0603 merged 1 commit into
masterfrom
tinawu/fix-rtf-binary-nullstrip

Conversation

@tinawu0603

@tinawu0603 tinawu0603 commented Jun 6, 2026

Copy link
Copy Markdown

What happened

Some Outlook .msg files store the body only as compressed RTF, with no HTML or plain-text copy — common for automated mail where the real content is in the attachments. Parsing those crashed with "Unknown type of RTF compression!", which dropped the whole file (subject, sender, recipients, attachments) even though all of it was readable.

The fix

Two bugs. Binary properties were getting their null bytes stripped, but those bytes are real data — the compressed-RTF stream is full of them, and removing them shifted the header so the decompressor choked. Binary values are now left untouched. The decompressed body also came back as raw RTF bytes nothing decoded; it's now turned into clean plain text (empty when the RTF carries no content), matching the HTML and plain-text paths. Adds striprtf to the rtf extra.

Evidence

A real .msg that used to throw the RTF error now parses with all 9 attachments preserved and a correctly empty body. Existing parse and msg-to-eml tests still pass, non-RTF output is byte-identical, and a new test pins the null-byte behavior so an upstream re-sync can't silently reintroduce it.

Testing

Video of a MSG that worked before and after, ensuring no regression

Screen.Recording.2026-06-05.at.23.04.16.mov

Video of the file broken in prod but working locally after this change when pointing backend-service to use the locally updated msg_parser package

Screen.Recording.2026-06-05.at.23.02.45.mov

File broken in prod
CleanShot 2026-06-05 at 23 13 41@2x

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0049009. Configure here.

Comment thread msg_parser/msg_parser.py Outdated
Comment thread msg_parser/msg_parser.py Outdated
@tinawu0603
tinawu0603 force-pushed the tinawu/fix-rtf-binary-nullstrip branch from 0049009 to 2df070e Compare June 6, 2026 03:50
### What happened
Some Outlook .msg files store the body only as compressed RTF, with no HTML or plain-text copy — common for automated mail where the real content is in the attachments. Parsing those crashed with "Unknown type of RTF compression!", which dropped the whole file (subject, sender, recipients, attachments) even though all of it was readable.

### The fix
Two bugs. Binary properties were getting their null bytes stripped, but those bytes are real data — the compressed-RTF stream is full of them, and removing them shifted the header so the decompressor choked. Binary values are now left untouched. The decompressed body also came back as raw RTF bytes nothing decoded; it's now turned into clean plain text (empty when the RTF carries no content), matching the HTML and plain-text paths. Adds striprtf to the rtf extra.

### Evidence
A real .msg that used to throw the RTF error now parses with all 9 attachments preserved and a correctly empty body. Existing parse and msg-to-eml tests still pass, non-RTF output is byte-identical, and a new test pins the null-byte behavior so an upstream re-sync can't silently reintroduce it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tinawu0603
tinawu0603 force-pushed the tinawu/fix-rtf-binary-nullstrip branch from 2df070e to e15b64f Compare June 6, 2026 04:10
max-parallel: 4
matrix:
python-version: [2.7, 3.5, 3.6, 3.7]
python-version: ["3.14"]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual python version we're running, let's just set it in CI for this fork that's only used by us

@tinawu0603
tinawu0603 marked this pull request as ready for review June 6, 2026 04:13
@tinawu0603
tinawu0603 requested a review from a team as a code owner June 6, 2026 04:13
@tinawu0603
tinawu0603 merged commit 51a2844 into master Jun 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants