Skip to content

fix(email): drop the empty entry of an address group - #4576

Merged
cragwolfe merged 2 commits into
Unstructured-IO:mainfrom
chrikrah:fix/email-empty-address-group
Oct 22, 2026
Merged

cragwolfe merged 2 commits into
Unstructured-IO:mainfrom
chrikrah:fix/email-empty-address-group

Conversation

@chrikrah

@chrikrah chrikrah commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

partition_email() reports To: undisclosed-recipients:; as sent_to=[""]. This change drops entries without an address and gives None, as a missing header does.

That header is an RFC 5322 group with no members, which mail clients write whenever every recipient is in Bcc. email.utils.getaddresses() returns it as ("", ""), and the four address properties in email.py format that pair into an empty string. cc_recipient and bcc_recipient do the same:

To: undisclosed-recipients:;   Cc: Team: [email protected], [email protected];   Bcc: undisclosed-recipients:;
08d407e:     sent_to=['']   cc_recipient=['[email protected]', '[email protected]']   bcc_recipient=['']
this change: sent_to=None   cc_recipient=['[email protected]', '[email protected]']   bcc_recipient=None

One helper, _format_addresses(), now drops entries without an address for all four properties, and returns None when none are left, as a missing header already does. A group with members keeps only their addresses. The filter also covers a header that the strict parser in Python 3.12.3 rejects, such as [email protected] <[email protected]>. It also comes back as ("", ""), so it gives None now, as in #4407. CHANGELOG entry under 0.27.31, with the version bumped.

Testing

$ python -m pytest -q -p no:cacheprovider test_unstructured/partition/test_email.py
77 passed, 1 skipped in 3.81s
# baseline at 08d407e: 76 passed, 1 skipped, so the delta is the new test
# email.py reverted, test kept: 1 failed, 76 passed, 1 skipped (test_partition_email_drops_the_empty_entry_of_an_address_group)
$ ruff check unstructured/partition/email.py test_unstructured/partition/test_email.py
All checks passed!
$ ruff format --check unstructured/partition/email.py test_unstructured/partition/test_email.py
2 files already formatted
# ruff 0.15.0, Python 3.12
# not run: scripts/version-sync.sh -c, which needs an origin remote; test_msg.py, which fails 4 tests here with or without this change because the extras are not installed

No issue exists for this. #4407 dropped the same empty entries inside a larger parser fallback and was closed by its author before review. This is only that filter, on the code #4543 left. @cragwolfe, you merged #4543 on these properties. I picked None over [] because a missing header already gives None, so callers test one value. Say if [] fits better and I will switch it.

View guided diff

An RFC 5322 group with no members, such as "To: undisclosed-recipients:;",
comes back from email.utils.getaddresses() as ("", ""), so sent_to,
cc_recipient and bcc_recipient held [""]. Drop entries without an address
in one helper used by all four address properties.

Signed-off-by: Christopher Krah <[email protected]>

@cragwolfe cragwolfe 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.

Reviewed 88de740fc05a50ab1d00df238489459e2753a5b1 with GPT Pro. No actionable code defects or material missing coverage found. Empty-address filtering preserves the formatting and order of retained mailboxes, and the serialized-message regression test covers empty groups alongside a populated group.

This is a code-review approval. GitHub currently reports merge conflicts with main. Required checks changelog, test_dockerfile, lint (3.12), test_unit (3.12), and test_ingest_src (3.12) have no results for this head, and no GitHub Actions runs are listed for it. The Socket project report succeeded and pull request alerts are neutral; these do not establish test success. Resolve the conflicts and obtain the required CI results before merging. No tests were run locally for this review.

(authored by codex)

@cragwolfe
cragwolfe merged commit 6d1aa94 into Unstructured-IO:main Oct 22, 2026
52 checks passed
@CyMule CyMule mentioned this pull request Oct 22, 2026
linhongyu510 pushed a commit to linhongyu510/unstructured that referenced this pull request Oct 22, 2026
Drops the `-dev6` suffix so 0.27.34 can be tagged and published. There
are no code changes.

Since 0.27.33, this release contains:

- Free decode buffers sooner when restoring original elements (Unstructured-IO#4524)
- Free image buffers sooner during figure extraction (Unstructured-IO#4523)
- Honor `encoding=` in `partition_json` and `partition_ndjson` (Unstructured-IO#4483)
- Read a PowerPoint line break as a newline (Unstructured-IO#4571)
- Drop the empty entry of an email address group (Unstructured-IO#4576)
- Read CSV and TSV cells as the file holds them (Unstructured-IO#4574)
- Classify text as an email address only when all of it is one (Unstructured-IO#4577)

After merge, create the `0.27.34` GitHub release from the merge commit.
That publishes to PyPI.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4582?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by 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.

2 participants