This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new!

Feature: Tools & Utilities

Tidy up your mailboxes with Archivemail

By Shashank Sharma on November 13, 2008 (9:00:00 AM)

Share    Print    Comments   

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 options mailbox. 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:

$ archivemail -D '20 Oct 2008' -n trip: trip: 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 -o option: 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.

Smart options

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.

The -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:

0 0 1 * * archivemail -d10 /var/spool/mail/username

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.

Shashank Sharma specializes in writing about free and open source software for new users and moderates the forum boards. He is the coauthor of Beginning Fedora, published by Apress.

Share    Print    Comments   


on Tidy up your mailboxes with Archivemail

Note: Comments are owned by the poster. We are not responsible for their content.

Tidy up your mailboxes with Archivemail

Posted by: Anonymous [ip:] on November 13, 2008 05:16 PM
Thanks for this. I haven't tried it yet but I've been looking for something like this for ages...


Tidy up your mailboxes with Archivemail

Posted by: Anonymous [ip:] on November 13, 2008 06:01 PM
It's all great and all but how do you restore messages from that archive? There is a way, is there?


Tidy up your mailboxes with Archivemail

Posted by: Anonymous [ip:] on November 13, 2008 06:25 PM
I found this [1] tutorial a while back and use it for all my users. This archiving tool doesn't save space, but just moves things out of INBOX (I also use it to auto delete their junk mail after 31 days) into a sub-folder thus keeping their inbox fast and efficient.
I think some kind of tool that goes through and looks for attachments in emails and replaces them with a gzip'ed version after a certain number of days would be handy also.



This story has been archived. Comments can no longer be posted.

Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya