Mutt

Mutt is a text-based email client for Unix-like systems. It was originally written by Michael Elkins in 1995 and released under the GNU General Public License version 2 or any later version. The Mutt slogan is “All mail clients suck. This one just sucks less.

The aim is:

  • send/receive mails over terminal
  • multi account usage
  • secured credentials
  • gpg mail encryption
  • using urls in text
  • sidebar layout
  • colors, style and keybindings

prerequisits

pkgs
# install packages
> yay -S mutt gnupg urlview
# setup config directory
> mkdir -p ~/.mutt/{Maildir,cache}

muttrc

~/.muttrc
# load secrets
source "gpg -dq $HOME/.mutt/passwords.gpg |"

# acc 1
source ~/.mutt/profile.account1
folder-hook $folder '~/.mutt/profile.account1'

# acc 2
source ~/.mutt/profile.account2
folder-hook $folder '~/.mutt/profile.account2'

# additional config
source ~/.mutt/colors
source ~/.mutt/settings
source ~/.mutt/keybindings

account

~/.mutt/profile.account1
# "account1@mailbox.org"
set realname = "User Name"
set from = "account1@mailbox.org"
set hostname="imap.mailbox.org"
set spoolfile="imaps://account1@imap.mailbox.org/INBOX"
set ssl_force_tls = yes
set ssl_verify_host = yes
set smtp_url="smtp://account1@mailbox.org@smtp.mailbox.org:587"
set smtp_pass=$my_account1
set imap_user="account1@mailbox.org"
set imap_pass=$my_account1
set folder="imaps://imap.mailbox.org/"
set postponed="+Drafts"
set record="+Sent"
set spoolfile="+INBOX"
set signature="~/.mutt/signature.account1"
# encryption setup
set pgp_default_key="0xABCD1234"
set pgp_sign_as="0xABCD1234"
~/.mutt/profile.account2
# "account2@mailbox.org"
set realname = "User Name"
set from = "account2@mailbox.org"
set hostname="imap.mailbox.org"
set spoolfile="imaps://account2@imap.mailbox.org/INBOX"
set ssl_force_tls = yes
set ssl_verify_host = yes
set smtp_url="smtp://account2@mailbox.org@smtp.mailbox.org:587"
set smtp_pass=$my_account2
set imap_user="account2@mailbox.org"
set imap_pass=$my_account2
set folder="imaps://imap.mailbox.org/"
set postponed="+Drafts"
set record="+Sent"
set spoolfile="+INBOX"
set signature="~/.mutt/signature.account2"

signature

touch ~/.mutt/signature.account{1,2}

login passwords

Create ~/.mutt/passwords file for account credentials

~/.mutt/passwords
set my_account1 = "secretpassword"
set my_account2 = "secretpassword"

variable must begin with my_ eg. my_account1


Now encrypt ~/.mutt/passwords using gpg2

# encrypt file
> gpg2 -r <GPG_PUBKEY> -e ~/.mutt/passwords

# validate output
> gpg2 -dq ~/.mutt/passwords.gpg

# remove plaintext file
> shred ~/.mutt/passwords
> rm ~/.mutt/passwords

settings

~/.mutt/settings
# General options
set imap_check_subscribed
set imap_keepalive = 300
unset imap_passive
set mail_check = 600
set mbox_type=Maildir

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

# hide stuff
ignore headers *
unignore headers from to subject date cc
hdr_order from to cc subject date

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

# set up the sidebar, default not visible
set sidebar_width=25
set sidebar_visible=yes

# add sidebox inboxes
mailboxes =inbox =something

keybindings

~/.mutt/keybindings
# sidebar controll
# ctrl-o: open selected folder
bind index \CO sidebar-open
bind pager \CO sidebar-open
# ctrl-n: next folder
bind index \CN sidebar-next
bind pager \CN sidebar-next
# ctrl-p: previously folder
bind index \CP sidebar-prev
bind pager \CP sidebar-prev

# folder-hook
# F2: open account 1
macro index,pager <f2> '<sync-mailbox><enter-command>source ~/.mutt/profile.account1<enter><change-folder>!<enter>'
# F3: open account 2
macro index,pager <f3> '<sync-mailbox><enter-command>source ~/.mutt/profile.account2<enter><change-folder>!<enter>'

# urlview
# U: open URLs
macro index,pager U "<enter-command>set pipe_decode = yes<enter><pipe-message>urlview<enter><enter-command>set pipe_decode = no<enter>""view URLs"

F2: account1
F3: account2
ctrl-o: open selected folder
ctrl-n: next folder
ctrl-p: previously folder
U: open link in urlview

colors

~/.mutt/colors
## See https://github.com/h3xx/mutt-colors-neonwolf

# Neonwolf Color Scheme for Mutt
# Based mostly on the colors from the badwolf lightline theme
# custom body highlights -----------------------------------------------
# custom index highlights ----------------------------------------------
# for background in 16 color terminal, valid background colors include:
# base03, bg, black, any of the non brights
# style notes:
# when bg=235, that's a highlighted message
# normal bg=233

# basic colors ---------------------------------------------------------
color error         color196        color235                        # message line error text
color tilde         color81         color233                        # vi-like tildes marking blank lines
color message       color82         color235
color markers       brightcolor232  color222                        # wrapped-line /^\+/ markers
color attachment    brightcolor165  color235                        # attachment headers
color search        color232        color154                        # search patterns in pager
color status        brightcolor232  color39
color indicator     brightcolor232  color154                        # selected email in index
color tree          brightcolor165  color233                        # arrow in threads (`-->')

# basic monochrome screen
mono bold           bold
mono underline      underline
mono indicator      reverse
mono error          bold
mono header         bold                            "^(From|Subject|Date|To|Cc|Bcc):"
mono quoted         bold

# index ----------------------------------------------------------------

color index         color160        color233        "~A"            # all messages
color index         color166        color233        "~E"            # expired messages
color index         brightcolor154  color233        "~N"            # new messages
color index         color154        color233        "~O"            # old messages
color index         color244        color233        "~R"            # read messages
color index         brightcolor39   color233        "~Q"            # messages that have been replied to
color index         brightcolor154  color233        "~U"            # unread messages
color index         brightcolor154  color233        "~U~$"          # unread, unreferenced messages
color index         color222        color233        "~v"            # messages part of a collapsed thread
color index         color222        color233        "~P"            # messages from me
#color index         color39         color233        "~p!~F"        # messages to me
#color index         color39         color233        "~N~p!~F"      # new messages to me
#color index         color39         color233        "~U~p!~F"      # unread messages to me
#color index         color244        color233        "~R~p!~F"      # messages to me
color index         brightcolor165  color233        "~F"            # flagged messages
color index         brightcolor165  color233        "~F~p"          # flagged messages to me
color index         brightcolor165  color233        "~N~F"          # new flagged messages
color index         brightcolor165  color233        "~N~F~p"        # new flagged messages to me
color index         brightcolor165  color233        "~U~F~p"        # new flagged messages to me
color index         color232        color196        "!~N ~D"        # deleted messages
color index         color232        color196        "~N ~D"         # deleted new messages
color index         color244        color233        "~v~(!~N)"      # collapsed thread with no unread
color index         color81         color233        "~v~(~N)"       # collapsed thread with some unread
color index         color81         color233        "~N~v~(~N)"     # collapsed thread with unread parent
# statusbg used to indicated flagged when foreground color shows other status
# for collapsed thread
color index         color160        color233        "~v~(~F)!~N"    # collapsed thread with flagged, no unread
color index         color81         color233        "~v~(~F~N)"     # collapsed thread with some unread & flagged
color index         color81         color233        "~N~v~(~F~N)"   # collapsed thread with unread parent & flagged
color index         color81         color233        "~N~v~(~F)"     # collapsed thread with unread parent, no unread inside, but some flagged
color index         color39         color233        "~v~(~p)"       # collapsed thread with unread parent, no unread inside, some to me directly
color index         color81         color160        "~v~(~D)"       # thread with deleted (doesn't differentiate between all or partial)
color index         color222        color233        "~T"            # tagged messages
color index         brightcolor222  color233        "~T~F"          # tagged, flagged messages
color index         brightcolor222  color233        "~T~N"          # tagged, new messages
color index         brightcolor222  color233        "~T~U"          # tagged, unread messages

# message headers ------------------------------------------------------

color hdrdefault    brightcolor222  color235
color header        brightcolor39   color235        "^(From|To|Cc|Bcc)"
color header        brightcolor165  color235        "^(Subject|Date)"

# body -----------------------------------------------------------------

color quoted        color39         color235
color quoted1       color165        color235
color quoted2       color39         color235
color quoted3       color222        color235
color quoted4       color166        color235
color signature     color81         color235                        # everything below /^--\s*$/

color bold          color255        color233
color underline     color233        color244
color normal        color244        color233

## pgp

color body          color160        color233        "(BAD signature)"
color body          color39         color233        "(Good signature)"
color body          color235        color233        "^gpg: Good signature .*"
color body          color241        color233        "^gpg: "
color body          color241        color160        "^gpg: BAD signature from.*"
mono  body          bold                            "^gpg: Good signature"
mono  body          bold                            "^gpg: BAD signature from.*"

# yes, an insane URL regex
color body          brightcolor39   color233        "([a-z][a-z0-9+-]*://(((([a-z0-9_.!~*'();:&=+$,-]|%[0-9a-f][0-9a-f])*@)?((([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?|[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)(:[0-9]+)?)|([a-z0-9_.!~*'()$,;:@&=+-]|%[0-9a-f][0-9a-f])+)(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*(/([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*(;([a-z0-9_.!~*'():@&=+$,-]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?(#([a-z0-9_.!~*'();/?:@&=+$,-]|%[0-9a-f][0-9a-f])*)?|(www|ftp)\\.(([a-z0-9]([a-z0-9-]*[a-z0-9])?)\\.)*([a-z]([a-z0-9-]*[a-z0-9])?)\\.?(:[0-9]+)?(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*(/([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*(;([-a-z0-9_.!~*'():@&=+$,]|%[0-9a-f][0-9a-f])*)*)*)?(\\?([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?(#([-a-z0-9_.!~*'();/?:@&=+$,]|%[0-9a-f][0-9a-f])*)?)[^].,:;!)? \t\r\n<>\"]"
# and a heavy handed email regex
color body          brightcolor39   color233        "((@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\]),)*@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\.[0-9]?[0-9]?[0-9]\\]):)?[0-9a-z_.+%$-]+@(([0-9a-z-]+\\.)*[0-9a-z-]+\\.?|#[0-9]+|\\[[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\.[0-2]?[0-9]?[0-9]\\])"

# simplified regex for URL & email
#color body		magenta		default	"(ftp|https?|gopher|news|telnet|finger)://[^ \"\t\r\n]+"
#color body		magenta		default	"[-a-z_0-9.]+@[-a-z_0-9.]+"

# vi: ft=muttrc ts=4 sw=4 sts=4 et

urlview

~/.urlview
REGEXP (((http|https|ftp|gopher)|mailto)[.:][^ >"\t]*|www\.[-a-z0-9.]+)[^ .,;\t>">\):]
COMMAND chromium %s

change COMMAND to your needs