Converters

How to Split a Large MBOX File on Mac

Huge mailbox archives are awkward to open, move or import. Cutting them with the wrong tool damages messages.

6 min read

Quick AnswerSplit a large MBOX file on Mac in 2 ways. Use a Python script or converter software. Split at message boundaries and never at a byte count. Python creates numbered parts of a size you choose. Start with about 1,000 messages per part. Count the messages in all parts afterwards. Compare the total with the original file.

Years of mail exported from Gmail or Thunderbird can produce a single file of many gigabytes. Text editors freeze on it, uploads fail halfway and some tools refuse to import it. Smaller parts solve most of this, provided the cuts fall between messages.

Why Should You Split a Big Mailbox?

Smaller parts help in four ways.

  • Transfers over a slow connection can restart from one part instead of the beginning.
  • Import tools that struggle with huge files can cope with parts of a few thousand messages.
  • Damage to one part costs you a slice of mail, not everything.
  • Counting is quicker when every part has a known size.

Why Does Byte Splitting Damage Mail?

Every MBOX file is one long text file in which a line starting with From and a space begins every message (RFC 4155). General tools like the Unix split command cut at a set number of bytes or lines (see the man page) so the cut can fall in the middle of a message. Next, the following part starts with a fragment, which a mail app can reject or garble. Cuts have to follow the From line boundaries while Python’s mailbox module handles that for you.

Which Part Size Suits Your Mailbox?

Choose a message count, not a file size. Mailboxes with big attachments need smaller counts than plain text mail. Use these starting points.

Mailbox typeMessages per partWhy
Mostly text mail5,000 to 10,000Parts remain light and quick to open
Many attachments500 to 2,000Attachments make messages heavy
Unsure1,000Safe default, adjust after one test

These counts are our suggestions, not limits set by any mail app. Check what your mail app accepts before you decide.

How Do You Split an MBOX File With Python?

Who it suits. Technical users who work in Terminal. Source file size limit. None in the script. Free disk space equal to the original is needed for the parts. Extra application. Python 3 installed on your Mac.

Save the script as split_mbox.py. Create an empty folder, open Terminal there and enter python3 split_mbox.py export.mbox 1000, where the number is messages per part. Give the full path to your export if it lives elsewhere.

import sys
import mailbox

source = sys.argv[1]
size = int(sys.argv[2])

part = 0
count = 0
out = None
for msg in mailbox.mbox(source):
    if count % size == 0:
        if out is not None:
            out.flush()
            out.close()
        part += 1
        out = mailbox.mbox(f"part-{part:03d}.mbox")
    out.add(msg)
    count += 1
if out is not None:
    out.flush()
    out.close()
print(count, "messages written to", part, "files")
Tested on a 25 message sample split into parts of 10. Output was three files with 10, 10 and 5 messages.

Parts are named part-001.mbox, part-002.mbox and so on. Your original is untouched so you can try different sizes. Free disk space equal to the original is needed for the parts.

How Do You Check the Split Parts?

Add up the messages in all parts and compare the total with the original MBOX file. Our script prints the total processed while you can count separately with the listing script from our guide to opening MBOX files. Then open a few messages near the start and end of two parts, including some with attachments. Our article on checking a converted mailbox explains a fuller routine.

Which Limits Does the Splitting Script Have?

Our script splits by count only, therefore one part can be larger than another when attachment sizes vary. Folder structure is not preserved, because an MBOX file is a flat list of messages. Big inputs take time because the module processes the file in sequence.

What Happens to Attachments When You Split?

Attachments live inside their messages so splitting an MBOX file by message count places every attachment with its message. Nothing is separated. Part sizes vary as a side effect: a part with a few large attachments can be much bigger than one with thousands of short notes. If you need parts of similar file size instead, count in smaller steps and check results or split by date range using a tool that handles it.

Which Split Strategy Fits Your Archive?

StrategyGood forTrade off
Fixed message countPlain, predictable partsSizes can vary widely
By year or date rangeArchives organized by periodNeeds a tool that filters by date
By sender or labelProject based archivesNeeds filtering before splitting

The script in this article uses the first strategy for any MBOX file because it is plain and safe. Date and sender filters need extra logic and every extra rule is another chance for an error so test them on a small sample.

How Much Disk Space and Time Does Splitting Need?

Splitting creates new files while the original remains in place so you need free space about equal to the original. Time depends on your disk and the file size. Large archives on an external spinning disk can take much longer than the same file on the internal disk so copy the source to your Mac first if you can. Close other heavy apps and wait for Terminal to print the final count.

What Should You Do With the Split Parts?

Once you have numbered parts of the MBOX file, you can move them one at a time. Import the first part and check it before you continue. If an import fails, you lose only that part and you can retry it. Store the original and the parts in different places until you are sure everything arrived, since that gives you two routes back if something goes wrong.

What Is a Careful Splitting Routine?

  1. Copy the MBOX file to a disk with enough free space.
  2. Split into parts of 1,000 messages as a first test.
  3. Count the parts and add up the messages.
  4. Import the first part and open some messages.
  5. Process the rest only after the first part works.

Starting with one part feels slower, yet it catches problems while they are still small. That habit saves hours on a mailbox that took years to build.

Can MacXTools Convert the Split MBOX Files?

If the goal is to move the mail into another app, splitting is only a step. MacXTools MBOX Converter works on files directly and avoids scripting. Our guide to the MBOX format explains where these exports come from while a separate article shows how to extract attachments from an MBOX file if most of the weight comes from files.

Common Questions

Why Is My MBOX File So Large?

Attachments are stored inside the messages so a mailbox with many files grows quickly. Years of mail add up too. Any MBOX file that has grown this way benefits from splitting.

Are Attachments Separated When I Split?

No. Attachments live inside their messages so splitting an MBOX file by message count places every attachment with its message.

Can I Split an MBOX File Without Damage?

Yes, if every cut falls between messages. Python’s mailbox module follows message boundaries, unlike byte based tools.

How Many Emails Belong in One Part?

Start with about 1,000 and adjust after a test. Mailboxes with large attachments need smaller parts than plain text mail.

Is the Original MBOX File Modified?

No. Our script only opens the source and creates new parts so the original is as it was.

How Do I Know No Email Went Missing?

Add up the messages in every part and compare with the original total. Then open a sample from the start and end of every part.

How Much Free Space Do I Need to Split a Large File?

About the same as the original, because the parts are new files written beside it.

Sources

Every version, option and date above is taken from these pages and not from memory.

  1. RFC 4155, The application/mbox Media Type IETF
  2. mailbox, manipulate mailboxes in various formats, Python documentation Python Software Foundation
  3. split(1), Linux manual page man7.org