26

Specifically an Apple Mail .mbox file. I'm looking for a way to browse the emails it contains short of just importing it back into Apple Mail and cluttering up my currents emails.

I don't mind having to convert the mbox file to something else if need be.

A command line tool is also fine (preferred even).

Many thanks if anyone can help!

2
  • 2
    Give Thunderbird a go.
    – user3463
    Jul 13, 2012 at 22:47
  • I'm assuming it needs to be for/in OS X? Or would a windows or linux solution be fine?
    – Journeyman Geek
    Jul 13, 2012 at 23:54

3 Answers 3

28

OS X, like most Unix and Linux variants, has the command-line mail and mailx clients.

You can see if they will read your .mbox file. They do use mbox as one of the filenames they handle.

mail -f ~/.mbox

Use the x command to exit without changing the file.

2
  • 1
    mail is good for plain-text messages, but cumbersome for HTML and outright useless for something with a lot of embedded graphics or heavy use of HTML layout mechanisms which do not render well in a terminal.
    – tripleee
    Dec 11, 2020 at 10:27
  • +1 for x. I used q, and that transferred the mail from /var/mail/user to ~/mbox
    – wisbucky
    Jun 15, 2021 at 0:04
4

Berkeley MBOX is basically a plain-text format so you can view it simply with less, though you will need to understand SMTP and MIME to make sense of what you are looking at. Every line which matches the regular expression ^From (with a space after the four alphabetics) is the beginning of a new message. Modern email messages use various MIME transport encodings which can be anything between almost human-readable (=?utf-8?Q?Like_this?=) to completely oblique (base64).

You can use csplit on the same regex to split the file into individual messages, or use the formail utility which is part of the Procmail package with the -s option. The latter offers a number of options to enable various heuristics if the input file is not completely well-formed, etc.

For graphics-heavy email messages with potentially problematic contents (i.e. spam), I have occasionally spun up Thunderbird in a Virtualbox instance and made sure it has no access to the Internet, then imported the mailbox there for modern HTML etc rendering. If a message requires images from an external server, you just get a placeholder if the image cannot be fetched.

1
  • +1 for csplit
    – Samveen
    Sep 5, 2022 at 6:21
1

I might create a secondary user and import your file there... Easy-peasy browsing without cluttering up your account.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .