Automatically archiving old email

If you like me host your own email server for privacy reasons you will surely notice that your mailbox will grow quite large after some time. Luckily there’s a very convenient program - archivemail - that easily solves this problem for us. Email messages are compressed very well considering it is all text. There is some precious disk space to save (about 70-80 percent reduction in size for text files).

It is easy to setup in Debian, or any other distribution:

sudo apt-get install archivemail

After installing the program you invoke it with the mailbox locations as the arguments. To compress and archive emails in the Archive and Sent folders in a standard mailbox structure:

archivemail $HOME/mail/Archive $HOME/mail/Sent

This will archive any emails older than 180 days and compress them using gzip.

The number of days (default 180) can be changed by passing the parameter -d according to the man page:

-d NUM, --days=NUM
           Archive messages older than NUM days. The default is 180\. This option is incompatible with the --date option below.

To automatically archive old email messages you simply add it to your crontab (make sure you pipe any output to /dev/null unless you want to get bombarded with messages):

0 2 * * sun archivemail $HOME/mail/Archive $HOME/mail/Sent &> /dev/null