Sunday, November 18, 2007

Using mutt for gmail via IMAP

You use mutt, you love it. You hate the user interface "latency" of every other MUA, and the fact that no other MUA has "got" how to handle mail threading as mutt does.
BUT also you, a true road warrior, want mail(box) availabilty and plenty of storage.
Well, recently gmail added IMAP support, with a very good support of the standard AND a well thought mapping between gmail labels and IMAP folders ( "virtual" folders).

The good news is that you can link your beloved mutt to gmail, use IMAP folders and also use SMTP TLS authentication via smtp.gmail.com

Here is a copy of my .mutt/muttrc (obviously must change "username" and other stuff):

## ~/.mutt/muttrc
set from=username@gmail.com
set realname="JuanJo seC"
set reverse_name=yes
set reverse_realname=no
set imap_user = 'username@gmail.com'
set spoolfile = imaps://imap.gmail.com:993/INBOX
#set sendmail="/usr/sbin/ssmtp -C$HOME/.mutt/ssmtp.conf"
set smtp_url="smtp://username@smtp.gmail.com:587/"
set folder = "imaps://imap.gmail.com:993"
#set record=+sent-mail-`date +%Y`
set record="+[Gmail]/Sent Mail"
set postponed="+[Gmail]/Drafts"
# previously do: mkdir -p ~/.mutt/cache/{headers,bodies}
set header_cache="~/.mutt/cache/headers"
set message_cachedir="~/.mutt/cache/bodies"
set certificate_file=~/.mutt/certificates
set move=no
set delete=yes
set edit_hdrs
set include
set reply_to
set abort_nosubject=no
alternates '(username|altusername)([-+].*)?@.*'
set hdr_format="%4C %Z %{%m/%d} %-15.15F (%4c) %s" # format of the index

hdr_order From: Date: User-Agent: X-Mailer To: Cc: Reply-To: Subject:
ignore *
unignore From: Date: User-Agent: X-Mailer To: Cc: Reply-To: Subject:
my_hdr Reply-To:

# setup gmail filters to apply the corresp. labels:
mailboxes ! =ml-lug-list =ml-lug-org =[Gmail]/Drafts "=[Gmail]/All Mail"

set editor="jed %s -l ~/.mutt/jed.mutt.sl"
set alias_file=~/.mutt/mail_aliases
source ~/.mutt/mail_aliases

send-hook . 'set realname="JuanJo seC"'
## hack to make $reverse_name and 'my_hdr From:' work ok (eg mlists)
send-hook . 'set from=username@gmail.com'
send-hook . 'unmy_hdr From:'
###
send-hook . 'set signature=~/.signature'

#send-hook lug-list 'set record=+sent-lug-list'
send-hook lug-.+@lugmen.org.ar 'my_hdr From: JuanJo seC <username+mlist@gmail.com>
subscribe lug-.+@lugmen.org.ar



Very cool to experiment folder switching in mutt using:
'c' ("Open Mailbox")
TAB (will show all IMAP folders)
TAB (again: will show only the 'mailboxes' mutt var)

And here is my jed rc:

% ~/.mutt/jed.mutt.sl
% emacs keybinding for jed:
() = evalfile("emacs");
% Find signature begin, position cursor there:
if (re_fsearch("^--")) {
call("previous_line_cmd");
} else {
% else search headers end
re_fsearch("^$");
call("next_line_cmd");
}
push_mark();


Yeahh... finally I can read mailing lists with an interface that doesn't suck! 8)
Enjoy!