Skip to content

feat(email): parse email attachments - #3978

Open
DanielNg0729 wants to merge 6 commits into
docling-project:mainfrom
DanielNg0729:feat/email-attachment-parsing
Open

DanielNg0729 wants to merge 6 commits into
docling-project:mainfrom
DanielNg0729:feat/email-attachment-parsing

Conversation

@DanielNg0729

@DanielNg0729 DanielNg0729 commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Hi maintainers, this PR is to follow-up to #3873 and #3909 to now actually parse the attachment instead of just listing it.
#3873 added .eml/.msg parsing and optional listing of attachment names, this PR optionally parses the attachments themselves.

Summary

With EmailBackendOptions(process_attachments=True), Docling converts each attachment and adds its content under an "Attachments" section, with one subsection per attachment. A PDF, DOCX, PPTX, XLSX, image or HTML attachment goes through the same pipeline as a standalone document (layout, tables, OCR, ...), with the default options of its format.

If Docling cannot parse an attachment (unsupported format, missing optional dependency, corrupt bytes), the attachment gets a name (content_type): could not be parsed by Docling. note. Each count or size limit also leaves a note. No attachment is dropped without a trace.

How it works

  • The attachment bytes come from the same mail-parser representation for .eml and .msg, so both formats use one code path. The backend decodes base64 and quoted-printable payloads.
  • The email backend (Tach layer core) must not import DocumentConverter (layer entrypoints). So document_converter.py injects a factory with register_attachment_converter_factory(). If no factory is registered, the backend lists the attachments instead.
  • All emails share one attachment converter (functools.cache). The pipelines and models load once per process, not once per email.
  • DoclingDocument.add_document(child, parent=<attachment heading>) merges each converted attachment into the email document.
  • The attachment converter uses default options. So an attached .eml/.msg is parsed, but its own attachments are not.
  • The option is opt-in (default off), because it runs a full pipeline for each attachment. Limits: max_attachments (default 32), max_attachment_bytes (default 25 MB) and max_attachment_total_bytes (default 100 MB).

Known limits

  • Attachments use the default options of their format. The format_options (for example PdfPipelineOptions for OCR, tables or the accelerator) and the allowed_formats of your converter do not apply to attachments. The process_attachments description and docs/usage/supported_formats.md state this.
  • A failed attachment gives a note in the document. It does not add an entry to ConversionResult.errors, and the status stays SUCCESS, because the backend has no access to the conversion result.
  • The shared attachment converter keeps its models in memory until the process ends.

Usage

from docling.datamodel.base_models import InputFormat
from docling.datamodel.backend_options import EmailBackendOptions
from docling.document_converter import DocumentConverter, EmailFormatOption

converter = DocumentConverter(
    format_options={
        InputFormat.EMAIL: EmailFormatOption(
            backend_options=EmailBackendOptions(process_attachments=True)
        )
    }
)

# Works for .eml and .msg; attachment content is embedded in the result.
doc = converter.convert("message.eml").document
print(doc.export_to_markdown())

Set list_attachments=True instead to only list attachment names/types without parsing them (the previous behavior).

Checklist:

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@DanielNg0729 DanielNg0729 changed the title feat(email): parse Outlook email attachments feat(email): parse email attachments Aug 11, 2026
@mergify

mergify Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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)(?:\(.+\))?(!)?:

@codecov

codecov Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.81818% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/email_backend.py 69.00% 25 Missing and 6 partials ⚠️

📢 Thoughts on this report? Let us know!

@DanielNg0729

Copy link
Copy Markdown
Member Author

Hi Dr @dolfim-ibm, just wanted to kindly follow up on this PR too. This is ready for review when you have a moment. Thank you very much!

@adrienpl

Copy link
Copy Markdown

Great initiative! Our team is eagerly waiting for this recursive attachment parsing feature to be merged. 🚀

Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
@DanielNg0729
DanielNg0729 force-pushed the feat/email-attachment-parsing branch from 863674e to bfaf044 Compare October 13, 2026 06:17
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI enhancement New feature or request tests issue related to changes needed in the tests labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

Adds an opt-in process_attachments option to EmailBackendOptions. When it is on, the email backend converts each .eml and .msg attachment with a shared DocumentConverter and merges the result into the email document. New options limit the attachment count and size. Attachments that cannot be parsed leave a note.

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

1 related pull request(s) in the same code
PR State Signal Assessment
#3873 merged referenced as #3873; also references issue #3909 related: This PR is merged. It added .msg support and attachment name listing. This PR builds on that code and adds attachment parsing, which is a different feature.

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 bfaf044033. It read the code and did not run it.

The feature is opt-in, and the base64 and size-limit paths look correct. The main risk is that attachments past max_attachments are dropped without any note. This conflicts with the PR claim that nothing is silently dropped. Check that behavior, and check how DocumentConverter() is created per email.

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

Comment thread docling/backend/email_backend.py Resolved
Comment thread docling/backend/email_backend.py Resolved
@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 13, 2026
…max_attachments

Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
@github-actions github-actions Bot added ai:ci-needs-care AI triage: check CI-safety findings before you approve CI and removed ai:ci-needs-care AI triage: check CI-safety findings before you approve CI ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Oct 13, 2026

@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 changes since bfaf044033 at 9d12e6f78f. It read the code and did not run it.

The new changes address both earlier findings. I found no new defect. The email backend now notes attachments over max_attachments, and all emails share one cached attachment converter. The limit that attachments use default options is now documented.

Earlier findings

  • fixed (question): A new DocumentConverter() per email ignores user pipeline options and reloads pipelines
  • fixed (suggestion): Attachments over max_attachments are dropped with no note

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 Oct 13, 2026
@PeterStaar-IBM PeterStaar-IBM added the email issue related to email (EML, MSG) backend label Nov 6, 2026
Signed-off-by: Nguyen Hoang Duong <danielnguyenh07@gmail.com>
@github-actions github-actions Bot removed the ai:ci-needs-care AI triage: check CI-safety findings before you approve CI label Nov 7, 2026
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 7, 2026
Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
@github-actions github-actions Bot removed the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 7, 2026
@DanielNg0729

Copy link
Copy Markdown
Member Author

Hi Dr @dolfim-ibm, Dr @PeterStaar-IBM , i also wanted to kindly follow up on this PR too. This is ready for review when you have a moment. Thank you very much!

@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Nov 7, 2026
PeterStaar-IBM
PeterStaar-IBM previously approved these changes Nov 7, 2026
@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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)(?:\(.+\))?(!)?:

1 similar comment
@mergify

mergify Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 2 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require two reviewer for test updates 👀 reviews
🟢 Enforce conventional commit —

🔴 Require two reviewer for test updates

Waiting for

  • #approved-reviews-by >= 2
This rule is failing.

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

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)(?:\(.+\))?(!)?:

Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Nov 11, 2026
@DanielNg0729

DanielNg0729 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member Author

Hi @dolfim-ibm, @PeterStaar-IBM, i wanted to kindly follow up on this PR too. I just rebased this with the latest main to resolve the conflict. This is ready for review when you have a moment. Thank you very much

@ceberam

ceberam commented Nov 11, 2026

Copy link
Copy Markdown
Member

@DanielNg0729 Thanks a lot for your effort on this PR!
We need a global contract on how Docling should process attachments.
I raised this concern on another PR you opened (#4716) regarding attachments in Office documents.
These 2 PRs follow different approaches and consistency across Docling backends should also be taken into account.
I have listed some thoughts on this discussion here: #5251. It would be good if you could share your view too. IMHO, we should first agree on a common contract and only then proceed with the implementation across all the backends consistently.

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) email issue related to email (EML, MSG) backend enhancement New feature or request tests issue related to changes needed in the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants