Skip to content

fix(email): keep display name of Exchange recipients in .msg files - #5704

Open
shashank11yadav wants to merge 1 commit into
docling-project:mainfrom
shashank11yadav:fix/msg-exchange-recipient
Open

shashank11yadav wants to merge 1 commit into
docling-project:mainfrom
shashank11yadav:fix/msg-exchange-recipient

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

The .msg converter lost a To or Cc recipient whenever that recipient had no SMTP address. Inside an Exchange organisation, python-oxmsg returns the legacy Exchange DN (/O=.../CN=...) as the address in that case. The recipient loop passed the DN through formataddr(), so mailparser found no usable mailbox and dropped the recipient. When every recipient in a header was like this, the whole To or Cc line was missing from the converted document.

For a recipient with no SMTP address, the header now keeps only the display name. The To or Cc text is built from the .msg recipients in their original order, using the same quoting and header-safety helpers as the sender path. The display name is read from its own property rather than re-parsed from a combined string, so a DN with parentheses or a name with a comma is handled. A recipient with neither an address nor a name is skipped. Messages where every recipient has an SMTP address take the same path as before.

_msg_to_rfc822_bytes now returns a third value, the per-header text. The email tests that call it are updated for the new return shape. No documentation, examples or test data changed.

Issue resolved by this Pull Request:
Fixes #5703

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

  • Without the fix, the four new tests fail (4 failed).
  • With the fix, the four new tests pass (4 passed).
  • The three email test files (tests/test_backend_email.py, tests/test_backend_email_msg_sender.py, tests/test_backend_email_msg_nul.py) give 72 passed.
  • Lint: ruff check reports all checks passed. ruff format --check over the repo's Python directories reports 987 files already formatted.
  • Types and limits: ty check exits 0, tach check reports all modules validated, and the max-lines check (1500 lines per file) exits 0.
  • Not run: the full test suite, so only the three email test files above were run. The pre-commit hooks that CI's lint job runs (prek) were not run.

For a .msg recipient inside an Exchange organisation, python-oxmsg
returns the legacy Exchange DN as the address when no SMTP address is
stored. formataddr() put it in the angle brackets, mailparser dropped
the mailbox, and the converted document lost the recipient, or the
whole To/Cc line.

As for the sender, keep the display name of such a recipient and
render the header from the .msg recipients when one of them has no
SMTP address. The name is taken from PidTagDisplayName directly, so
a DN with "(FYDIBOHF23SPDLT)" or a name with a comma is not re-parsed.

Signed-off-by: Shashank Yadav <65058495+shashank11yadav@users.noreply.github.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @shashank11yadav, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working email issue related to email (EML, MSG) backend priority:medium labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 5d570ecc6f. The analysis read the diff only. It did not run code from this pull request.

The change keeps the display name of a .msg recipient that has only a legacy Exchange DN and no SMTP address. _msg_to_rfc822_bytes now returns a third value with the full To and Cc text, and convert() uses it.

Topic labels added: bug, email, priority:medium.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#5590 open changes the same code related: Both PRs change docling/backend/email_backend.py. PR 5590 keeps the body apart from the text of an attached message. This PR fixes lost .msg recipients. The problems are different, and both PRs can merge.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions 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.

AI first review (advisory): no blocker found

This review covers the full diff at 5d570ecc6f. It read the code and did not run it.

I found no defect that blocks the merge. I traced the new recipient loop and the convert() override in docling/backend/email_backend.py. Recipients with an SMTP address still take the old formataddr path. A recipient without one now shows only its display name, and the shown text goes through _header_safe and _quote_display_name. The new tests cover the comma, parentheses and header-injection cases.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Dec 1, 2026
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/email_backend.py 94.44% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working email issue related to email (EML, MSG) backend priority:medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.msg: a recipient with a legacy Exchange address loses the To line

1 participant