The BSD mailbox format has, according to Jamie Zawinski, never been formally documented (see his anti-content-length rant), and does not have, as far as I know, any formal identifiers that may be used as metadata for identifying a file to applications as being a BSD mailbox, except for the fact it has the 4-byte magic number 0x46726f6d. I'd like to know if there any conventions for identifying these mailbox files.

So far I have found:

  1. the file extension .mbox used on some sites, supported with local scripting, but because I haven't seen this used in any widely used applications, I think this doesn't count as a convention - by contrast, RFC *822 messages are often given the .eml extension, which is widely supported, including by Microsoft and Apple; and
  2. no MIME type for it: it is not in the list of IANA types, although there may be informal extended types for it.


Note that I am asking for a way of communicating that a file is a BSD mailbox file, not a recogniser for them. And note also that a recogniser for BSD mailbox files that is not sure to reject mailbox files that use the Content-Length encoding is a dangerous thing, for the reasons Jamie gives in the link above: the same file might represent completely different sequences of email messages under the two schemes.

  • The 0x46726f6d is not really a magic number, but the first four bytes of the string '^From ' with which the mailbox should start (as per the rant). Not even the file command recognises such files (it doesn't seem to have a pattern for BSD mailbox at all). – Anthon Mar 4 '14 at 11:28

I would use fuzzy heuristics to determine if a file is a mbox file. For example, here's an AWK script:

ls -F | awk '{
    if($0 !~ /\//){
        getline first < $0; 
        if(first ~ /^From .*@/){
            print $0 " is a mbox file"

Since getline kills an AWK script should there be an issue opening a file, we use the -F argument to ls to add a / at the end of directories. The $0 !~ /\// check makes sure to not open any name with a slash in it. We then read the first line of the file, putting it in the variable first.

Now we're ready to do a fuzzy heuristic check for a mbox file. If the first line of a file begins with "From" and then has an @ somewhere in the first line, we report that the file is a BSD mbox file.

And, yes, maildirs are a better idea (as long as you have enough inodes to store a bunch of small files) because they are more reliable than BSD mbox files, and because we don't have to do that ugly workaround much maligned in "The UNIX Haters Handbook" of needing to add a '>' before a line that begins "From".

  • 1
    I agree that this kind of heuristic is good for figuring out if a file is a BSD mailbox: additionally, I'd want to see at least three LF-terminated lines in the file, with the 2nd line resembling an rfc822-style header or its first line. But here I'm interested in something else: finding out if there are conventions for saying that a file is a BSD mailbox – Charles Stewart Mar 5 '14 at 11:00
  • As JWZ pointed out, the format is widely used but nowhere documented. His suggestion to look for only '^From ' on the first line is as close to a official standard for BSD mailboxes (Some old Usenet readers didn't put an @ in first line when saving an article as a BSD mbox) – samiam Mar 6 '14 at 3:27
  • samiam: I've updated the question to say why I don't want a recogniser but a metadata representation. – Charles Stewart Mar 7 '14 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.