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!

9 comments:

Flyer said...

Great how-to! But how do you make all mail except mail from mailing lists go to "All mail"(Inbox?) mailbox? Thanks in advance.

Unknown said...

Hi Flyer,

You can't, All Mail is actually that.
The usual way to do this filtering is to "skip inbox+apply label" for everything from mailing lists.
Then, if you don't want to "see" the noise from "All Mail" in mutt just don't put the "=[Gmail]/All Mail" in the 'mailboxes' line.

Cheers,
--J

Flyer said...

Thanks. I love mutt :)

Unknown said...

Thanks for the help! This really made it easy to switch to gmail+mutt.

David

elchelo said...

Check it out!

http://www.unomendoza.com.ar/2007/12/16/nota167865.html

:)

Unknown said...

I created a small patch for unicode-mess :(

http://www.gerolf.ziegenhain.com/linux/content.html#configuration

/Gerolf

Anonymous said...

The line 'set record="+[Gmail]/Sent Mail"' is not needed as Gmail copies it to the account's default Sent Mail folder with no further action by mutt.

Also, if you're using an account initially set up in a region where Google lost the Gmail trademark battle (.uk for me), then you should change the [Gmail] entries to [Google Mail] or whatever you see when exploring the imap folder with mutt. It should be obvious from the visible folder hierarchy.

Cheers,
Jonathan

Anonymous said...

Regarding the 'set record="+[Gmail]/Sent Mail"' comment...it's true that you don't need to specify this, but then you should disable copy with 'set copy=no' otherwise mutt will store a local copy of all sent messages as well as Gmail's copy.

Michael said...

Just a quick thanks for the howto. Saved me a lot of time and research.

Thanks :)