Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(email): degrade gracefully on malformed address headers#4407

Open
santhreal wants to merge 1 commit into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
santhreal:fix/email-malformed-address-headersanthreal/unstructured:fix/email-malformed-address-headerCopy head branch name to clipboard
Open

fix(email): degrade gracefully on malformed address headers#4407
santhreal wants to merge 1 commit into
Unstructured-IO:mainUnstructured-IO/unstructured:mainfrom
santhreal:fix/email-malformed-address-headersanthreal/unstructured:fix/email-malformed-address-headerCopy head branch name to clipboard

Conversation

@santhreal

@santhreal santhreal commented Jul 17, 2026

Copy link
Copy Markdown

partition_email raises an uncaught IndexError on a valid .eml whose To/From/Cc/Bcc header contains a malformed address such as an unterminated quoted string. The message is parsed with policy.default, whose structured address parser runs eagerly on get_all("To"), and since email_metadata is computed for every element, one corrupt header aborts the whole partition. Reproduces on Python 3.11 and 3.12:

import io
from unstructured.partition.email import partition_email
partition_email(file=io.BytesIO(b'To: "\r\nFrom: a@b.com\r\n\r\nbody\r\n'))
# IndexError: list index out of range  (email/_header_value_parser.py, local_part)

The fix routes the four address properties through one helper that keeps the policy.default parse (so encoded-word decoding for well-formed headers is unchanged) and falls back to a lenient compat32 re-parse only when it raises. Well-formed addresses in a mixed header are still recovered; a wholly malformed header degrades to None. Includes regression tests for each header and an end-to-end partition test.

partition_email crashed with an IndexError raised by the stdlib
email._header_value_parser when a To/From/Cc/Bcc header held a malformed
address such as an unterminated quoted string. policy.default parses
address headers eagerly on get_all, so a single bad recipient header
aborted the whole partition.

Route the four address properties through one helper that falls back to a
lenient compat32 re-parse when the structured parser raises, recovering
the well-formed addresses in a mixed header and degrading to None when
none are recoverable.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 2 files

Shadow auto-approve: would auto-approve. Fix for crash on malformed email address headers, with a fallback that recovers valid addresses. Adds regression tests. The change is bounded and clearly beneficial.

Re-trigger cubic

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.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.