Over time, people tend to accumulate a large number of messages in various email accounts, most of which they never bother with again. The problem is particularly acute for administrator accounts that receive routine notifications of events that are viewed, if at all, no more than once. The archivemail tool lets you easily archive these old messages and thereby free up some disk space and improve your mail client's performance.
Archivemail is available from the software repositories for most distribution, and you can also install it from the source tarball. If you visit the archivemail Web site, you'll notice is the most recent version, archivemail-0.7.2, is a year old, but the project is by no means dead. A version with new features, bug fixes, and cleaner code is in the works, according to the developers.
Archivemail supports IMAP, mbox, MH, and Maildir format mailboxes. You need to know the exact path of your mailbox to work with archivemail. If you use the Evolution mail client, the mailbox will be in the ~/.evolution/mail/local/Inbox.sbd/ directory; Thunderbird stores it under ~/.mozilla-thunderbird. The location of the mailbox depends on the mail client and configuration. Many email clients keep the mailbox in the users' home directory. You will have to specify the complete path to your mailbox when using archivemail. If you only enter the mailbox name, archivemail assumes the mailbox is in the current directory.
When you point archivemail to your mailbox it will automatically archive all messages older than 180 days by default. You can change this period with the
-d command option. The syntax to using archivemail is
archivemail optionsmailbox. So, for instance, the command
archivemail -d 40 trip creates a trip_archive.gz file that contains messages from the trip mailbox that are older than 40 days. The messages are removed from the mailbox into the compressed archive.
In addition to specifying the number of days, you can use the
-D argument to specify dates. For example, to archive messages older than July 4, 2008, in the trip mailbox, use the command
archivemail -D '4 Jul 2008' trip.
You can specify the date as I did in the example above, or as '2008-07-04' or as '4 July 2008'. Put the date in quotes and type in the full year, since archivemail doesn't accept two-digit years. If you're unsure of any of the command-line options, you can run archivemail with the
-n command option. With
-n, instead of writing the changes to the files, archivemail informs you what it would have done. When I tell archivemail to archive messages older than 20 October with the dry-run option, I get the message:
I would have archived 9 of 16 message(s) (1.2MB of 2.0MB) in 0.0 seconds
By default, archivemail creates the archive in the same directory as the mailbox, but you can specify a destination for the archive using the
archivemail -d 90 -o ~/mail-archives/ trip archives all messages older than 90 days under the ~/mail-archives/ directory. archivemail complains if it can't find the destination directory, so create the new directory beforehand.
Archivemail offers some clever additional options, such as the ability to ignore unread messages in the mailbox, archiving a message only if it's over a specified size limit, and storing your messages in uncompressed archives.
-u option tells archivemail to ignore unread messages in your mailbox.
To archive large messages, use the
-S option. The command
archivemail -d 60 -S 2 trip will archive all messages larger than 2MB in size that are more than 60 days old.
If instead of archiving you wish to delete old messages, you can do that with the
--delete option. The following command will delete all messages older than 120 days:
archivemail -d 120 --delete trip. To delete all messages larger than 5MB in size, use the command
archivemail -S 5 --delete trip.
You can use the aptly named
--no-compress option if you wish to keep your messages in an uncompressed archive.
By default, archivemail compresses the archives and names each archive file mailbox_archive.gz. With the
-s option, archivemail can append the weekday name, month name, and year to the name of the archive. For example, to archive all messages older than January 1, 2008, and name the archive trip_2007.gz, use the command
archivemail -D '1 Jan 2008' -s _%Y trip. Refer to the man page for information on how to append other information to the name of the archive.
Of course, you can create a cronjob for archivemail to automate the process of archiving or deleting old messages. To create a monthly archive of your system messages, you can add an entry like this to crontab:
With that command, messages more than 10 days old will be archived on the first of every month.
Archivemail is a simple tool that does its job well. It offers a nice selection of parameters with which you can select messages, makes it easy to archive and delete messages, and does its job quickly and well. Archivemail meets an obvious need in mail management.