Geekblok

B10m, BOK, Joffie - old geeks on a blog

Entries Comments



Managing e-mails

22 October, 2007 (10:51) | emails, technical | By: B10m

Many people face the problem of handling e-mails efficiently. There is no right or wrong way to handle e-mail, but some methods just are a little easier to work with than others.

A lot of people ask me how I handle all my e-mails. In this post I’ll describe my setup. It’s far from perfect, but for me it works and it might work for you too.

I’m a Linux geek, so I use a CLI mail agent, named mutt. This simple yet powerful piece of software is wisely described as:

All mail clients suck. This one just sucks less.

As funny as it might sound, it’s true. After using PINE for a long time, I’ve switched to mutt and never looked back. The interface is powerful and it does close to everything you’d want your mail client to do. Other things, like filtering the mail, I do with a custom script using Mail::Audit (yes, I should use Email::Filter). I prefer a custom Perl script over procmail for I have difficulty grasping the procmail way of writing filters and rules. It just seems too complicated to me. Mail::Audit is a lot more simple, as we’ll see in a minute.

Ok, now that we know the tools we’re working with, let’s look at how I hook it all up.

First of all, I needed to define what exactly I wanted to achieve. In my case, I made a few rules:

  1. my “inbox” should remain as clean as possible
  2. I should be able to retrieve emails from the past as fast as possible
  3. both received and sent mails should be easy to retrieve

These rules made me think of a setup like this for incoming mail:

incoming_mail.png

Mail coming from the evil internet, is being parsed by the Mail::Audit script and stored in two locations. The inbox of mutt (in my case /var/mail/$username) and directly archived. This way, I can keep my inbox clean. When I’m done with the e-mail (read: replied), I can delete it, keeping my inbox clean (woohoo, rule 1 accomplished!).

Since the mails are directly archived, I can retrieve them fairly easy with tools like grepmail (yes, Joffie, a simple grep will also do, but this is a little nicer ;-)
So, rule 2 has been accomplished too. Not only can I keep my inbox clean by deleting mail, I can also retrieve messages “from the past”. I chose to keep the e-mails archived by month, instead of one huge archive (file), for it’ll speed up queries (usually you know at least the year and often remember the month of the message you’re looking for).

The code responsible for this:

#!/usr/bin/perl

use strict;
use Mail::Audit;
my $mail = Mail::Audit->new(
emergency => "~/mail/backup/emergency_mbox"
);

#------------------------------------------------------------------------------#
# Backup
#   Reason: always good

$mail->noexit(1);
$mail->accept("/home/$username/mail/backup/%Y-%m.mail",
{ interpolate_strftime => 1 });
$mail->noexit(0);

#------------------------------------------------------------------------------#
# Accept
#   Reason: we want to read emails

$mail->accept;

As you can see, I use interpolate_strftime here to specify the archive by month. For this month, the email would now be copied to “/home/$username/mail/backup/2007-10.mail”, exactly what I wanted.

Now there’s only one rule we haven’t covered yet: “both received and sent mails should be easy to retrieve”.

Since we already automatically create the archives, it’d be nice if mutt could write the sent messages to the same archive. That way, we can see the full threads of mails, instead of only seeing received mail in one place and sent mail in the other. So just tell mutt to write to the same locations in your ~/.muttrc:

set folder="~/mail"
set record=+backup/`date +%Y-%m`.mail

The “set folder” specifies where your mailboxes are located. The “set record” line uses this and adds “backup/” and the current year-month, in the same manner as we’ve seen above.

All set, now both your incoming mails and outgoing mails are automatically archived in one spot, making it easy to search and find them again. By doing this, you can actually delete mails from your inbox, making it easier and faster to read new e-mails.

The only drawback is that you will have to restart your mutt session every month, for the file name is only calculated when you start up mutt. To me that was a little annoying (I always keep my mutt open in a terminal), but oh well, big deal! ;-)

Comments

Comment from Joffie
Time: October 22, 2007, 2:11 pm

Thanks for the hints. I’ll remain using procmail, but now with the recipe:

BACKUP=$MAILDIR/backup
TODAY=`date +%Y-%m`

:0 c:
$BACKUP/$TODAY.mail

And I installed grepmail too.

Comment from Blom
Time: October 22, 2007, 2:14 pm

You’re free to choose the tools you want (and I know you already have quite a massive list of procmail recipes ;-)

grepm is a little wrapper around grepmail, aimed at mutt users. You might like that too.

Comment from BOK
Time: October 22, 2007, 9:37 pm

C’mon, THREE systems for keeping your email organized?! Well, if it makes you happy…
I’d rather get rid of most emails once they’ve lost their value (sort of, like being read or orders delivered). The rest is stored in folders on my IMAP-server (Dovecot), so I can access all of it from everywhere, whether using mutt, Thunderbird, Roundcube-webmail or the CLI.

Different programs can be used for backup-purposes like Unix-scripts or IMAPSize (http://www.broobles.com/imapsize/index.php) for Win32.

Just my $0,02 :-)

Comment from Blom
Time: October 22, 2007, 9:45 pm

I’m not using three systems. I’m using a procmail like filtering system (most likely you use filters in Thunderbird or something similar aswell) and I use mutt, a mail client ;-)

Glad you’re happy with your IMAP setup. I would just like to see you search for a specific mail (IMAP sucks for searching). Then again, you don’t save e-mails for that long, so it’ll probably go rather fast…

But like I said. My setup is far from perfect. It does, however, satisfy my three needs (keep a clean “inbox”, fast search and incoming/outgoing mail in one archive, not two, so threads of mail can be retrieved).

Write a comment





Preview: