Repository navigation
fix(email): fall back to the HTML body when the plain part is blank - #4295
Merged
dolfim-ibm merged 1 commit intoSep 21, 2026
Merged
Conversation
_get_body_paragraphs checks whether a part is present, not whether it produced
text, then returns unconditionally:
if self.mail.text_plain:
...
return paragraphs
A multipart/alternative message can carry a whitespace-only text/plain part
beside a real text/html one, which many senders generate automatically. That
makes mail.text_plain a truthy [' '], _split_paragraphs returns [], and the
empty list is returned instead of falling through to the HTML body. The whole
message renders with no body.
Before, on a two-part message whose plain part is a single space:
# Blank Plain Part
From: Alice <[email protected]>
To: Bob <[email protected]>
After, the same message also carries 'Real content that should appear.'
Tests: 23 passed in tests/test_backend_email.py. One new case builds the
message as raw bytes and converts it through DocumentConverter.convert().
Reverting email_backend.py alone gives 1 failed, 22 passed.
ruff check and ruff format --check are clean on both files.
Signed-off-by: Christopher Krah <[email protected]>
Contributor
|
✅ DCO Check Passed Thanks @chrikrah, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
_get_body_paragraphschecks whether a part is present, not whether it produced text, then returns unconditionally, atdocling/backend/email_backend.py:270:A
multipart/alternativemessage can carry a whitespace-onlytext/plainpart beside a realtext/htmlone, and many senders generate exactly that.mail.text_plainis then a truthy[' '],_split_paragraphs(" ")gives[], and the branch returns that empty list instead of falling through to the HTML one.The whole body is dropped, and the conversion still reports success.
Before
A two-part message whose plain part is a single space, converted through
DocumentConverter.convert():After
The same message, with the body present:
Each branch now returns only once it has produced a paragraph. The final
self.mail.bodyfallback stays as it was.Tests
One new case builds the message as raw bytes and converts it through
DocumentConverter.convert(), the path a user takes.Revert
email_backend.pyalone, keep the case, and the file gives1 failed, 22 passed.No groundtruth changed. No committed
.emlfixture carries a blank alternative part, so the suite never reached this line.Scope
A message whose plain part holds real text behaves as before: the branch still returns on the first paragraph it finds. Only the case where a branch produced nothing changes.
Duplicate search
Two open pull requests touch
docling/backend/email_backend.py: #3978 and #3791. Neither mentions_get_body_paragraphsortext_plain.Closed #4259 touched this file for a different concern, adding
isinstance(part, str)guards against non-string parts. Its diff leaves this control flow alone, so a blank string part still reproduces on top of it.Checklist:
No document covers which part supplies the body.
The change corrects existing output rather than adding a capability.