From: jc@minya.UUCP (John Chambers)
Newsgroups: comp.mail.misc
Subject: Re: What is the format of a mailbox file?
Date: 8 Sep 92 02:47:03 GMT
Distribution: na

In article <1992Aug26.203046.25591@murdoch.acc.Virginia.EDU>, sdm7g@aemsun.med.Virginia.EDU (Steven D. Majewski) writes:
> 
> What is the format of a unix mailbox file and where can the 
> definition be found. ( I didn't see any pointers in the man
> page for 'mail'. )

To my knowledge, it isn't documented anywhere. This is is part because
it  depends partly on what flavor of Unix mailer you have.  The "pure"
uucp mailer (which isn't so very pure on most systems these  days  ;-)
had a very simple format back in the old days. A mail file was started
either by the start of the file or by the sequence:
   "\n\nFrom "
Note the two line feeds before the "From", and the SPACE after it. But
as  I've  noted,  there are some variant mailers that do clever things
that shoot down attempts to match on this simple string.  The most fun
are the ones that add their own headers before an existing "\n\nFrom "
byte sequence.

> How is the status of new, read, etc. indicated in the file? 

What does that mean?  You are clearly talking about some mailer  other
than the usual ones that come with Unix.  The basic Unix mailers don't
add anything but a "From " line to the start of  a  message.   But  of
course lots of add-on mail packages do all sorts of clever things with
their headers.  None of this is very portable.  Well, if you  are  the
sort  that  thinks  that the only mailers that God wants us to use are
the brand X mailers (where X mostly == Internet  in  the  BSD  world),
then  you  probably think that some particular headers are "standard".
You are in for some rude surprises when the Real World starts to  send
you mail.

> BTW: the reason for the question is that I need to write a filter
> to split/merge and generally reorganize my mailboxes. If anyone has
> any hints on a good program to do this, I'm listening. And that's why
> I've tacked 'comp.lang.perl' onto the Newsgroups line. I would expect
> someone must have done something like this in Perl, already. 

Yup; I've been doing just that. I have a little perl program that does
the  useful  task of chopping up the mailbox into mail files (and only
occasionally mistakes one message for N when some turkey  mailer  adds
headers  with  embedded blank lines followed by a "From" line ;-).  It
looks for interesting (to me) subjects and/or senders, and  does  some
appropriate  (for  me)  things when it gets a match, running vi on all
the files that don't match.  I also have a little perl program that  I
feed the headers via "!}rpl" and it generates headers for a reply. And
so on.  It's fun; everyone should try it.  You rapidly get a real feel
for how truly demented the various mailers out there can be.

The most frustrating thing about figuring out how to chop up a mailbox
file is knowing that the mail arrives in separate files, just like you
want it.  The idiots who wrote the mail packages decided to join these
files  into  one big one, eating up lots of cpu time to do so, just so
that you and I would have to write programs to try to reconstruct  the
original  separate files, eating up yet more cpu time.  If they'd just
made the "mailbox" a directory rather than a  file,  they  could  have
delivered  the mail via a link, and no chopping would be necessary.  I
keep getting tempted to write a new mailer that does it this way ...

BTW, when it reached here, it didn't have comp.lang.perl anywhere.  So
maybe you should repost it there ...

> ======== "If you have a hammer, find a nail" - George Bush,'91  =========

The nail that sticks up gets hammered down.
   -- Old Japanese saying.
-- 
All opinions Copyright (c) 1992 by John Chambers. Inquire for licensing at:
1-617-647-1813 ...!{bu.edu,harvard.edu,eddie.mit.edu,ruby.ora.com}!minya!jc 
--
Pensu tutmonde; agu loke.
Xref: sparky comp.mail.headers:295 comp.mail.uucp:1758