procmail
[Top] [All Lists]

Re: splitting up mbox with formail?

1998-08-26 00:48:52
I have a very large mailbox file with 6 months worth of messages in
it.  I would like to split this file up into 6 smaller mbox files 
based on month.

Obviously, entering the large mailbox file and manually saving each
message to the appropriate file is too tedious.  How could I use the
procmail tools to automate this task?

   cat mbox | formail -s procmail -m procmailrc

Make sure you have a procmailrc file in your directory like this:

   DIR=splitboxes
   DUMMY=`test -d $DIR || mkdir $DIR`

   :0:
   * ^FROM_MAILER
   $DIR/daemon

   :0
   * ^From.*\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Nov|Dec)[ ]+[0-9]+[ 
]+[0-9:]+[ ]+19[0-9][0-9]
   {
      FROM=$MATCH
   
      :0
      * FROM ?? ^^\/[^\t ]+
      { MONTH = $MATCH }
   
      :0
      * FROM ?? .*19\/[0-9][0-9]
      { YEAR = $MATCH }
   
      :0:
      $HOME/$DIR/$MONTH$YEAR
   }
   
   :0:
   $DIR/Unknown

Your files should show up in ./splitboxes broken up by month.  I chose to go 
with the
date in the From_ header since I *know* that it's correct; oftentimes the Date: 
header
is way off.

NOTE:  This script is NOT Y2K compliant, so there.
NOTE2: Replace \t with an actual TAB character.

Chris