Skip to content

Instantly share code, notes, and snippets.

@Scott31393
Last active May 24, 2022 09:19
Show Gist options
  • Save Scott31393/08ebc58fff6123979579ec954b58c28d to your computer and use it in GitHub Desktop.
Save Scott31393/08ebc58fff6123979579ec954b58c28d to your computer and use it in GitHub Desktop.
muttrc files

Mutt Configuration

Install offlineimap

Install

$ sudo apt-get install offlineimap

Gmail .offlineimaprc

# A gmail example
#
# First generic defaults
# This example was updated on 2021-05-27 to account
# for the isync rename of Master/Slave for Far/Near
Create Slave
SyncState *

IMAPAccount gmail
SSLType IMAPS
Host imap.gmail.com
User <[email protected]>
Pass <pwd>

#---------------------------------------------------------------------------------
# Throttle mbsync so we don't go over gmail's quota: OVERQUOTA error would
# eventually be returned otherwise. For more details see:
# https://sourceforge.net/p/isync/mailman/message/35458365/
# PipelineDepth 50

MaildirStore gmail-local
SubFolders Verbatim
# The trailing "/" is important
Path ~/Mail/
Inbox ~/Mail/Inbox

#----------------------------------------------------------------------------------

IMAPStore gmail-remote
Account gmail

Channel gmail
Master :gmail-remote:
Slave :gmail-local:
# Exclude everything under the internal [Gmail] folder, except the interesting folders
Patterns * ![Gmail]* "[Gmail]/Sent Mail" "[Gmail]/Starred" "[Gmail]/All Mail"
# Or include everything
#Patterns *
# Automatically create missing mailboxes, both locally and on the server
Create Both
# Sync the movement of messages between folders and deletions, add after making sure the sync works
Expunge Both
# Save the synchronization state files in the relevant directory
SyncState *


# emails sent directly to my kernel.org address
# are stored in my gmail label "Inbox"
Channel inbox
Master :gmail-remote:"Inbox"
Slave :gmail-local:inbox

# emails sent directly to my kernel.org address
# are stored in my gmail label "amarula"
Channel starred
Master :gmail-remote:"[Gmail]/Starred"
Slave :gmail-local:starred

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel open-source
Master :gmail-remote:"Open-Source Kernel-U-Boot"
Slave :gmail-local:open-source

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-kernel
Master :gmail-remote:"linux-kernel"
Slave :gmail-local:linux-kernel

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-drm
Master :gmail-remote:"linux-drm"
Slave :gmail-local:linux-drm

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-intel
Master :gmail-remote:"linux-intel"
Slave :gmail-local:linux-intel

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-tesla
Master :gmail-remote:"linux-tesla"
Slave :gmail-local:linux-tesla

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-amd
Master :gmail-remote:"linux-amd"
Slave :gmail-local:linux-amd

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-rockchip
Master :gmail-remote:"linux-rockchip"
Slave :gmail-local:linux-rockchip

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel linux-nxp
Master :gmail-remote:"linux-nxp"
Slave :gmail-local:linux-nxp

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel u-boot
Master :gmail-remote:"u-boot"
Slave :gmail-local:u-boot

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel u-boot-nxp
Master :gmail-remote:"u-boot-nxp"
Slave :gmail-local:u-boot-nxp

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel u-boot-nvidia
Master :gmail-remote:"u-boot-nvidia"
Slave :gmail-local:u-boot-nvidia

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel u-boot-rockchip
Master :gmail-remote:"u-boot-rockchip"
Slave :gmail-local:u-boot-rockchip

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel u-boot-samsung
Master :gmail-remote:"u-boot-samsung"
Slave :gmail-local:u-boot-samsung

Channel me
Master :gmail-remote:"me"
Slave :gmail-local:me

# emails sent directly to my kernel.org address
# are stored in my gmail label "open-source"
Channel libcamera
Master :gmail-remote:"libcamera"
Slave :gmail-local:libcamera

Channel sent
Master :gmail-remote:"[Gmail]/Sent Mail"
Slave :gmail-local:sent
# Exclude everything under the internal [Gmail] folder, except the interesting folders
Patterns * ![Gmail]* "[Gmail]/Sent Mail"
# Or include everything
#Patterns *
# Automatically create missing mailboxes, both locally and on the server
Create Both
# Sync the movement of messages between folders and deletions, add after making sure the sync works
Expunge Both
# Save the synchronization state files in the relevant directory
SyncState *

# Get all the gmail channels together into a group.
Group all
Channel inbox
Channel open-source
Channel sent
Channel starred
Channel linux-kernel
Channel u-boot
Channel u-boot-nxp
Channel u-boot-rockchip
Channel u-boot-nvidia
Channel u-boot-samsung
Channel me
Channel linux-drm
Channel linux-intel
Channel linux-tesla
Channel linux-amd
Channel linux-rockchip
Channel linux-nxp
Channel libcamera

Crontab Fetch Mail

Create /usr/bin/fetch-mail.sh service

$ sudo vim /usr/bin/fetch-mail.sh

Append following cmd:

check ()
{
    while pkill offlineimap
    do
        sleep 2
    done
}

quick ()
{
    offlineimap -u quiet -q -s
}

full ()
{
    offlineimap -u quiet -s
}

# parse options
while getopts "qf" OPTION
do
    case $OPTION in
        q)
            check
            quick
            exit 0
            ;;
        f)
            check
            full
            exit 0
            ;;
        ?)
            echo "Nothing to do."
            exit 1
            ;;
    esac
done

Fetch mail everry 20 min using Crontab:

$ crontab -e

Append:

*/20 * * * * /usr/bin/fetch-mail.sh -q
10 */8 * * * /usr/bin/fetch-mail.sh -f

Success:

crontab: installing new crontab

Gmail .muttrc

# Folder hooks
folder-hook 'account.com.gmail.<account0>' 'source ~/.mutt/account.com.gmail.<account0>'
folder-hook 'account.com.gmail.<account1>' 'source ~/.mutt/account.com.gmail.<account1>'
folder-hook 'account.com.gmail.<account2>' 'source ~/.mutt/account.com.gmail.<account2>'

# Default account
#source ~/.mutt/account.com.gmail.<account0>
source ~/.mutt/account.com.gmail.<account2>

# Macros for switching accounts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/account.com.gmail.<account0><enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/account.com.gmail.<account1><enter><change-folder>!<enter>'
macro index <f4> '<sync-mailbox><enter-command>source ~/.mutt/account.com.gmail.<account2><enter><change-folder>!<enter>'

# Send Notification on New Mail

set new_mail_command="notify-send 'New Email' '%n new messages, %u unread.'"

#color index green black '^~t <account2>@gmail.com !~c .'
color index red black ^~p

#macro index .i  "<limit>(~N|~F)<Enter>"  "view new/flag"
#macro index .a  "<limit>~A<Enter>"       "view all"

# Bind to I key in index view:
macro index I  "<search>~F\n"                     "Search for next important"
# Bint to I key in pager:
macro pager I  "<exit><search>~F\n<display-message>" "Jump to next important"

# Fetch mail shortcut
bind index G imap-fetch-mail

# ctrl + b macro to get mail links
macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'

# Common options
set ssl_starttls = yes
set sort_aux=last-date-received
set sort=threads
unset pop_delete
set pop_last

bind index G imap-fetch-mail

# ctrl + b macro to get mail links
macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'

# Show the number of attachment
set index_format="%4C %Z %X %{%y%m%d} %-12.12L %?M?(#%03M)&(%4c)? %?y?(%.20Y) ?%s"


set implicit_autoview
auto_view text/html  application/x-pgp-message
set mailcap_path="~/.mailcap"

# Reply to all recipients
bind index,pager g group-reply

# I use the following macros to apply patches directly from mutt (once I'm
# in a project working directory):
macro index A ":unset pipe_decode\n|(umask 0022 && git am -3)\n:set pipe_decode\n"
macro pager A ":unset pipe_decode\n|(umask 0022 && git am -3)\n:set pipe_decode\n"


set edit_headers=yes


## =============================================================
## Color definitions - See the manual.txt at
## "The Pager" and "Using color and mono video attributes"
## =============================================================

## From the manual to mutt-0.96.3:
## Objects that you can colorize:
##      attachment, body, bold, error, header, hdrdefault,
##      index, indicator, markers, message, normal,
##      quoted, quoted1, ..., quotedN,
##      search, signature, status, tilde, tree, underline.
## Color names you can use for "background" and "foreground":
##      white black green magenta blue cyan yellow red default colorx
   
#   color normal      white  black  # pager body
   color normal      default  default  # pager body
   
   color attachment  green  black  # ..
#  color body        green  black  # ..
   
#  match ftp addresses:
#  color "default" is not known any more?
#  color body cyan default "ftp://[^ ]*"
   color body cyan black   "ftp://[^ ]*"
#  match http addresses:
#  color "default" is not known any more?
   color body        green   default "[[:alnum:]][-+.#_[:alnum:]]*@[-+.[:alnum:]]*[[:alnum:]]"
#
#  Colorize "Internet addresses":
   color body        cyan    default "(http|ftp|news|telnet|finger)://[^ >]*"
   color body        cyan    default "<URL:[^ ]*>"
   color error       red     default  # global
#
# NEW color scheme for header:
   color header      blue     default  "^cc:"
   color header      cyan   default  "^date:"
   color header      green    default  "^from"
   color header      cyan     default  "^from:"
   color header      cyan     default  "^to:"
   color header      cyan   default  "^importance:"
   color header      blue     default  "^importance: normal"
   color header      green    default  "^message-id:"
   color header      white    red      "^newsgroups:"
   color header      blue     default  "^organi[sz]ation:"
   color header      cyan   default  "^priority:"
   color header      red      white    "^priority: urgent"
   color header      blue     default  "^priority: normal"
   color header      cyan   default  "^reply-to:"
#  color header      white    blue     "^subject: "  # white on blue!
   color header      default  blue     "^subject:"  # white on blue!
# special color for replies to posts on Usenet:
   color header      red      white    "^to: guckes-usenet"
   color header      cyan   default  "^user-agent:"
# special color for good user agents - mutt and xemacs:
   color header      blue     default  "^user-agent: .*mutt"
   color header      blue     default  "^X-Mailer: .*xemacs"
# pine and tin:
   color header      red      default  "^user-agent: .*pine"
   color header      red      default  "^user-agent: .*tin"
   color header      blue     default  "^x-editor: .*vim"
   color header      cyan   default  "^x-mailer:"
# Old Pine versions only identify by the message id:
   color header      red      default  "^message-id: .*pine"
# special color for "Mozilla" mailer (aka Netscape)
   color header      white    red      "^x-mailer: mozilla"
   color header      magenta  default  "^x-newsreader:"
   color header      white    red      "^x-newsreader: .*trn"
# tin puts its info on CCs into an extra line:
   color header      white    red      "^x-also-posted-to: "
   color header      white    red      "^x-webtv-signature: "
# Lotus-Schmotus:
  color header       white    red      "^x-lotus-fromdomain: "
  color header       white    red      "^X-Mailer: Lotus Notes"
# M$ sucks:
# X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
  color header       white    red      "^X-Mailer: Internet Mail Service"
  color header       white    red      "^X-Mailer: .*Microsoft Outlook"
# AK-Mail users do not seem to be able to type, either:
  color header       white    red      "^X-Mailer: .*AK-Mail"
   
   
#
#  color hdrdefault  blue   black  #
#  color indicator   white  blue   # index
   color indicator   default  cyan   # index
#   color markers     red    default# index
   color markers     yellow    default# index
color	attachment	yellow	default
#  color message     white  blue   # index
   color message     default  blue   # index
   
## ==================================================
## Colorizing the body of messages (ie in the pager)
## ==================================================
   
#  Coloring quoted text - coloring only the first four levels:
color quoted	white	default
color quoted1	yellow	default
color quoted2	red	default
color quoted3	green	default
color quoted4	cyan	default
color quoted5	yellow	default
color quoted6	red	default
color quoted7	green	default

#color signature	red	default
#color signature	blue	default
#color signature	yellow	default
color signature	magenta	default

# change the color of the gpg output
color body	green	default	"^gpg: "

#color status	white	blue	# index status bar default: black white
color status	default	cyan	# index status bar default: black white
color tilde	blue	default	# pager body
color tree	brightmagenta	default	# index
   
color bold	green	default # ..
color underline	yellow	default #
#  How this works:  Mutt recognizes sequences with embedded CTRL-H ('^H').
#  If this matches one of the following kinds
#  then you get to see the text as either "bold text" or "underlined text"
#  depending on the capabilities of your terminal.
#  bold:       "c" -> "bold 'c'"
#  underline:  "_" -> "underlined 'c'"
#  On color terminals you will see them with their own color.
  
   color body        blue   red     "<[Gg]>"
   color body        blue   red     "<[Bb][Gg]>"
#  Colorize smileys:  :-)  ;-)  :-/  :-(
   color body        yellow black   "[;:]-[)/(|]"


#  Remember:  Order counts!  The last matching rule "wins".
#  So we'll start with some general rules first:
#
#  mail to myself (personal mail):
#color	index	magenta	default		'~p'

#  mail NOT to myself (unpersonal mail):
#color index magenta   black  '! ~p'

#  mail from important people (like myself ;-):
#color index    cyan     default  '~f ([email protected]\|[email protected])'

# SPAM?!
#  color index magenta black  '! ~p ~f
#  @(aol\|hotmail\|msn\|prodigy\|yahoo)\.(com'
# color index magenta black '~f
# @(aol\|hotmail\|msn\|prodigy\|yahoo)\.(com\|net)'
#  color index magenta black  '! ~p ~f @compulink.nlrs.com'
#  color index magenta black  '! ~p ~f funtime'
#  color index magenta black  '! ~p ~f free'
#color index brightgreen default  '~s tgil'
#color index brightgreen default  '~s gtrouble'
#color index brightgreen default  '~s gnerudite'
#  color index magenta black  '! ~p ~f worldnet.att.net'

#color index       magenta      default  ~F      # Flagged
#color index       blue         default  ~T      # Tagged
#color index	blue		default	~N	# New
color index	magenta		default	~N	# New
color index	magenta		default	~D	# Deleted

#navigate sidebar
bind index,pager <F1> sidebar-open
bind index,pager <F2> sidebar-prev
bind index,pager <F3> sidebar-next

macro index L '| git am -s'\n

Outlook365 .muttrc

# .muttrc
# ================  IMAP ====================
set imap_user= '<username>@seco.com'
set imap_pass = '<outlook365-app-pwd>'

set mbox="imap://outlook.office365.com/INBOX"
set postponed="imap://outlook.office365.com/Drafts"
set spoolfile="imap://outlook.office365.com/INBOX"
set folder="imap://outlook.office365.com/"
set record="imap://outlook.office365.com/Sent Items"
#set trash="imap://outlook.office365.com/Deleted Items"
mailboxes

# ================  SMTP  ====================
set smtp_url="smtp://<username>@[email protected]:587/"
set smtp_pass = $imap_pass
set ssl_force_tls = yes # Require encrypted connection

# ================  Composition  ====================
set editor = vim
set edit_headers = yes  # See the headers when editing
set charset = UTF-8     # value of $LANG; also fallback for send_charset
# Sender, email address, and sign-off line must match
unset use_domain        # because joe@localhost is just embarrassing
set realname = "Name Surname"
set from = "<username>@seco.com"
set use_from = yes

set ssl_starttls = yes
set sort_aux=last-date-received
set sort=threads
unset pop_delete
set pop_last
bind index G imap-fetch-mail

# ctrl + b macro to get mail links
macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'

# Show the number of attachment
set index_format="%4C %Z %X %{%y%m%d} %-12.12L %?M?(#%03M)&(%4c)? %?y?(%.20Y) ?%s"


set implicit_autoview
auto_view text/html  application/x-pgp-message
set mailcap_path="~/.mailcap"

# Reply to all recipients
bind index,pager g group-reply

# Allow Mutt to open new IMAP connection automatically.
unset imap_passive

set mail_check=90
set imap_keepalive=180
set imap_idle
set timeout=15

Open Mail Links

$ sudo apt-get install urlview

Add macro to .muttrc to open links using "ctrl + b"

macro pager \cb 'urlview' 'Follow links with urlview'

Multiple accounts base .muttrc

# Default account
# .muttrc
# ================  IMAP ====================
mailboxes =AllMail =Drafts =INBOX =Trash =Important =Sent =Starred =OpenSource
mailboxes ~/Mail/tm-gmail/\[Gmail\].All\ Mail/ ~/Mail/tm-gmail/\[Gmail\].Drafts/ ~/Mail/tm-gmail/INBOX ~/Mail/tm-gmail/\[Gmail\].Trash/ ~/Mail/tm-gmail/\[Gmail\].Important/ ~/Mail/tm-gmail/\[Gmail\].Sent\ Mail/ ~/Mail/tm-gmail/\[Gmail\].Starred/ ~/Mail/tm-gmail/Open-Source\ Kernel-U-Boot/

# ================  SMTP  ====================
set smtp_url = "smtp://<account2>@smtp.gmail.com:587/"
set smtp_pass = <pwd>
set ssl_force_tls = yes # Require encrypted connection

# ================  Composition  ====================
set editor = vim
set edit_headers = yes  # See the headers when editing
set charset = UTF-8     # value of $LANG; also fallback for send_charset
# Sender, email address, and sign-off line must match
unset use_domain        # because joe@localhost is just embarrassing
set realname = "Tommaso Merciai"
set from = "<account2>@gmail.com"
set use_from = yes

set ssl_starttls = yes 
set sort_aux=last-date-received
set sort=threads
unset pop_delete
set pop_last

set mail_check=90
set imap_keepalive=180
set imap_idle
set timeout=15

set sidebar_visible = yes

Html message support

lynx resolve the problem:

$ sudo apt-get install lynx

Append in ~/.muttrc file:

set implicit_autoview
auto_view text/html  application/x-pgp-message
set mailcap_path="~/.mailcap"

Then create ~/.mailcap and add the following line:

text/html; lynx -dump -force_html  %s;  needsterminal; copiousoutput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment