I recently needed to back up an email account before deleting it. I tried several methods for doing this and found that using one of my Ubuntu-based VPS servers I could easily set up a background task that backed everything up.
I referenced several other articles to gather the information I needed. I tried many configurations before finding one that worked for me on Ubuntu 12.10 x64.
Here are the steps:
Install fetchmail and procmail
On Ubuntu this is quick and painless with the help of apt.
apt-get install fetchmail procmail -y
Create configuration files for fetchmail and procmail
Create a .fetchmailrc file.
Edit the configuration using your favorite editor and include the following. Note that I'm connecting to GMail in this example, but the settings will vary depending upon the requirements of your email server.
mda 'usr/bin/procmail -d %T'
Note the critical mda directive which lets fetchmail know to talk to procmail to deal with email that it fetches.
Let's create a folder in the home directory to hold downloaded email. And a folder within it for this account. We'll touch a log file for logging. Also, we'll create a .procmailrc file.
mkdir -p ~/email/my_username
Edit the .procmailrc configuration using your favorite editor and include the following.
Replace my_username with the name of the folder you created to hold your downloaded email.
If everything is in place, we can fire it off and download all the email. I suggest running inside a screen so you can disconnect and walk away. In my case I was downloading several gigabytes of email. It can take a while, but it gets the job done.
fetchmail -nk -a -d 200 -N &