mutt with multiple accounts

2017-05-02

** WARNING: This is a 3 year old poorly written walk through. I am going to update it and make it somewhat more worth reading after the holidays (today is 12/17/2020). Come back for an update the week of the New Year. Thanks for reading! ** glorious mutt

I’ve been using mutt, specifically Neomutt for about 2 months now trying out different setups, hacking on the config here and there whenever I have time. Or, whenever I happen to encounter one of those Defcon 5 level annoyances that can shift priorities. Although, There have been very few of those moments with mutt, to be sure. In the following paragraphs I’ll give a not too overly in depth rundown of my configuration and note some things that I found along the way.

If you plan on using this post as a guide i implore you to do so with the manpage open and ready to be cross referenced before you decide on something you’re not absolutely sure of.

So, here are the deets:

  • Gmail - 2 raw gmail accounts. Mutt will handle IMAP and SMTP.
  • GPG - Because. Because.
  • I will point out that I am using NeoMutt 20170428 (1.8.2) at the time of writing.
~/.mutt ❯  ls
cache/         secrets/       imap.account2          sidebar
certificates/  temp/          mailcap                sig
headers/       binds          mutt_bgrun             view_attachment.sh*
messages/      imap.account1  muttrc.monstar_island

Above is my configuration structure for mutt, with the main configuration file, .muttrc in ~/. Mutt allows you to source files, among other shell functions, so you can separate your config into logical units as I’ve done. You’ll want to create cache/, headers/, and messages/ for caching or expect to time mutt’s startup with a sundial.

.muttrc

source "/usr/share/doc/mutt/samples/gpg.rc"

set my_gpass1   = `gpg -q -d ~/.my_pass.gpg`
set my_gpass2   = `gpg -q -d ~/.my_pass2.gpg`
account-hook imap.mmmemail 'set imap_user=mmmemail@gmail.com
imap_pass=`gpg -q -d ~/.my_pass.gpg`'
account-hook imap.canibaoxa 'set imap_user=canibaoxa@gmail.com
imap_pass=$my_gpass2'

source ~/.mutt/imap.mmmemail

Very sparse - The first line is necessary to allow mutt to do its gpg magic. There are many different encryption options and you should find the one so find the one that suites your needs, and then save the file somewhere more convenient. The next couple of lines are how I decrypt my encrypted password. If you know enough to use GPG you know enough to not use plain text passwords. Be aware this isn’t the best way of doing it, but its moderately secure.

The account-hooks are the functioning mutt uses for switching between accounts. If you only have 1 account instead of the account hooks you would either continue your config here, or source another file containing your account specific config, exactly like you see in the final line. Which, if you have multiple accounts, is used to define the default account.

meat and potatoes

Here’s the “main” configuration. It’s not important what you name these BTW, exercise whatever repressed artistic expression you want. I keep my account specific configs in imap.. I've chosen to use folding (through vim) for ** a e s t h e t i c s ** (thats the if you're not sure what I'm referring to) and that is entirely personal choice.


ources
    source "~/.mutt/muttrc.sidebar.canibaoxa"
    source "~/.mutt/muttrc.monstar_island"
    source "~/.mutt/binds
#

# paths
set message_cachedir    = "~/.mutt/messages"
set certificate_file    = "~/.mutt/certificates"
set mailcap_path        = "~/.mutt/mailcap"
set tmpdir              = "~/.mutt/temp"
set signature           = "~/.mutt/mmmemail.sig"
#

So since my sidebar configurations for both accounts I’ve made it a standalone config so there’s less duplicate work. You’ll need to use the sidebar patch if you’re using standard non Debian MUTT.

monstar_island is my “theme”. More on that later.

The paths portion is where where I set caching and tell it where to cache. As well the location of the mailcap file to read any non plain text mail. We’ll come back around to the mailcap at the end. You can define your signature here too.

# user
set realname            = "Viktor Vaughn"
set imap_user           = "mmmemail0@gmail.com"
set imap_pass           = `gpg -q -d  ~/.mutt/secrets/password.gpg`
set smtp_url            = "smtp://mmmemail@smtp.gmail.com:587/"
set smtp_pass           = `gpg -q -d  ~/.mutt/secrets/password.gpg`
set folder              = "imaps://imap.gmail.com/"
set spoolfile           = imaps://imap.gmail.com/INBOX
set imap_check_subscribed

set pgp_sign_as         = 0xabcd1234
set pgp_autosign
set pgp_verify_sig
set pgp_replyencrypt    = yes
set pgp_timeout         = 3600

set ssl_starttls        = yes
set ssl_force_tls       = yes

set from                = "mmmemail@gmail.com"
set use_from            = "yes"
set envelope_from
set postponed           = "+[Gmail]/Drafts"
set trash               = "+[Gmail]/Trash"
unset record
set query_command       = "goobook query '%s'"
set text_flowed         = yes
set editor              = "vim -c 'set spell spelllang=en'"
set sig_dashes
set fcc_attach
set reply_to
set reverse_name
set include             # the next 3 set's are to
set edit_headers        # go right to vim and edit through that composition
set autoedit            # window, rather than mutt giving me 21 questions
set forward_quote
unset mime_forward
#

Ok - that’s kind of a lot to unpack. And I would like to again stress that you should be reading the manpage to figure out what these are all about before you commit to anything. With that said, the imap and smtp stuff should be self explanatory.

  • [folder] - the default location of your mailboxes. You’ll notice later on I’ve prepended folders with +, or =. Those expand to what you’ve set to folder. If you’re using IMAP its most likely the IMAP url.
  • [spoolfile] - your default mailbox.
  • [imap_check_subscribed] - so you don’t have to explicitly state every mailbox you want checked.
  • [text_flowed] - In short it formats your plaintext emails in such a way that the reader is not left to assume you’re some sort of uncivilized savage.
# inbox
set mbox_type           = Maildir
set timeout             = 60
set mail_check          = 60
set imap_keepalive      = 30
unset imap_passive
set delete
set quit
set pipe_decode
set thorough_search
unset confirmappend
unset mark_old
# h e a d e r s
ignore *
unignore  X-Bogosity From: To: Cc: Date:
hdr_order X-Bogosity From: To: Cc: Date:
#unignore From: Subject: To: Cc:
#

#index
set forward_format      = "Fwd: %s"
set date_format = "%m/%d•%H:%M"
set index_format = "%Z ⌈%D⌋ %-20.20F ⌜%s⌟"
set implicit_autoview
alternative_order text/plain text/html text/encriched
auto_view text/html
set sort                = "reverse-threads"
set sort_browser        = "alpha"
set sort_aux            = "last-date-received"
set uncollapse_jump
set sort_re
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"
#

The timeout, imap_keepalive, and mail_check are sort of underplayed, I think because of all the things most likely to cause you to go full angry panda, these are amongst the highest ranked. These define your check intervals and how long mutt waits for you to do a thing. If you set them much lower, or with a much larger delta you’re going to run into race conditions and network timeout issues that leave your client frozen while you thought you just weren’t getting any mail.

# macros
macro index,pager A **"<save-message>=[Gmail]/All%20Mail<enter><enter>" "Archive
Message"**
macro index,pager gi "=INBOX" "Go to inbox"
macro index,pager ga "=All Mail" "Go to all mail"
macro index,pager gs "=Sent Mail" "Go to starred messages"
macro index,pager gd "=Drafts" "Go to drafts"
macro pager \cu |urlview\n
#

This is the final thing I want to point out, and one of the main reasons for writing this: If you’ve looked at other tutorials, manuals (official or otherwse) you may have seen and possibly tried this macro except without the white space escaping %20. Ive not seen it documented anywhere, but i’ve seen the macro in its non functional form everywhere. I may have missed it in the docs, or on a mailing list, but it was my Hail Marie that I just happened to remember after working through ever possible quote, single quote backspace escape sequene possible.

That covers just about all I think should be called out before this turns into hand holding. You can however see my complete config including mailcap and theme on my github. Configuring colors/a theme doesnt really need much explanation. It’s standard xterm stuff. With that said, I’m always willing to answer any questions.