1

I would like to organize all incoming email into the following directory structure based on the date of the email:

ROOT --+-- YYYYMMDD --+-- HH --+-- mm --+-- YYYYMMDD-HHmmSS-000001
       |              |        |        |
       |              |        |        |      ....
       |              |        |        |
       |              |        |        +-- YYYYMMDD-HHmmSS-NNNNNN
       |              |        +-- mm --
       |              +-- HH --+-- mm -- 

Note that each email will be stored as a separate file and the name of the file is YYYYMMDD-HHmmss-NNNNN, where NNNNN is a running number.

Can procmail or maildrop do this? If not, what other options are there?

Thanks in advance.

kjloh
  • 11

1 Answers1

2

This can be achieved using procmail. Here is an example .procmailrc:

MAIL=$HOME/ROOT
VERBOSE=on
LOGFILE=$MAIL/procmail.log

DATE=`date +%Y%m%d`
HOUR=`date +%H`
MIN=`date +%M`
SLICE=$DATE/$HOUR/$MIN

MAILDIR=$MAIL
DEFAULT=$MAILDIR/$SLICE/

# Creates the slice if necessary.
DUMMY=`test -d $MAILDIR/$SLICE || mkdir -m 700 -p $MAILDIR/$SLICE`

Subtlety: the slash after $DEFAULT indicates Maildir format. If you prefer mbox instead, remove it.

mavam
  • 121