# A basic .muttrc for use with Gmail

# Passwords and other private data
source $HOME/.mutt/private.data
source $HOME/.mutt/aliases

# Change the following line to a different editor you prefer.
set editor = "vim -c 'source ~/.muttvimrc'"
set edit_headers=yes
# Basic config, you can leave this as is
#set folder = "imaps://imap.gmail.com:993"
set folder = "~/.mail/home"
set spoolfile = "+Inbox"
set mail_check = 120
set timeout = 300
set imap_keepalive = 300
set postponed = "+drafts"
set mime_forward
set mime_forward_rest = yes
set record = "+sent"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
#set signature=~/.mutt/sig
set index_format= '%4C %Z %[%b %d %T] %-15.15L [%N] (%?l?%4l&%4c?) %s'
set pager_format= '%4C %Z %[%b %d %T] %-15.15L [%N] (%?l?%4l&%4c?) %s'
set attach_format="%u%D%I %t%4n %T%.120d%> [%.7m/%.10M, %.6e%?C?, %C?, %s] "
set text_flowed=yes
set sig_on_top
set sig_dashes = no
set move = no
set delete
unset confirmappend
set smart_wrap
#set pager = /usr/bin/less
set quit
unset mark_old
unset resolve # don't advance to next message after operation
unset markers # don't insert a '+' on wrapped lines
set wait_key = no
set include
set sort='threads'
set sort_aux='reverse-last-date-received'
set auto_tag = yes
set pipe_decode = yes
ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
#unignore *
hdr_order Date From To Cc
auto_view text/html
auto_view text/calendar application/ics
alternative_order text/html text/plain *
#alternative_order text/plain text/html *
# Google Contacts
set query_command = "goobook reload && goobook query '%s'"
bind editor <Tab> complete-query
bind editor ^T complete
bind editor <space> noop 
auto_view text/html
# Google Contacts
#set query_command = "goobook query '%s'"
#bind editor <Tab> complete-query
#bind editor ^T complete
#bind editor <space> noop 
set text_flowed=yes

# sidebar patch
#set sidebar_delim = '  │'
#set sidebar_visible = no
#set sidebar_width = 30
#color sidebar_new brightgreen default

# MY keybindings
bind pager j next-line
bind pager <Down> next-line
bind pager k previous-line
bind pager <Up> previous-line
bind pager > next-undeleted
bind pager < previous-undeleted
bind pager / search
bind generic gg first-entry
bind pager gg top
bind generic G last-entry
bind index G last-entry
bind pager G bottom
bind index - collapse-thread
bind index _ collapse-all
#bind index q noop
bind index,pager s noop # unset s for saving, since our archive command below is pretty much all we do
bind index,pager f flag-message
bind index,pager F forward-message
bind index u undelete-message
#macro attach a "<pipe-message>ripmime -i - -d "
macro attach a "<save-entry><bol>"
macro attach T "<tag-pattern>"
macro index,pager a "<pipe-message>goobook add<enter>" "Add the sender address to Google Contacts"

# color settings
#color normal default default

# Gmail-style keyboard shortcuts

#folder-hook "+[Gmail]/All Mail" 'macro index y "<save-message>=Inbox<enter>" "Copy message from archive to Inbox"'
folder-hook . 'macro index,pager x "<change-folder>=Inbox<enter>" "Go to inbox"'
folder-hook . 'macro index,pager A "<group-reply>" "Group reply'
#folder-hook . 'macro index,pager a "<group-reply>" "Group reply'
folder-hook . 'macro index,pager n "<toggle-new>" "Toggle new flag"'
folder-hook +Inbox 'macro index x "<sync-mailbox><exit>" "Sync mailbox and exit"'
#folder-hook +Inbox 'macro index qq "<sync-mailbox><shell-escape>/usr/bin/offlineimap -u basic -q<enter>"  "Sync mail with offlineimap (quick form)"'
folder-hook +Inbox 'macro index qq "<sync-mailbox>"  "Sync mail with disk"'
#folder-hook +Inbox 'macro index qf "<sync-mailbox><shell-escape>~/bin/offlineimap.sh<enter>" "Sync mail with offlineimap (full form)"'
folder-hook +Inbox 'macro index qf "<sync-mailbox>"  "Sync mail with disk"
folder-hook +Inbox 'macro index y "<clear-flag>N<save-message>=archive<enter>" "Gmail archive message"'
folder-hook +Inbox 'macro index Y "<tag-pattern>!~F<enter><tag-prefix><clear-flag>N<save-message>=archive<enter>" "Tag all unstarred messages and archive"'
folder-hook +Inbox 'macro index N "<tag-pattern>~N<enter><tag-prefix><clear-flag>N<untag-pattern>~T<enter>" "Tag all unstarred messages and archive"'
folder-hook +Inbox 'macro pager y "<save-message>=archive<enter><next-undeleted>" "Gmail archive message, move to next message"'
folder-hook +Inbox 'macro index,pager x "<sync-mailbox><exit>" "Sync mailbox to disk and exit"'
folder-hook +archive 'macro index y "<save-message>=Inbox<enter>" "Move message to Inbox"'
folder-hook results$ 'macro index y "<save-message>=Inbox<enter>" "Move message to Inbox"'
folder-hook +archive 'macro pager y "<save-message>=Inbox<enter><exit>" "Gmail archive message"'
folder-hook results$ 'macro pager y "<save-message>=Inbox<enter><exit>" "Gmail archive message"'
#folder-hook +file_transmit 'macro index s "<pipe-message>ripmime -i - -d "
#macro pager u "<pipe-entry>urlview<enter>" "Follow links in urlview"
macro index,pager d "<enter-command>set trash=trash<enter><delete-message>" "Gmail delete message"
macro index,pager gi "<change-folder>=Inbox<enter>" "Go to inbox"
macro index,pager ga "<change-folder>=archive<enter>" "Go to all mail"
macro index,pager gs "<change-folder>=spam<enter>" "Go to spam messages"
macro index,pager gd "<change-folder>=drafts<enter>" "Go to drafts"
macro index,pager gt "<change-folder>=sent<enter>" "Go to drafts"

# Index sorting keys
macro index SS "<shell-escape>~/bin/by-score<enter><enter-command>source ~/.muttrc<enter>" "Sort by score"
macro index ST "<shell-escape>~/bin/by-threads<enter><enter-command>source ~/.muttrc<enter>"       "Sort by thread"
macro index SD "<shell-escape>~/bin/by-date<enter><enter-command>source ~/.muttrc<enter>"  "Sort by date"
macro index SR "<shell-escape>~/bin/by-reverse<enter><enter-command>source ~/.muttrc<enter>"  "Sort aux by date"
macro index SE "<shell-escape>~/bin/by-sent<enter><enter-command>source ~/.muttrc<enter>" "Sort by date sent"


# Search with notmuch
macro index / "<enter-command>unset wait_key<enter><shell-escape>notmuch-mutt --prompt search<enter><change-folder-readonly>~/.cache/notmuch/mutt/results<enter>" "Search messages"

# -*-muttrc-*-

# Star scoring 
source ~/.mutt/stars

set my_red_star = 1000
set my_orange_star = 900
set my_purple_question = 800
set my_yellow_bang = 600
set my_blue_star = 500
set my_green_star = 400
set my_magenta_question = 300
set my_green_check = 200
set my_blue_info = 100
set my_del_star = 0

macro index sr "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_red_star<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with RED"
macro index so "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_orange_star<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with ORANGE"
macro index sm "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_magenta_question<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with MAGENTA"
macro index sp "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_purple_question<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with MAGENTA"
macro index sy "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_yellow_bang<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with YELLOW"
macro index sg "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_green_star<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with GREEN"
macro index sc "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_green_check<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with GREEN (check)"
macro index si "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_blue_info<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with BLUE"
macro index sb "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_blue_star<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter>" "Mark the current message with BLUE STAR"
macro index sd "<enter-command>set pipe_decode=no<enter><pipe-entry>~/bin/stars $my_del_star<enter><pipe-entry>~/bin/del_stars<enter><enter-command>set pipe_decode=yes<enter><enter-command>source ~/.muttrc<enter><sync-mailbox>" "Remove color marking from the current message"

macro pager sr "<pipe-entry>~/bin/stars $my_red_star<enter><next-undeleted>" "Mark the current message with RED"
macro pager so "<pipe-entry>~/bin/stars $my_orange_star<enter><previous-undeleted><enter-command>source ~/.muttrc<enter>" "Mark the current message with ORANGE"
macro pager sm "<pipe-entry>~/bin/stars $my_magenta_question<enter><next-undeleted>" "Mark the current message with MAGENTA"
macro pager sp "<pipe-entry>~/bin/stars $my_purple_question<enter>" "Mark the current message with MAGENTA"
macro pager sy "<pipe-entry>~/bin/stars $my_yellow_bang<enter><next-undeleted>" "Mark the current message with YELLOW"
macro pager sg "<pipe-entry>~/bin/stars $my_green_star<enter><next-undeleted>" "Mark the current message with GREEN"
macro pager sc "<pipe-entry>~/bin/stars $my_green_check<enter><next-undeleted>" "Mark the current message with GREEN (check)"
macro pager si "<pipe-entry>~/bin/stars $my_blue_info<enter><next-undeleted>" "Mark the current message with BLUE"
macro pager sb "<pipe-entry>~/bin/stars $my_blue_star<enter><next-undeleted>" "Mark the current message with BLUE STAR"
macro pager sd "<pipe-entry>~/bin/stars $my_del_star<enter><pipe-entry>~/bin/del_stars<enter><next-undeleted><sync-mailbox>" "Remove color marking from the current message"
macro index,pager \ci "<pipe-message> less<Enter>" "call less to extract URLs out of a message"

source ~/.mutt/mutt-gruvbox/colors-gruvbox-shuber.muttrc
#source ~/.mutt/solarized-dark-256-colors.muttrc
#source ~/.mutt/solarized-light-256-colors.muttrc
#source ~/.mutt/solarized-light-16-colors.muttrc
# Colors for items in the index
#color index brightcyan default ~N
#color index brightred default ~O
#color index brightyellow default ~F
#color index white green ~T
#color index blue default ~D
color index black color175 '~n 1900-2000'  # Mark the message with pink!
color index white color196 '~n 1000-1100'  # Mark the message with red!
color index color128 default '~n 300-399'  # Mark the message with magenta!
color index black color220 '~n 600-799'  # Mark the message with yellow!
#color index white color2 '~n 600-799'  # Mark the message with yellow!
color index white color20 '~n 500-599'  # Mark the message with blue star!
color index black color40 '~n 400-499'  # Mark the message with green!
color index white color128 '~n 800-999'  # Mark the message with magenta!
color index color40 default '~n 200-299'  # Mark the message with green (check)!
color index blue default '~n 100-199'  # Mark the message with blue!
color index white color208 '~n 900-999'  # Mark the message with orange!
color indicator black white
#color indicator white black
#mono index bold ~N
#mono index bold ~F
#mono index bold ~T
#mono index bold ~D
#
### Highlights inside the body of a message
#
### URLs
#
#color body brightgreen default "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
#color body brightgreen default "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
#mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
#mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
#
### Email addresses.                                                                                                                                                       
#color body brightgreen default "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
#
### Header                                                                                                                                                                 
#color header green default "^from:"
#color header green default "^to:"
#color header green default "^cc:"
#color header green default "^date:"
#color header yellow default "^newsgroups:"
#color header yellow default "^reply-to:"
#color header brightcyan default "^subject:"
#color header red default "^x-spam-rule:"
#color header green default "^x-mailer:"
#color header yellow default "^message-id:"
#color header yellow default "^Organization:"
#color header yellow default "^Organisation:"
#color header yellow default "^User-Agent:"
#color header yellow default "^message-id: .*pine"
#color header yellow default "^X-Fnord:"
#color header yellow default "^X-WebTV-Stationery:"
#
#color header red default "^x-spam-rule:"
#color header green default "^x-mailer:"
#color header yellow default "^message-id:"
#color header yellow default "^Organization:"
#color header yellow default "^Organisation:"
#color header yellow default "^User-Agent:"
#color header yellow default "^message-id: .*pine"
#color header yellow default "^X-Fnord:"
#color header yellow default "^X-WebTV-Stationery:"
#color header yellow default "^X-Message-Flag:"
#color header yellow default "^X-Spam-Status:"
#color header yellow default "^X-SpamProbe:"
#color header red default "^X-SpamProbe: SPAM"
#
### Coloring quoted text - coloring the first 7 levels:                                                                                                                    
#color quoted cyan 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
#
### Default color definitions                                                                                                                                              
##color hdrdefault white green                                                                                                                                             
#color signature brightmagenta default
#color indicator default cyan
#color attachment default green
#color error red default
#color message white default
#color search brightwhite magenta
#color status brightyellow blue
#color tree brightblue default
#color normal white default
#color tilde green default
#color bold brightyellow default
##color underline magenta default                                                                                                                                            
#color markers brightcyan default
#
### Colour definitions when on a mono screen                                                                                                                               
#mono bold bold
#mono underline underline
#mono indicator reverse
