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.

  • 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

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

| improve this answer | |

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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