Searching for Signal

the n01se blog

Scratching the mutt, part 2: Patch and configuration

This is part 2 of a series that started here.

Before jumping into the patch and configuration details for using sendbox, let's take one step back and review the reasons for sending via IMAP. Sending email via IMAP gets mixed reviews in the community because it is non-standard, seldom supported by mail user agents (such as mutt), and supported by few IMAP servers (I'm only aware of Courier IMAP). The argument is that mail should be sent via SMTP and received via IMAP, and isn't that good enough?

I think there are good reasons to consider using IMAP for sending:

  • only a single connection to the server needed
  • avoid reconfiguring the local MTA to use the appropriate outgoing SMTP server to match my From address
  • avoid messing with SMTP-AUTH
  • avoid sending the message twice over the wire, i.e. once over SMTP and once over IMAP to put it in the "sent" folder
  • works well for offline situations, don't need to cook up separate offline methods for both IMAP and SMTP

For me, these reasons trump the naysayers' arguments. Overall, sending email via IMAP is more elegant than splitting the operations between IMAP and SMTP, and elegance in software attracts me irresistably.

Let's start with the patch then talk about configuration details to make use of it. After all, the patch introduces latent functionality that won't take effect unless you change your configuration. But configuration is useless without the patch.

Obtaining a patched mutt

Here are three options for obtaining a patched mutt:

  • If you're on Gentoo, use mercurial to fetch the n01se.net overlay and use emerge:

    hg clone http://n01se.net/gentoo/overlay overlay-noise
    export PORTDIR_OVERLAY="$PWD/overlay-noise $PORTDIR_OVERLAY"
    emerge mutt
    
  • If you're on Debian, use my n01se.net apt repository:

    echo "deb http://n01se.net/agriffis/debian sid main" >> /etc/apt/sources.list
    echo "deb-src http://n01se.net/agriffis/debian sid main >> /etc/apt/sources.list
    apt-get update
    apt-get install mutt
    
  • Apply the patches and build it yourself. This patches was made on 1.5.12 but applies cleanly and works on 1.5.13 too:

    wget http://n01se.net/agriffis/mutt/mutt-1.5.12-sendbox.patch
    

Configuring your Outbox in mutt

There are three ways to use Courier's Outbox (if you learn of another IMAP server that supports the Outbox concept, I'd love to hear about it). The first way is to simply specify it in your configuration. For an IMAP configuration, that would be:

set sendbox=imaps://imap.domain.com/INBOX/Outbox
set use_sendbox=yes

This simplistic configuration works if the administrator of your mail server has enabled Outbox by default. Unfortunately this is seldom the case. More commonly, you'll need to the second way, which is to ssh into the server and start imapd yourself to enable Outbox. This is simpler than it sounds, just add to the above:

set tunnel="ssh -q server.domain.com env OUTBOX=.Outbox SENDMAIL=/usr/sbin/sendmail \
    /usr/sbin/courier-imapd .maildir"

To make this work with multiple servers, you can use account hooks.

If you're an offlineimap user, your offlineimaprc should have something like this:

[Account email]
localrepository = local
remoterepository = remote

[Repository local]
type = Maildir
localfolders = ~/mail
sep = .

[Repository remote]
type = IMAP
preauthtunnel = ssh -q server.domain.com 'env OUTBOX=.Outbox SENDMAIL=/usr/sbin/sendmail /usr/sbin/courier-imapd .maildir'
nametrans = lambda foldername: re.sub('^INBOX\.', '', foldername)

and your muttrc can then contain simply:

set sendbox=~/mail/Outbox
set use_sendbox=yes

Just don't forget to run offlineimap after sending mail from mutt, otherwise it won't leave your local Outbox!