Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. 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  
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
add comment

2 Answers

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
add comment

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

share|improve this answer
add comment

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.