Extract EML files from an MBOX file
Solved Email & Outlook
AJ
Andrew Jackson
February 12, 2021
2 replies
7,340 views
Reviewed by moderators

I have a single MBOX file and need it split into individual EML files, one per message, for a system that ingests EML.

What splits an MBOX into per message EML files reliably?

Accepted Answer
Verified by Eddie Thwan, Forum Moderator ยท Reviewed February 2021

This is the cleanest of the MBOX operations because it is essentially unpacking a container into its contents, one message becoming one EML and the routes run from script to tool:

The script route, again the most control: Python's mailbox module opens the MBOX, iterates messages and writes each with as_bytes to a numbered or subject named .eml file, a dozen lines producing the exact per message EML the ingesting system wants. The control matters here for naming, since the target system often has filename expectations, date prefixed or ID based, that a script satisfies precisely while a tool may not.

The client route: Thunderbird with ImportExportTools NG imports the MBOX and then exports the folder as individual EML files, the add-on's export all messages as EML operation doing exactly this split with a folder of results.

The converter route: MBOX to EML converters do the split as their whole purpose, keeping folder structure if the MBOX came from a multi folder export, useful when the source was a full mailbox rather than one folder.

The naming and encoding details that decide whether the ingesting system accepts the output: filenames need to match what the system expects and avoid characters it rejects, subject based names sanitized of slashes and colons and the EML output should preserve the original headers and encoding intact rather than re encoding, which a straight write of the message bytes achieves and a careless conversion can corrupt. Test one EML through the ingesting system before splitting the whole MBOX, the single file that validates the naming and format before you commit thousands.

Python script with ID based filenames the ingesting system wanted, split 3,000 messages cleanly and the test EML validated first so the full run just worked. Preserving headers with a straight byte write mattered, an earlier converter attempt had re encoded and the system rejected those. Control was the right call.