Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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