Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
This is much different than the standard Maildir layout. Are you expecting local MUAs or alternatively IMAP/POP servers to be able to understand this scheme? – EEAA Oct 14 '10 at 4:11
I won't be using a standard MUA or server. There will be an application that reads the emails, and it expects the emails to be in the directory structure and filenames described. – kjloh Oct 14 '10 at 4:45

You can get close if you first set up a cron job:

 * * * * * mkdir -p $ROOT/`date -d "now+1min" +%Y%m%d/%H/%M/`

and then use a .forward file like:

|cat >>$ROOT/`date +%Y%m%d/%H/%M/%Y%m%d-%H%M%S`

You'll end up with your messages in per-second mbox-format files. If you get multi per second, you might tag a -%N onto the date format in the .forward file to insert a nanosecond tick into the filename. If you get multiple emails per nanosecond... I can't help you :)

share|improve this answer

You could also have procmail run the command upon receipt of an email, instead of via a cron job.

share|improve this answer

Your Answer


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.