Maildir auto-archive

GPLv3
If you’ve got your mail sitting on some server and in Maildir format, and you’ve used Outlook’s “Auto Archive” feature, you might wish that your inbox (and subdirectory contents) could be automatically swept clean of items older than, say, 3 weeks, and shoved into a Year/Quarter sub folder (like “Inbox/2008/Q1/”).

A couple years ago I wanted this too. So I wrote a cronjob and perl script to make this happen.

Installation is straightforward:

  1. Copy the shell script that cron calls, autoarchive, and the perl script, autoarchive.pl, onto the server holding your Maildir.
  2. Edit the autoarchive shellscript to make sure the path and –max-days is ok with you.
  3. Make both scripts executable with chmod u+x
  4. Make a backup of your mail. This is GPL code. No warranty is implied. Read the code and try it out with –dry-run first.
  5. Calling autoarchive.pl with the “–dry-run” option will let you make sure it’s doing what you want it to do. If it does, delete the dry-run.
  6. Wire it up to cron with something like:
    PATH=$HOME/bin:/usr/bin:/bin
    42 10 * * * autoarchive > /dev/null