0

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
  • 117
  • 2
  • 4
  • 7
  • 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 04: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 04:45

2 Answers2

0

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 :)

pjz
  • 10,595
  • 1
  • 32
  • 40
0

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

AMB
  • 1