You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'str' object has no attribute 'policy' crash in BytesParser for certain .olk15Message files #5
A single .olk15Message file causes extraction to crash with 'str' object has no attribute 'policy' error.
Evidence
ERROR messages 5B9C093F-3450-46F7-A067-FDEC803B6FCA.olk15Message 'str' object has no attribute 'policy'
Root Cause
writer.py:27 calls BytesParser(policy=email.policy.compat32).parsebytes(mime_bytes). The .olk15Message parser in parsers/message.py builds an EmailMessage and calls .as_bytes(), but the resulting MIME output contains something that Python's email parser chokes on — likely a malformed header or encoding issue where a header value is a str object instead of the expected type.
The _clean_text() function in parsers/message.py removes nulls but may not catch all binary artifacts that end up in header values.
Proposed Fix
In writer.py:27, wrap BytesParser.parsebytes() in a try/except with a fallback:
First try policy=email.policy.compat32
On failure, try writing the raw mime_bytes directly without re-parsing (since the bytes were already valid enough to be produced by EmailMessage.as_bytes())
In parsers/message.py, add a _sanitize_header() helper that ensures all msg[key] assignments produce clean, ASCII-safe strings before calling .as_bytes()
Log a warning when fallback is used so the user knows a message was written with reduced parsing
This issue has been resolved with the following changes:
Root Cause
writer.py:27 called BytesParser(policy=email.policy.compat32).parsebytes(mime_bytes). When the .olk15Message parser in parsers/message.py produced MIME with malformed headers (e.g., binary contamination), Python's email parser would crash with 'str object has no attribute policy' and the message was lost (returned False, not written).
Changes Made
Modified write_eml() in writer.py to catch BytesParser exceptions
On parse failure, fall back to writing raw MIME bytes directly to Maildir
Extract Message-ID from raw bytes for deduplication when parsing fails
Extract headers from raw bytes for CSV when parsing fails
Verification
All 54 tests pass
New tests verify: fallback writes succeed, CSV has entry, deduplication works in fallback mode
The problematic message (5B9C093F-3450-46F7-A067-FDEC803B6FCA) is now written successfully
Activity
thomasmaerz commentedon Apr 7, 2026
Fix Applied
This issue has been resolved with the following changes:
Root Cause
writer.py:27 called BytesParser(policy=email.policy.compat32).parsebytes(mime_bytes). When the .olk15Message parser in parsers/message.py produced MIME with malformed headers (e.g., binary contamination), Python's email parser would crash with 'str object has no attribute policy' and the message was lost (returned False, not written).
Changes Made
Verification