Convert MBOX to CSV on Mac

How MBOX to CSV conversion on a Mac works, what it keeps and loses, how to check the CSV opens cleanly in a spreadsheet, and when to keep the original mail format.

Turning an MBOX mailbox into a CSV file on a Mac is useful when you need email in rows and columns: sender, recipients, date, subject and perhaps the message text. That suits sorting, filtering, counting or importing into another system. It is not a faithful copy of the mailbox. This review covers what the conversion changes, where it tends to break, and how to check whether the result is good enough for your purpose. No specific converter apps were tested for this article, so it describes the format and the process rather than ranking products.

Is converting MBOX to CSV right for your use?

Conversion is a good fit when you want to analyse email as data. Examples include listing who wrote to an address over a period, building a contact or correspondence log, auditing subject lines, or feeding message metadata into another tool. The benefit is that every message becomes one row you can sort and filter in Numbers, Excel or a database.

The tradeoff that decides most cases is that CSV is flat text. It has no place for attachments, inline images, HTML formatting, the MIME structure of a message or most of its headers. A conversion keeps the fields you choose and drops the rest.

Keep the mail in its original form, either as the MBOX file or as individual EML or plain-text messages, if you need any of the following:

  • Full messages for reading, archiving or legal or compliance purposes, where fidelity matters more than structure.
  • Attachments.
  • The ability to re-import the mail into a mail client later.
  • A readable record that someone can work through in order, rather than scanning spreadsheet cells.
  • In these cases a CSV can still serve as an index alongside the original, but it should not replace it.

What the conversion actually changes

The terms involved are often used loosely, so it helps to be precise. An MBOX file is a single text file in which messages are stored one after another. Each message starts with a separator line beginning with "From ". Several variants exist, such as mboxo and mboxrd, and they differ in how body lines that themselves start with "From " are escaped.

When Apple Mail exports a mailbox, it produces a folder whose name ends in .mbox. Inside that folder is a file named mbox, which holds the messages. In Finder you can reach it with Show Package Contents. Gmail's Takeout export and Thunderbird's local folders also use MBOX-style files, but individual files may follow different variants.

Converting to CSV is not a change of display. It is a parsing and flattening step that rewrites the stored characters. A typical converter:

  • Splits the file into individual messages using the separator lines.
  • Reads selected headers, usually Date, From, To, Cc, Subject and Message-ID, and puts each into a column.
  • Decodes encoded headers. A subject stored as an encoded word such as =?UTF-8?B?...?= becomes readable text in the CSV.
  • Decodes the message body from its transfer encoding, such as quoted-printable or base64, and picks one text part. Usually this is the plain-text part, or HTML if no plain-text part exists.
  • Writes everything as delimited text, wrapping fields in quotes when they contain commas, quote marks or line breaks. Quote marks inside a field are doubled, as described in the common CSV convention, RFC 4180.

Because the characters themselves change, the CSV cannot be turned back into the original messages. Decoding is one-way in practice. Anything the converter did not select, such as attachments, alternative body parts or routing headers, is simply absent from the output.

CSV and TSV differ only in the delimiter: a comma or a tab. TSV can look tidier for short metadata. However, many tools that read TSV do not apply quoting rules, so a tab or line break inside a message body can shift columns. For anything that includes message text, quoted CSV is usually the safer choice.

Element in MBOX | Typical CSV result
Date header | Text column; may be kept as-is or reformatted, which affects sorting
From, To, Cc | Text columns; multiple recipients end up in one cell
Subject | Text column, decoded from encoded words if the tool supports it
Plain-text body | One cell, often multi-line
HTML-only body | Raw HTML in a cell, or stripped text, depending on the tool
Attachments and inline images | Omitted, or reduced to a filename list at best
Other headers and MIME structure | Omitted unless specifically mapped

A transparent way to do it on a Mac

If Python 3 is available on your Mac, its standard library includes modules for reading MBOX files and writing CSV, so no third-party tool needs to see your mail. Recent macOS versions may offer to install Apple's command line developer tools the first time you run python3.
The script below is a starting point, not a tested product:
• It reads a file named mbox.
• It keeps the first plain-text part of each message.
• It writes UTF-8 with a byte-order mark, which helps some spreadsheet apps recognise the encoding.
• It puts an apostrophe in front of cells that begin with characters a spreadsheet might treat as a formula.
That last step changes the stored text slightly. Remove the safe() wrapper if the CSV is going into a system that is not a spreadsheet. Always run the script on a copy of the mailbox.

import csv
import mailbox
from email.header import decode_header, make_header
from email.utils import parsedate_to_datetime

def text(value):
    if value is None:
        return ""
    try:
        return str(make_header(decode_header(value)))
    except Exception:
        return str(value)

def body(msg):
    part = None
    if msg.is_multipart():
        for p in msg.walk():
            if p.get_content_type() == "text/plain" and not p.get_filename():
                part = p
                break
    elif msg.get_content_maintype() == "text":
        part = msg
    if part is None:
        return ""
    payload = part.get_payload(decode=True) or b""
    charset = part.get_content_charset() or "utf-8"
    try:
        return payload.decode(charset, errors="replace")
    except LookupError:
        return payload.decode("utf-8", errors="replace")

def iso_date(value):
    try:
        return parsedate_to_datetime(value).isoformat()
    except (TypeError, ValueError):
        return ""

def safe(cell):
    return "'" + cell if cell[:1] in ("=", "+", "-", "@") else cell

with open("messages.csv", "w", newline="", encoding="utf-8-sig") as f:
    w = csv.writer(f)
    w.writerow(["date_raw", "date_iso", "from", "to", "cc", "subject", "message_id", "body"])
    for msg in mailbox.mbox("mbox", create=False):
        row = [
            text(msg["Date"]),
            iso_date(msg["Date"]),
            text(msg["From"]),
            text(msg["To"]),
            text(msg["Cc"]),
            text(msg["Subject"]),
            text(msg["Message-ID"]),
            body(msg),
        ]
        w.writerow([safe(c) for c in row])

Known limits of this script:
• Messages that contain only HTML produce an empty body column.
• Attachments are ignored.
• Malformed dates leave the ISO column blank, though the raw date is still kept.
GUI converter apps for macOS do the same basic job with a point-and-click interface. Judge them on the points in the checklist further down. A tool's appearance or marketing wording does not tell you whether it processes mail locally or uploads it. Check its documentation or privacy policy, or test it with network access monitored, before giving it real mail.

Will the CSV stay readable and usable after you share it?

Most problems show up when the CSV is opened somewhere else, not during conversion. The main ones to check are listed below.

  • Character encoding: if a spreadsheet app reads a UTF-8 file under another encoding, accented letters and non-Latin scripts turn into garbled symbols. Writing a byte-order mark often helps. Using the app's text import option and choosing UTF-8 explicitly is more reliable than double-clicking the file.
  • Multi-line cells: message bodies contain line breaks. Correctly quoted CSV handles this, but an app or script that splits on line breaks without honouring quotes will break rows apart.
  • Cell size: Microsoft documents a limit of 32,767 characters per Excel cell, so very long bodies can be cut off in Excel. Other apps have their own limits.
  • Formula injection: cells beginning with =, +, - or @ may be interpreted as formulas when opened in a spreadsheet. Treat CSVs built from untrusted mail with care.
  • Dates: a raw Date header sorts as text, not chronologically. An ISO-format column sorts correctly, but only for dates that parsed successfully.
  • Copying and pasting: a cell copied out of a spreadsheet pastes as plain text. Long bodies lose their visual line structure in many destinations.

For accessibility, a CSV opened in a spreadsheet is presented as a grid. That works well for short metadata columns that assistive technology can move through cell by cell. It works less well for long message bodies packed into single cells, where reading order within the cell and navigation depend on the app. No screen reader or spreadsheet combination was tested for this article. If people using assistive technology will rely on the output, test with their actual setup. Also consider giving them plain-text or EML copies of the messages, with the CSV used only as an index.

Checks before you rely on the result

  • Compare message counts. Counting lines that begin with "From " in the mbox file, for example with grep -c '^From ' mbox in Terminal, gives a rough figure to compare with the CSV row count. Escaping differences between MBOX variants or malformed files can make this count imperfect.
  • Open the CSV through your spreadsheet's import option and confirm that columns line up all the way to the last row.
  • Spot-check a message with a non-English subject, one with an attachment, one that is HTML-only and one with a long multi-line body.
  • Confirm that dates sort in the order you expect.
  • If a third-party tool is involved, confirm where processing happens before using real data.

Gaps in this review

No specific Mac converter apps, prices, version numbers or performance figures were available or tested, so none are recommended or compared. The script above follows documented Python standard-library behaviour, but it has not been run against a range of real mailboxes. The notes on spreadsheet and assistive-technology behaviour are general cautions, not results from a scoped test. Treat any product claim you find elsewhere, including claims about privacy, speed or attachment handling, as unverified until you have checked it against your own sample data.