markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

feat: add EmlConverter with attachment support

Open VANDRANKI opened this issue 7 months ago • 1 comments

Summary

Adds EmlConverter for converting RFC 822 .eml files to markdown.

This extends the gap identified in issue #1662. The converter handles:

  • Email headers (From, To, Cc, Subject, Date)
  • Body content (prefers text/plain, falls back to text/html with tag stripping)
  • Attachments: each attachment is passed through the MarkItDown converter pipeline and rendered under its own heading in the output

What this PR covers

  • converters/_eml_converter.py - new EmlConverter class
  • converters/__init__.py - registers the new converter in exports
  • _markitdown.py - registers EmlConverter(markitdown=self) in enable_builtins(), matching the ZipConverter pattern for recursive conversion
  • tests/test_eml_converter.py - 11 tests covering headers, body, attachment conversion, unsupported format fallback, and body/attachment isolation

Attachment design

Attachment conversion follows the same pattern as ZipConverter: a MarkItDown instance is injected via the constructor and used to call convert_stream() on each attachment. This means any format markitdown supports (XLSX, PDF, DOCX, etc.) is automatically available for email attachments with no additional code.

If no MarkItDown instance is available (e.g., the converter is instantiated directly), attachments are listed by filename with a note rather than silently skipped.

Example output

# Email Message

**From:** [email protected]
**To:** [email protected]
**Subject:** Q1 Report
**Date:** Sat, 04 Apr 2026 12:00:00 +0000

## Content

Please find the Q1 report attached.

## Attachments

### Q1_Report.xlsx

## Sheet1
| Quarter | Revenue |
|---------|---------|
| Q1 2026 | 1.2M    |

Testing

All 11 tests pass. ruff check and ruff format pass with zero issues.

Closes #1662

VANDRANKI avatar Apr 04 '26 22:04 VANDRANKI

@microsoft-github-policy-service agree

VANDRANKI avatar Apr 04 '26 22:04 VANDRANKI