How Fetchmail (and Mutt) Saved Me From Email Mediocrity.

9 08 2009

I’ve always had an ambivalent relationship with email. I used pine in college, but since then, it’s been mostly windows (and windows flavored) email clients.

At the start of my career, it was Outlook. Outlook could read email, but it’s primary feature seemed to be this calendaring thing. Largely it seemed to schedule meetings for me at the busiest times of day, and then canceled them at the last minute. It was easily thwarted by scheduling all day events or just ignoring it altogether.

When Thunderbird stabilized (it’s name; Minotaur? Pbbbbttt!) I decided to switch to that. It also read mail, but had two important features over Outlook. A mediocre feed reader, and not-being-Outlook.

I’ve been using Thunderbird ever since then, though I’ve occasionally tried other clients. Evolution was pretty good. It read mail and integrated with Gnome. It also had this crash-to-desktop feature that I could live without, so I went back to Thunderbird.

At the end of the day, these were all just windows-y applications. You claw at the screen with your mouse all day, dragging little sprite mails into little sprite folders. Configuration is a clicky-clicky exercise of navigating annoying menu tress to overcrowded little dialogs. Setting up one mail box, complete with filtering and signature wiz-bang, is just annoying. Setting up two or three? Even more so.

Why is it so annoying? Why can’t I grab the email from all my accounts and sort it into one set of folders? Why isn’t there a simple text file configuration for all this?

With those thoughts in mind, I started looking for the next great mail client. But in one of the first blogs I read, I stumbled across the magic words: ‘Fetchmail’ and ‘Maildirs’. *HEAD SLAP*

I feel the need to take a short Yegge here to defend my nerd cred.

Please understand that I spent most of my early career on Windows machines. My first programming job was at a VB6 shop.

Windows and Windows applications seem to have a general approach to users that says “Here, let me do that for you, before you break something.” Like how I take the TV remote from my mother when she’s about to “switch it over to DVD”.

Windows says “here, let me install that for you”. Or “here, let me scour the network for printers so all you need to do is pick one from a list” Or, everyone’s favorite, “you seem to be having trouble with that letter. Why don’t we turn it over to this anthropomorphic, animated paper clip. We think he can do it without spilling coffee on the keyboard.”

The point here is not to turn this into a “Windows makes you stupid” rant. The point is, that after years of that learned helplessness, I still sometimes have trouble getting in tune with the Tao of Linux. But I’ve got it now. I still get to be in the nerd club, right? We cool, right?

End Yegge.

So where was I? Oh yeah, ‘Fetchmail’ *SLAP*

Fetchmail is super easy to install and setup. I wish someone had told me about this before.

*Note: All my steps are Ubuntu flavored*

$ sudo apt-get install fetchmail fetchmailconf

I installed fetchmailconf. It was kind of crappy, but it helped me get the global settings configured. After that, I just edited the run control file myself.

So here’s what my ~/.fetchmailrc looks like (sorta)

# Configuration by fetchmailconf
set postmaster "my_username"
set bouncemail
set no spambounce
set properties ""

# don't keep on server because it's my hotmail account and who cares
poll with proto POP3
       user '' there with password 'secret' is 'my_username' here options ssl

# keep, just because (see, it's IMAP)
poll with proto IMAP
       user '' there with password 'secret' is 'my_username' here options keep ssl

# no keep. gmail is configured to archive after pop access.
poll with proto POP3
       user '' there with password 'secret' is 'my_username' here options ssl

mda "/usr/bin/maildrop"

This configures fetchmail to pull from three different accounts and deliver all the mail to me. The line that starts with ‘mda’ tells fetchmail not to bother going to port 25, just hand it off to a program called maildrop.

Oh, yeah, I also installed maildrop

$ sudo apt-get install maildrop

Maildrop is what actually sorts the mail. It uses a file called ~/.mailfilter to decide where to deliver the mail. This file contains the the regular expressions that decide what mail folder to deliver a message to.


logfile "$HOME/maildrop.log"

if (/^(To|Cc|Bcc):.*user@work/)
  to $WORK

if (/^X-Apparently-To:.*trisano-dev/)

if (/^(To|Cc|Bcc|Delivered-To):(.*user@hot|.*user@gmail)/)
  to $PLAY


This is an example of a ~/.mailfilter file based on my first attempt. It sets up a default folder for mail. In this case, I’m using the Maildirs format, which I prefer over a single spoolfile. This file also specifies a few subfolders and uses simple regular expressions to decide which folder(s) to deliver a message to.

The regular expressions, by the way, are applied against the entire message, including the headers. So the expression /^X-Apparently-To:.*trisano-dev/, looks for a line starting with the header X-Apparently-To (an awesome header) and then the word trisano-dev (a google groups mailing list, in this case) anywhere else on the line. If it finds a match, it drops that message in the $TRISANO folder.

To make this work, I needed to create the maildirs folders. A utility installs with maildrop that takes care of that. I ran maildirmake once for each folder.

$ maildirmake ~/Maildir
$ maildirmake ~/Maildir/.Trisano
$ maildirmake ~/Maildir/.Play
$ maildirmake ~/Maildir/.Work

While I was getting set up, I ran fetchmail from the command line. Some of the early runs took a while because I had a lot of email laying around on servers.

Once everything worked, I set up cron to run fetchmail every few minutes. I actually use gnome-schedule for that, which is handy, because I don’t speak fluent cron.

$ sudo apt-get install gnome-schedule

Well, I have nicely filtered messages going into my new maildirs. Problem is, Thunderbird can’t read maildirs. But that’s OK, because I was tired of Thunderbird anyway (isn’t that how all this got started?).

I was looking for a nice emacs mail client to use long term but, by happy coincidence, eggyknap was chatting up Mutt in IRC one day, so I decided to give it a try.

$ sudo apt-get install mutt

A simple Mutt configuration looks like this (in ~/.muttrc)

set mbox_type=Maildir

set realname='Ryan L. Bell'

set folder="~/Maildir"
set mask="!^\\.[^.]"
set mbox="~/Maildir"
set record="+.Sent"
set postponed="+.Drafts"
set spoolfile="~/Maildir"
set signature="~/.sig"
set sort=threads

This tells Mutt I’m using Maildirs and that my ~/Maildir folder should be opened by default. It also tells Mutt what folders to use for Sent messages and saving email Drafts. These folders will be in Maildir format, but Mutt handles creating them, so Bob’s your uncle.

The last two lines tell Mutt which signature file to use for outgoing messages, and tells Mutt to sort using threads, by default.

I didn’t think I could face a sendmail configuration, so for simplicity’s sake, I just have Mutt talking directly to my smtp server. One day I may try using Lamson for this. We’ll see.

Again, from the ~/.muttrc file:

# Outgoing
set smtp_url="smtp://"
set smtp_pass="secret"

Next, I set up Mutt to know about all my maildirs. This was not strictly necessary, but it makes navigating between folders in Mutt much more pleasant.

# Mailboxes
mailboxes "=.Play"
mailboxes "=.Work"
mailboxes "=.Trisano"
mailboxes "=.Sent"
mailboxes "=.Drafts"

The last things I added to my mutt configuration were these folder hooks.

# Folder hooks
folder-hook .*Play    set from=""
folder-hook .*Play    set signature="~/.sig"

folder-hook .*Work    set from=""
folder-hook .*Work    set signature="~/.sig-work"

folder-hook .*Trisano set from=""
folder-hook .*Trisano set signature="~/.sig-work"

These hooks set my Reply-To header and signature file based on what folder I am in.

This barely scratches the surface of what you can configure Mutt to do. I’ve included a link to the Mutt configuration page in the links section.

Now I have exactly the email configuration I desired. I can control my mail filtering with regular expressions and a simple text file. I can grab mail from all my accounts and sort it into a simple set of folders. With Mutt, I have plenty of hooks to change the behavior of the client to suit my needs. I can even modify the message headers when a message is sent.

So what will I do with all this new found power and control? Who knows? But it won’t be boring.

Whew! Ran a little long this time. I guess I’ve been storing up some blogging action points. As always, corrections, additions, and enhancements are always welcome in the comments.


Run IE in VirtualBox

20 01 2009

I tweeted this earlier today, but decided to blog it too. Here is an excellent screen cast on running IE (well, Windows too) in VirtualBox. Since the vhd’s are from Windows, and for the express purpose of cross browser testing, I’m assuming everything is above board.

A couple of notes: The screen cast is for OS X, but everything worked fine on Ubuntu. I just did a couple of things differently. I used wine to extract the exe’s, rather then 7zip. I also received a funky error from VirtualBox when I tried to run the image, but the error description told me exactly how to fix it.

The last thing I’ll note is that many comenters had problems w/ VirtualBox 2.1.0, so stick to 2.0.6.

Run Skype on Ubuntu 8.04

13 01 2009

I’ve had Skype working on Ubuntu for a while, but I thought I’d blog it so it would be easier to find if I had to do it again.

To get Skype, I just downloaded the Ubuntu bundle from Skype’s site. Or you can go and checkout their other linux downloads.

For the record, I was not having trouble making calls. Once I was on a call, dialing numbers produced funny echo sounds on the line. This made it impossible to participate in conference calls because I couldn’t navigate phone trees.

Here’s how I fixed it:

Get the pulseaudio-utils.

sudo apt-get install pulseaudio-utils

Then, run skype through padsp.

padsp skype

That is all.


14 10 2007

I hadn’t seen this before. A GNU/Linux Phone. Here’s one running Squeak.


11 07 2006

Some how tos for Linux.

Bind ALPs Touchpad to a Static Device

6 07 2006

For Linux users.

I was able to get my laptop’s touchpad working with minimal fuss. I installed the synaptics driver, qsynaptics, and configured the touchpad in /etc/X11/xorg.conf on event3. I thought everything was golden. Then I noticed that sometimes the scroll buttons on the touchpad wouldn’t work after rebooting. A ‘cat /proc/bus/input/devices’ determined that my touchpad was now bound to event2 (or sometimes event4). The touchpad binds at load time to whatever event is available. So how do you get it to bind to the same device every time?

Turns out the solution is pretty simple (not Windows simple, but still simple). You need to create a udev rule that creates a link to whatever event the touchpad binds to (call it, /dev/input/alps, for example). Then configure xorg.conf to use that link, instead of the event.


23 06 2006

I tried installing the latest release of Ubuntu (or, more specifically, Kubuntu) and I’m really happy with it. For a Linux distribution, the hardware detection is second to none. It found and installed the correct drivers for my video card and my wireless NIC without any input from me. That’s huge, because I’ve always wasted a lot of time getting those things working. I also got pptp working without any hassles. My system is in better shape then I ever had it with Gentoo and I haven’t had to compile anything.