My muttrc with Multiple Imap Accounts

Mar 20, 2021 • edited Jun 20, 2021

Here I share my mutt configuration.

The main features of the config are:

  • Support for multiple imap accounts at the same time.
  • Set from before sending.
  • Automatically set from based on message headers.
  • Sidebar config.
  • Spell support for multiple languages.
  • Auto sign mails with GPG.
  • Bookmarks.
  • Multiple maillists/mailboxes.

Note: This is a post that I will keep updated to reflect any significant changes to my mutt configuration.

Files

~/.mutt/muttrc

~/.mutt/cfg/general

~/.mutt/cfg/hooks

~/.mutt/cfg/gpg

~/.mutt/cfg/maillists

~/.mutt/cfg/mailboxes

~/.mutt/cfg/headers

~/.mutt/cfg/sidebar

~/.mutt/cfg/keybindings

~/.mutt/cfg/marcros

~/.mutt/cfg/coreimapfolders_gmail

~/.mutt/cfg/coreimapfolders_yourdomain

~/.mutt/muttrc

← back to Files

~/.mutt/cfg/general

set realname = "Your Name"
# list of my mail address
alternates "^(user@gmail.com|user@yourdomain.net)$"

# show mutt version at the start
push <show-version>

set charset = "utf-8"
set send_charset = "utf-8"

set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"

# this prevents Mutt from endlessly asking when you quit:
#     "Move read messages to ~/mbox? ([no]/yes):"
set move = no

# If you start mutt and several new messages are in your inbox and you close
# mutt before you have read them, then those messages will get flagged as old
# (by default). The behavior can be controlled via the mark_old configuration variable.
set mark_old = no

set include = yes
set quit = yes
set arrow_cursor = no
set delete = yes
set user_agent = yes

set abort_nosubject = yes

# check for unread, flagged, and total message counts
set mail_check_stats = yes
# 60 secs
set mail_check_stats_interval = 60

set sort = threads
set sort_aux = last-date-received

# personal variables, starts with my_
# to display variable value on mutt:
# type : set ?variable_name
set my_test = "hihi"

set hdr_format = "%4C %Z %{%b %d} %-15.15n (%4l) %s"

set ssl_starttls = yes
set ssl_force_tls = yes

## IMAP connections
# Allow Mutt to open a new IMAP connection automatically.
unset imap_passive
# Keep the IMAP connection alive by polling intermittently (time in seconds).
set imap_keepalive = 60
# How often to check for new mail (time in seconds).
set mail_check = 120
# Do not automatically poll subscribed mailboxes for new mail
set imap_check_subscribed = no

## spell
set my_ptbr_spell = "/usr/bin/aspell -c --mode=email --lang=pt_BR"
set my_enus_spell = "/usr/bin/aspell -c --mode=email --lang=en_US"
# default spell
set ispell = $my_ptbr_spell

## bookmarks in mutt
set alias_file = ~/.mutt/cfg/aliases
set sort_alias = alias
set reverse_alias = yes
source ~/.mutt/cfg/aliases

## view special formats
set mailcap_path = ~/.mutt/mailcap
# order to display in multitype mail
alternative_order text/plain text/enriched text/html
auto_view text/html
auto_view application/pdf

← back to Files

~/.mutt/cfg/hooks

# hook = execute a command before an operation
# hooks can match more than one? and why account-hook .
#    . No, they match only one.
#    . The dot is used to create a default when not match on other hooks.
#    . Is a nice ideia to use dot with unset in cases on when not match, like imap_user/pass.

##### account-hook # account-hook should only be used to set # connection-related settings such as passwords or tunnel commands. account-hook . 'unset imap_user; unset imap_pass' account-hook imaps://imap.gmail.com/ 'set imap_user = "user@gmail.com"; set imap_pass = "`~/shell-script/get-pass.sh imap user@gmail.com`"' account-hook imaps://mail.yourdomain.net/ 'set imap_user = "user"; set imap_pass = "`~/shell-script/get-pass.sh imap user@yourdomain.net`"'

##### folder-hook folder-hook imaps://imap.gmail.com/ 'source ~/.mutt/cfg/coreimapfolders_gmail; set from="user@gmail.com"' folder-hook imaps://mail.yourdomain.net/ 'source ~/.mutt/cfg/coreimapfolders_yourdomain; set from="user@yourdomain.net"'

##### send-hook, executed after edit the message in editor ##### send2-hook, executed every time that the message/headers is changed # ~h message header # ~s subject # -C to/cc # hostname is used only for Message-ID send2-hook . 'unset smtp_url; unset imap_pass; unset hostname' send2-hook ~h'user@gmail.com' 'set smtp_url = "smtps://user@smtp.gmail.com"; set smtp_pass = "`~/shell-script/get-pass.sh smtp user@gmail.com`"; source ~/.mutt/cfg/coreimapfolders_gmail; set hostname=gmail.com' send2-hook ~h'user@yourdomain.net' 'set smtp_url = "smtp://user@mail.yourdomain.net:587"; set smtp_pass = "`~/shell-script/get-pass.sh smtp user@yourdomain.net`"; source ~/.mutt/cfg/coreimapfolders_yourdomain; set hostname=yourdomain.net'

##### address to use in from when reply reply-hook . 'unset from' reply-hook ~C'user@gmail.com' my_hdr from: user@gmail.com reply-hook ~C'user@yourdomain.net' my_hdr from: user@yourdomain.net reply-hook ~C'debian-' my_hdr from: user@yourdomain.net # people and address to use reply-hook ~h'peopleaddress1' my_hdr from: user@yourdomain.net reply-hook ~h'peopleaddress2' my_hdr from: user@yourdomain.net

← back to Files

~/.mutt/cfg/gpg

# The default key for encryption (used by $pgp_self_encrypt and
# $postpone_encrypt).
# 
# It will also be used for signing unless $pgp_sign_as is set to a
# key.
#
set pgp_default_key = "0xXXXXXXXX"

set crypt_use_gpgme = yes

# decode application/pgp
set pgp_decode_command = "gpg --status-fd=2 %?p?--passphrase-fd 0 --pinentry-mode=loopback? --no-verbose --quiet --batch --output - %f"

# verify a pgp/mime signature
set pgp_verify_command = "gpg --status-fd=2 --no-verbose --quiet --batch --output - --verify %s %f"

# decrypt a pgp/mime attachment
set pgp_decrypt_command = "gpg --status-fd=2 %?p?--passphrase-fd 0 --pinentry-mode=loopback? --no-verbose --quiet --batch --output - %f"

# create a pgp/mime signed attachment
set pgp_sign_command = "gpg --no-verbose --batch --quiet --output - %?p?--passphrase-fd 0 --pinentry-mode=loopback? --armor --detach-sign --textmode %?a?-u %a? %f"

# create a application/pgp signed (old-style) message
set pgp_clearsign_command = "gpg --no-verbose --batch --quiet --output - %?p?--passphrase-fd 0 --pinentry-mode=loopback? --armor --textmode --clearsign %?a?-u %a? %f"

# create a pgp/mime encrypted attachment
set pgp_encrypt_only_command = "/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust -- -r %r -- %f"

# create a pgp/mime encrypted and signed attachment
set pgp_encrypt_sign_command = "/usr/lib/mutt/pgpewrap gpg %?p?--passphrase-fd 0 --pinentry-mode=loopback? --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor --always-trust -- -r %r -- %f"

# import a key into the public key ring
set pgp_import_command = "gpg --no-verbose --import %f"

# export a key from the public key ring
set pgp_export_command = "gpg --no-verbose --export --armor %r"

# verify a key
set pgp_verify_key_command = "gpg --verbose --batch --fingerprint --check-sigs %r"

# read in the public key ring
set pgp_list_pubring_command = "gpg --no-verbose --batch --quiet --with-colons --with-fingerprint --with-fingerprint --list-keys %r"

# read in the secret key ring
set pgp_list_secring_command = "gpg --no-verbose --batch --quiet --with-colons --with-fingerprint --with-fingerprint --list-secret-keys %r"

set pgp_good_sign = "^\\[GNUPG:\\] GOODSIG"

set pgp_check_gpg_decrypt_status_fd

set crypt_autosign = yes

← back to Files

~/.mutt/cfg/maillists

# list: used to mark a list as known. Mutt uses that as a list. Here you aren't subscribed.
# subscribe: mark as known and use other things as you are subscribed to the list.
# usage: list/subscribe mail_address(usually a part of mail address)

## this is regex? yes!
subscribe addr_maillistpart
subscribe addr_anothermaillistpart

← back to Files

~/.mutt/cfg/mailboxes

# mailboxes: folders that can receive mail and will be periodic checked.
# IMPORTANT: must be after set spoolfile and folder variables if you use !/=/+ in names.
# ! = your $spoolfile (incoming) mailbox
# = or + your $folder directory
# for more check '10. Mailbox Shortcuts' in manual.txt

source ~/.mutt/cfg/coreimapfolders_yourdomain mailboxes -label INBOX_yourdomain !

source ~/.mutt/cfg/coreimapfolders_gmail mailboxes ! mailboxes +somefolder mailboxes +anotherfolder

← back to Files

~/.mutt/cfg/headers

set edit_headers = yes

# ignore all
ignore *

# un-ignore these
unignore From:
unignore To:
unignore Reply-To:
unignore Mail-Followup-To:
unignore Subject:
unignore Date:
unignore Organization:
unignore Newsgroups:
unignore CC:
unignore BCC:
unignore Message-ID:
unignore X-Mailer:
unignore User-Agent:
unignore X-Junked-Because:
unignore X-SpamProbe:
unignore X-Virus-hagbard:
unignore Return-Receipt-To:
unignore Disposition-Notification-To:
unignore X-Disposition-Sent:
unignore X-Priority:
unignore X-URL:

hdr_order From: Subject: To: CC: BCC: Reply-To: Mail-Followup-To: Date: Organization: User-Agent: X-Mailer:

← back to Files

~/.mutt/cfg/sidebar

# Should the Sidebar be shown?
set sidebar_visible = yes

set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S'
set sidebar_short_path = yes

← back to Files

~/.mutt/cfg/keybindings

## some keys based on Emacs usage
# alt key = \e

bind index G imap-fetch-mail

bind index,pager \Cp previous-undeleted
bind index,pager \Cn next-undeleted
bind index,pager \ep previous-thread
bind index,pager \en next-thread
bind index,pager \ev previous-page
bind index,pager \Cv next-page

bind index,pager <Left> sidebar-toggle-visible
bind index,pager <Right> sidebar-open
bind index,pager <Up> sidebar-prev
bind index,pager <Down> sidebar-next

← back to Files

~/.mutt/cfg/macros

# from https://gitlab.com/muttmua/mutt/-/wikis/ConfigTricks
macro compose v "<edit-from>^Uidentity\_<tab>" "Select from"

#macro compose y "<ispell><send-message>" 'Spell and send message'
# set and run pt_BR spell
macro compose i '<enter-command>set ispell=$my_ptbr_spell<enter><ispell>'
# set and run en_US spell
macro compose I '<enter-command>set ispell=$my_enus_spell<enter><ispell>'

# based on https://github.com/redondos/mutt/blob/master/.mutt/sourced/macros
macro index ,r '<tag-pattern>.<enter><tag-prefix-cond><clear-flag>N\
<untag-pattern>.<enter><sidebar-next><sidebar-open>' "mark all read"

# save messages
macro index \Cs '<save-message>imaps://imap.gmail.com/saved_messages<enter>'

macro index d '<delete-message><previous-undeleted><next-new-then-unread>'

← back to Files

~/.mutt/cfg/coreimapfolders_gmail

# note: always keep the last /, because + and other shortcuts can use folder variable
set folder = "imaps://imap.gmail.com/"
set spoolfile = +INBOX
set trash = "+[Gmail]/Trash"
set postponed = "+[Gmail]/Drafts"
# if set this duplicate the sent mails on GMail
#set record = "+[Gmail]/Sent Mail"
unset record

← back to Files

~/.mutt/cfg/coreimapfolders_yourdomain

# note: always keep the last /, because + and other shortcuts can use folder variable
set folder = "imaps://mail.yourdomain.net/"
set spoolfile = "+INBOX"
set trash = "+Trash"
set postponed = "+Drafts"
set record = "+Sent"

← back to Files

That’s all.

muttconfig

Back to talau's home