Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

mbox_extractor.py

A simple Python script to extract emails and attachments from .mbox files and optionally convert them into readable PDF documents.

📦 Features

  • Extracts all emails from an .mbox archive
  • Saves individual emails as .eml files (if you want to skip saving .eml files, use the --no-eml flag)
  • Extracts and saves attachments
  • Converts emails to clean, human-readable PDF files (optional)
  • Quiet mode for batch or automated processing

🧰 Requirements

  • Python 3.7 or higher
  • The following Python packages:
    pip install reportlab

🚀 Usage

python mbox_extractor.py --mbox path/to/file.mbox [options]

Arguments

Argument Description Required
--mbox Path to the .mbox file to extract ✅ Yes
--out Output directory for extracted files (default: extracted_emails) ❌ No
--pdf Generate readable PDF files for each email ❌ No
--no-eml Do not save individual .eml files ❌ No
--quiet Suppress output messages (silent mode) ❌ No

Example

Extract all emails and attachments from inbox.mbox and generate PDFs:

python mbox_extractor.py --mbox inbox.mbox --pdf

Extract emails only, without creating PDFs or saving .eml files:

python mbox_extractor.py --mbox archive.mbox --no-eml --quiet

🗂️ Output Structure

If not specified otherwise, the script creates this structure for each mail in the output directory, similar to:

0001_subject/
├── 0001.eml
├── 0001.pdf
├── attachment1.pdf
├── attachment2.jpg
└── ...

⚙️ Notes

  • The script uses Python’s standard mailbox module to read .mbox archives.
  • PDFs are generated only if the --pdf flag is used.
  • When --no-eml is enabled, .eml files are skipped but attachments and PDFs are still saved.

🪪 License

This project is released under the MIT License.

About

Extract emails and attachments from .mbox files and optionally convert them into clean, readable PDF documents. Perfect for archiving, indexing, or reviewing large email exports from clients like Gmail, Thunderbird, or Apple Mail. Includes options for selective export, silent mode, and customizable output structure.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages