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#4407santhreal wants to merge 1 commit intoUnstructured-IO:mainUnstructured-IO/unstructured:mainfrom santhreal:fix/email-malformed-address-headersanthreal/unstructured:fix/email-malformed-address-headerCopy head branch name to clipboard
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
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.
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
partition_emailraises an uncaughtIndexErroron a valid.emlwhoseTo/From/Cc/Bccheader contains a malformed address such as an unterminated quoted string. The message is parsed withpolicy.default, whose structured address parser runs eagerly onget_all("To"), and sinceemail_metadatais computed for every element, one corrupt header aborts the whole partition. Reproduces on Python 3.11 and 3.12:The fix routes the four address properties through one helper that keeps the
policy.defaultparse (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 toNone. Includes regression tests for each header and an end-to-end partition test.