Using Gmail anti-spam with mutt

Posted by – 29/03/2012

OK, this is not another post on how to use Mutt and Gmail. This is just to comment on a feature I found in Mutt that was not obvious, and that helped me to stop running my own anti-spam tool.

So, for a number of reasons, my company stop filtering spams. I was setting up dspam to take over that job when I decided that it was just too much pain for a single account. Besides, although I am spammed a lot, I would never possibly be more efficient than Gmail anti-spam, given the load of emails their users classify everyday.

I am not migrating my old emails over to Gmail, though. And I am pretty comfortable with my current email work-flow… I am simply not going to use a webmail (even one as powerful as Gmail). OK, I am using GNOME 3 after being a Fluxbox and Bluetile user, but everything has a limit…

But how to keep the best of both worlds? And, more important, how to do that with minimum disruption of what I already have (my own IMAP server and Mutt managing my account there as spoolfile)? The answer is a little known trick using the “mailboxes” directive in .muttrc.

This directive accepts a fully-qualified imap mailbox address. So I just added something like:

mailboxes 'imaps://[Gmail]/Spam'

and added some shortcuts to save email from my inbox to that mailbox (the same as train-as-spam) and to rescue email from it (the same as train-as-ham):

macro index <F3> ";Wo;Wn;simaps://[Gmail]/Spam\n" "Train as SPAM"
macro index <F4> ";Wo;Wn;simaps://\n" "Train as HAM"

and that was it. In my IMAP machine I got a fetchmail downloading emails from Gmail’s INBOX so I can get trained-as-ham and new emails (all emails arrive first in my Gmail account) into my IMAP server. All my sieve rules are in place and nothing changed in my email work-flow.

It’s been working flawlessly for a week now. The only drawbacks are (1) Gmail knowing everything that arrives to me (not a big deal, since unencrypted emails aren’t private anyway), and (2) not getting the spam-count once Mutt is run: I have to change into that mailbox to log-in to Gmail.

Update: Mar 30, 2012 @ 18:15: I just found out that drawback number (2) above can be fixed by adding the following to .muttrc:

unset imap_passive

2 Comments on Using Gmail anti-spam with mutt

  1. rjc says:

    While username and password for an IMAP mailbox is needed if you’re using it from another account, a port number is only needed if you’re connecting to a server which doesn’t run the service on a standard port, i.e. 143 for IMAP and 993 for IMAPS. This makes “:993” in your config unnecessary.

    My £0.02 ;^)

    • spectra says:

      You are right, of course. I left it there since I tested it that way and it worked… I wasn’t sure if “mailboxes” accepted that syntax anyway, so I just threw in everything I could 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *