Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. 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
add comment

2 Answers 2

I don't have an answer fulfilling all of what you want but a part of it. If it is sufficient to use the date at which the mail arrives instead of the date header of the mail itself and if one folder per date is also sufficient, you can do this with maildrop:

DEFAULT="$HOME/Maildir"
MAIL = "$HOME/Maildir"
DAY = `date +%d`
MONTH = `date +%m`
YEAR = `date +%y`
ARCHIVEFOLDER = $YEAR$MONTH$DATE
`test -d $MAIL/.$ARCHIVEFOLDER`
if ( $RETURNCODE != 0 )
{
`maildirmake -f $ARCHIVEFOLDER $MAIL`
}
# logfile "/tmp/maildrop"
# log $MAIL/.$SPAMORDNER
to $MAIL/.$ARCHIVEFOLDER
}

I hope you can build up on this.

share|improve this answer
add comment

If you know some Python it should be a rather trivial exercise:

Python comes with an email package in the standardlib that allows your to read the emails from text files and automatically parse them into usable objects. After having parsed them you could just output them accordingly (each message has an "as_string" method).

The basic structure would be like this:

  1. Iterate over your files
  2. Open each file and parse into an email object
  3. take the date and split it into the fields you need
  4. open the target file handle (running number is last number+1 or 1)
  5. write msg.as_string() to the file
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.