Skip to content

My mail client setup

Published on: September 19, 2011 | Last modified on: September 19, 2011

As it seems lots of people like to share how they read their email, I will try and explain my own setup, based on OfflineIMAP and Mutt.

I will only detail here the features I appreciate and which might be tricky to setup for the newcomers.

All my configuration files are available in my git repository.

OfflineIMAP

My complete OfflineIMAP configuration can be found at: http://git.kirya.net/?p=dotfiles/offlineimap.git;a=tree.

Retrieving passwords from gnome-keyring or a .netrc file

OfflineIMAP documentation describes 6 ways to retrieve a password, none of them being as easy and as secure than retrieving it from gnome-keyring. Fortunately, OfflineIMAP allows to extend its features by using an external python script, which can be used to retrieve passwords stored in the keyring.

This script can be found at: http://www.clasohm.com/blog/one-entry?entry_id=90957.

As I use OfflineIMAP in different environments, I have added the possibility to fallback to retrieving an unencrypted password from a .netrc file. I can then use the same configuration on all hosts.

Here are the information I specify in my ~/.offlineimaprc file:

remotehost = imap.kirya.net
remoteusereval = get_username("imap.kirya.net")
remotepasseval = get_password("imap.kirya.net")

Mailboxes

OfflineIMAP can write a mailboxes file that can be sourced from Mutt configuration, here is what I use:

[mbnames]
enabled = yes
filename = ~/.mutt/mailboxes
header = "mailboxes "
peritem = "+%(foldername)s"
sep = "\nmailboxes "
footer = "\n"

I also have a function in my ~/.offlineimap.py file that allows me to prioritize (read list first) some folders.

Mutt

My complete Mutt configuration can be found at: http://git.kirya.net/?p=dotfiles/mutt.git;a=tree.

Checking missing attachments

Some scripts allow you to detect missing attachments when sending email, based on some keywords found in the text of your email. I use such a script, originally found on the Mutt wiki, in a slightly amended form: if running in an X environment, “my” script uses zenity to display a nice dialog box asking the user what to do in case the script detects a missing attachment; when running in a terminal, the script falls back to asking the user to add a dedicated header if she wants to send the email without attachment.

Viewing attachments

Though Mutt handles this very nicely by default, I had two separate issues, both solved in using external helper scripts and a customized ~/.mailcap file:

  • I want to also be able to view the attachments when using Mutt remotely. For this, I use a script originally found at: http://puzzling.org/logs/thoughts/2010/May/6/mutt-attachments. This script copies the attachment into a publicly accessible place (you actually need a webserver on the machine running mutt, though it could be adapted to eg. scp the file to your local computer).
  • By default, Mutt waits for the viewer used to open an attachment to exit to continue, eg. making it impossible to let an attachment open while reading the contents of the email. I use Gary Johnson‘s mutt_bgrun to workaround this issue.

Both scripts are called via my .mailcap file as follows (note that I have renamed the original scripts for my own use):

<Content-Type>; mutt-bgrun <X viewer> '%s'; test=test -n "$DISPLAY"
<Content-Type>; mutt-copy2dir '%s'

The first line is used in an X environment, launching your desired viewer for the designated file type. When running remotely, the attachment is copied and an URL pointing to it is displayed.

notmuch integration

Thanks to Stefano Zacchiroli, I am also using notmuch for indexing and searching my email. all you need to know is clearly explained in the following blogpost.

Setting the sender identity depending on the context

I have several email addresses, and I like Mutt to be able to “guess” which is the most adapted depending on the context.

Here is my default configuration:

set realname = "Julien Valroff"
set from = "julien@kirya.net"
set hostname = "kirya.net"
set use_envelope_from

Here, I define my extra email addresses:

alternates '(julien@valroff\.fr|jvalroff@april\.org|julien@debian\.org)'

The following setting allows Mutt to automatically use the email address the mail I reply to was sent to:

set reverse_name

This is from: http://wiki.mutt.org/?ConfigTricks

alias identity_1 $realname <julien@kirya.net>
alias identity_2 $realname <julien@debian.org>
alias identity_3 $realname <jvalroff@april.org>
alias identity_4 $realname <julien@valroff.fr>
macro compose F "<edit-from>^Uidentity_<tab>" "Choisir une adresse d'expédition"

These send-hooks allows me to automatically use the correct email address depending to where email are sent (eg. if I send an email to lists.debian.org, Mutt will use my @debian.org address):

set my_from = $from
send-hook '~t .*' 'set from = $my_from' # needed to reset default from
send-hook '~t @april\.org$' 'set from = "jvalroff@april.org"'
send-hook '(~C debian\.org$ | ~C debian\.net$)' 'set from = "julien@debian.org"'

DSPAM training

These are the macros I use for DSPAM training. Note that to train multiple mail at the same time (using Mutt tag feature), you need to configure your MTA to use the dspam-retrain-forward.pl script.

set my_spamaddr = "spam@kirya.net"
set my_hamaddr = "ham@kirya.net"
 
set my_mime_forward = $mime_forward
set my_copy = $copy
set my_weed = $weed
set my_resolve = $resolve
set my_editor = $editor
 
#tip: add a space before commands so that they are not saved in commands history
macro index X "<enter-command> set copy=no mime_forward=yes weed=no resolve=no editor='/bin/true'<enter><tag-prefix><clear-flag>N<tag-prefix><forward-message>$my_spamaddr<enter><send-message><tag-prefix><delete-message><enter-command> set copy=$my_copy mime_forward=$my_mime_forward weed=$my_weed resolve=$my_resolve editor='$my_editor'<enter><next-entry>" "Mark as spam"
macro pager X "<enter-command> set copy=no mime_forward=yes weed=no resolve=no editor='/bin/true'<enter><clear-flag>N<forward-message>$my_spamaddr<enter><send-message><delete-message><enter-command> set copy=$my_copy mime_forward=$my_mime_forward weed=$my_weed resolve=$my_resolve editor='$my_editor'<enter><next-entry>" "Mark as spam"
macro index H "<enter-command> set copy=no mime_forward=yes weed=no resolve=no editor='/bin/true'<enter><tag-prefix><clear-flag>N<tag-prefix><forward-message>$my_hamaddr<enter><send-message><enter-command> set copy=$my_copy mime_forward=$my_mime_forward weed=$my_weed resolve=$my_resolve editor='$my_editor'<enter><tag-prefix><save-message>=INBOX\n<enter><next-entry>" "Mark as ham and move to INBOX"
macro pager H "<enter-command> set copy=no mime_forward=yes weed=no resolve=no editor='/bin/true'<enter><clear-flag>N<forward-message>$my_hamaddr<enter><send-message><enter-command> set copy=$my_copy mime_forward=$my_mime_forward weed=$my_weed resolve=$my_resolve editor='$my_editor'<enter><save-message>=INBOX\n<enter><next-entry>" "Mark as ham and move to INBOX"