Mutt: Refactor, bindings, save attachments to ~/temp

master
Pierre Neidhardt 2015-10-14 12:11:12 +02:00
parent ecd6786843
commit 3d84244049
10 changed files with 136 additions and 116 deletions

View File

@ -276,8 +276,9 @@ globalkeys = awful.util.table.join(
awful.key({ modkey, }, "p", function () awful.util.spawn("zathura") end),
-- Mail user agent
awful.key({ modkey, }, "m", function () awful.util.spawn(term .. "mutt") end),
awful.key({ }, "XF86Mail", function () awful.util.spawn(term .. "mutt") end),
-- Mutt needs to be started in the folder where you want to save attachments.
awful.key({ modkey, }, "m", function () awful.util.spawn(term .. "sh -c 'cd ~/temp && mutt'") end),
awful.key({ }, "XF86Mail", function () awful.util.spawn(term .. "sh -c 'cd ~/temp && mutt'") end),
-- Web browser
awful.key({ modkey, }, "w", function () awful.util.spawn_with_shell("dwb 2>>/tmp/dwb" .. uid .. ".log") end),

View File

@ -1,41 +1,40 @@
# -*- mode:sh -*-
## Mutt -- Personal account
## Mutt -- Gmail account sample
set imap_user=user@gmail.com
set imap_pass=$my_pw_personal
set from=$imap_user
set hostname="gmail.com"
set folder = imaps://user@imap.gmail.com/
set spoolfile = +INBOX
set postponed = +[Google Mail]/Drafts
set folder=imaps://user@imap.gmail.com/
set spoolfile=+INBOX
set postponed=+[Gmail]/Drafts
unset record ## Google does it automatically, so we do not want duplicates.
## Send options.
set realname='User X'
set realname='John Doe'
set smtp_url=smtps://user:$imap_pass@smtp.gmail.com
set ssl_force_tls = yes
set ssl_force_tls=yes
unset ssl_starttls
## Signatures
## Note that fortune-mod must be installed to use fortune command.
set signature="cat ~/.mutt/real_name && cat ~/.mutt/asciiribbon && fortune -s|"
## Signature with a random 'fortune'.
set signature="cat ~/.mutt/real_name && fortune -s |"
## Sidebar mailboxes separator workaround.
mailboxes "+A-- User -----------"
mailboxes "+A-- Personal -------"
## Hooks
account-hook $folder "set imap_user=user@gmail.com imap_pass=$my_pw_personal"
## Reset PGP send-hooks.
## TODO: unhook does not seem to be working.
unhook send-hook
send-hook . 'unset pgp_autosign; unset pgp_autoencrypt'
## Remove your e-mail from group-reply.
## Remove own e-mail address from group-reply.
alternates $imap_user
## Gmail-specific macros:
## Prevent Gmail from deleting to 'All Mail', move it to Trash instead.
# macro index d ";s+[Gmail]/Trash<enter><enter>" "Move to Gmail's Trash"
# macro pager d "s+[Gmail]/Trash<enter><enter>" "Move to Gmail's Trash"
macro index d ";s+[Gmail]/Trash<enter><enter>" "Move to Gmail's Trash"
macro pager d "s+[Gmail]/Trash<enter><enter>" "Move to Gmail's Trash"
## Undelete messages.
# macro index u ";s+INBOX<enter><enter>" "Move to Gmail's INBOX"
# macro pager u "s+INBOX<enter><enter>" "Move to Gmail's INBOX"
macro index u ";s+INBOX<enter><enter>" "Move to Gmail's INBOX"
macro pager u "s+INBOX<enter><enter>" "Move to Gmail's INBOX"

3
.mutt/colors.classic.sh → .mutt/colors.classic Executable file → Normal file
View File

@ -1,7 +1,5 @@
#!/bin/sh
## 256 colors classic theme
cat <<EOF
set my_bg = black
set my_new = brightcyan
set my_old = brightred
@ -36,4 +34,3 @@ set my_quote4 = color32
set my_quote5 = color33
set my_quote6 = color39
set my_quote7 = color38
EOF

3
.mutt/colors.zenburn.sh → .mutt/colors.zenburn Executable file → Normal file
View File

@ -1,7 +1,5 @@
#!/bin/sh
## 256 colors Zenburn theme
cat <<EOF
set my_bg = color237
set my_new = color142
set my_old = color172
@ -36,4 +34,3 @@ set my_quote4 = color32
set my_quote5 = color33
set my_quote6 = color39
set my_quote7 = color38
EOF

View File

@ -1,24 +1,24 @@
## -*- mode:sh -*- #
## Mutt Configuration
## Note on folders:
## This configuration is made for Mutt with embedded IMAP support.
## These folders are assumed to exist:
## ~/.mutt.d: personal stuff (contacts, account information).
## ~/.mutt: public stuff (theme, mailcap).
## ~/.cache/mutt: header cache.
## ~/.mutt: public stuff (config, theme, mailcap).
## ~/.cache/mutt: cache for headers and messages.
################################################################################
## General options
## General options.
## Beep on new incoming mails.
set beep_new = "yes"
set beep_new=yes
set crypt_replyencrypt = yes
set crypt_replysign = yes
set crypt_replysignencrypted = yes
set crypt_use_gpgme = yes
set pgp_timeout = 3600
# set pgp_use_gpg_agent = yes
## PGP options.
set crypt_replyencrypt=yes
set crypt_replysign=yes
set crypt_replysignencrypted=yes
set crypt_use_gpgme=yes
set pgp_timeout=3600
## Headers are editable in editor.
set edit_headers=yes
@ -26,7 +26,8 @@ set edit_headers=yes
## Set EDITOR dynamically.
source "~/.mutt/maileditor.sh|"
## Reply fast
## Don't ask for recipient. We usually don't want to include mail unless we want
## to quote it.
set fast_reply=yes
set include=ask-no
set include_onlyfirst=yes
@ -34,79 +35,62 @@ set include_onlyfirst=yes
## Store message headers locally to speed things up. Gentoo wiki says that if a
## folder is specified, it is even faster. If no folder exists, the cache will
## be a single file.
set header_cache = "~/.cache/mutt"
set message_cachedir = "~/.cache/mutt_msg"
source "~/.mutt/cachepurge.sh|"
set header_cache=~/.cache/mutt/headers
set message_cachedir=~/.cache/mutt/messages
source "~/.mutt/purgecache.sh '$message_cachedir'|"
## Tell Mutt to check all IMAP folders. This will add all of them to the
## sidebar. Contrary to the manu 'mailboxes' way, order cannot be controlled, so
## you should set 'sidebar_sort' to yes. This will sort the folders
## alphabetically, ignoring punctuation.
## Tell Mutt to check all IMAP folders. This will add all of them to the sidebar
## (if used). Contrary to the 'mailboxes' menu, sorting order cannot be
## controlled, so you should set 'sidebar_sort' to yes. This will sort the
## folders alphabetically, ignoring punctuation.
set imap_check_subscribed
## Keep imap connection alive by polling intermittently (time in seconds).
set imap_keepalive = 30
set imap_keepalive=30
## Allow mutt to open new imap connection automatically.
unset imap_passive
## How often to check for new mail (time in seconds).
set mail_check=60
## Mailcap
set mailcap_path = ~/.mutt/mailcap
set mailcap_path=~/.mutt/mailcap
auto_view text/html
alternative_order text/plain text/html
## How often to check for new mail (time in seconds).
set mail_check = 60
## Mailbox type.
set mbox_type=Maildir
## Forward attachment as well
## Forward attachment as well.
set mime_forward=yes
set mime_forward_rest=yes
## Keep showing the list of mails while in pager.
set pager_index_lines=8
## Show context lines when going to next page and stop at the end instead of
## displaying next mail.
# set menu_context=3
set pager_context=3
set pager_stop=yes
## Encoding
## Encoding.
set rfc2047_parameters=yes
set send_charset="us-ascii:utf-8"
## Remove delay between mailbox switches.
set sleep_time = 0
set sleep_time=0
set sort = threads
set sort_aux = last-date-received
set strict_threads = yes
## Group mail into conversations, sort by last mail from conversation.
set sort=threads
set sort_aux=last-date-received
set strict_threads=yes
################################################################################
## Multiple accounts
## accountrc should contain the following config:
## Set account names (arbitrary).
# set my_ac_personal=personal
# set my_ac_work=work
#
## Fetch passwords
# source "ccat ~/.mutt.pwds.cpt |"
## Or
# source "gpg2 -dq ~/.mutt.pwds.gpg |"
##
## Folder hooks, one per account.
# source "~/.mutt.d/$my_ac_personal"
# folder-hook $folder 'source ~/.mutt.d/$my_ac_personal'
# source "~/.mutt.d/$my_ac_work"
# folder-hook $folder 'source ~/.mutt.d/$my_ac_work'
##
## Optionnaly you can add shortcuts to switch mailboxes:
# macro index,pager <f2> '<enter-command>source ~/.mutt.d/$my_ac_personal<enter><change-folder>!<enter>'
# macro index,pager <f3> '<enter-command>source ~/.mutt.d/$my_ac_work<enter><change-folder>!<enter>'
## Store passwords as follows in .mutt.pwds:
# set my_pw_account = foo
# set my_pw_personal = foo
# set my_pw_work = foo
##
## CCRYPT:
## $ ccencrypt .mutt.pwds
@ -116,29 +100,46 @@ set strict_threads = yes
## Encrypt them with:
## $ gpg2 -e -r <user> ".mutt.pwds"
## 'accountrc' should contain the following config:
## Fetch passwords
# source "ccat ~/.mutt.pwds.cpt |"
## Or
# source "gpg2 -dq ~/.mutt.pwds.gpg |"
##
## Source accounts. Default account is last.
# source "~/.mutt.d/personal"
# folder-hook $folder 'source ~/.mutt.d/personal'
# source "~/.mutt.d/work"
# folder-hook $folder 'source ~/.mutt.d/work'
##
## You can add an optional binding to switch mailboxes:
# macro index,pager <f2> '<enter-command>source ~/.mutt.d/personal<enter><change-folder>!<enter>'
# macro index,pager <f3> '<enter-command>source ~/.mutt.d/work<enter><change-folder>!<enter>'
source "~/.mutt.d/accountrc"
################################################################################
## Aliases
## Aliases.
## Mutt native support
## Mutt native support.
# set alias_file = "~/.mutt.d/aliases"
# set sort_alias = alias
# set reverse_alias = yes
# source $alias_file
## Abook
## Abook.
## We redirect the error stream in case the config file in not compatible with
## current abook bersion.
set query_command= "abook --mutt-query '%s' 2>/dev/null"
macro index,pager a "<pipe-message>abook --add-email-quiet<return>" "Add this sender to Abook"
bind editor <Tab> complete-query
## current Abook version.
set query_command="abook --mutt-query '%s' 2>/dev/null"
macro index,pager a "<pipe-message>abook --add-email-quiet<return>" "Add this sender to Abook"
bind editor <Tab> complete-query
################################################################################
## Keys
## Key bindings.
## Security issue: if enter-command is available from the GUI, it is possible to
## see the password unencrypted. We disable it for this reason. Every command
## Security issue: if 'enter-command' is available from the GUI, it is possible
## to see the password unencrypted. We disable it for this reason. Every command
## that the user intends to use must be bound to a key in advance, otherwise it
## will never be accessible.
bind generic,alias,attach,browser,editor,index,compose,pager,pgp,postpone ':' noop
@ -149,7 +150,7 @@ macro attach 'V' "<pipe-entry>cat >~/.cache/mutt/mutt-attach.mail && $BROWSER ~/
## Remap bounce-message function to "B"
bind index B bounce-message
## Always reply to group
## Always reply to group.
bind index,pager r group-reply
## Fix the 'change-dir' issue with multiple accounts. When change-dir was called
@ -168,8 +169,32 @@ bind index "^" imap-fetch-mail
## Changed kbs=^H to kbs=\177, then:
## $ tic -x termbs.src
## Vi/Emacs bindings.
bind pager j next-line
bind pager k previous-line
bind attach,index,pager \CD next-page
bind attach,index,pager \CU previous-page
bind attach,index,pager ? search-reverse
bind attach,index,pager h help
bind attach,index,pager \Ch display-toggle-weed
bind attach,index,pager N search-opposite
bind index <Esc>n toggle-new
bind pager <Esc>n mark-as-new
bind index <Esc>x collapse-thread
bind index <Esc>X collapse-all
bind attach,index,pager \CV next-page
bind attach,index,pager <Esc>v previous-page
bind pager g top
bind pager G bottom
bind pager <Esc>< top
bind pager <Esc>> bottom
bind attach,index g first-entry
bind attach,index G last-entry
bind attach,index <Esc>< first-entry
bind attach,index <Esc>> last-entry
################################################################################
## Custom headers for outgoing mail
## Custom header for outgoing mail.
## Undo any custom headers that may have been put in by the global Muttrc
# unmy_hdr *
@ -187,14 +212,14 @@ my_hdr X-Info: Simplicity is the ultimate sophistication.
# my_hdr X-Operating-System: `uname -s`, kernel `uname -r`
## This header only appears to MS Outlook users
# my_hdr X-Message-Flag: WARNING!! Outlook sucks!
# my_hdr X-Message-Flag: Warning: Outlook sucks!
## Custom Mail-User-Agent ID.
set user_agent = yes
set user_agent=yes
# my_hdr User-Agent: Every email client sucks, this one just sucks less.
################################################################################
## Themes
## Theme.
## Index format
## We use my_col_* to get dynamic column size.
@ -202,28 +227,31 @@ set user_agent = yes
# set index_format="%?M?_%M_ ?%Z %2C %.13d (%-68.68F) %-68.68s %?M?_%M_&(%c/%l?"
set date_format="%y-%m-%d %T"
folder-hook .*[sS]ent.* 'set my_col_from = `echo $((30 * ($(tput cols)-35-24) / 100))`; set my_col_subject = `echo $((70 * ($(tput cols)-35-24) / 100))`; set index_format="%2C | %Z [%d] %-$my_col_from.${my_col_from}t (%-4.4c) %?M?<%M> ?%-$my_col_subject.${my_col_subject}s"'
folder-hook ! .*[sS]ent.* 'set my_col_from = `echo $((30 * ($(tput cols)-35-24) / 100))`; set my_col_subject = `echo $((70 * ($(tput cols)-35-24) / 100))`; set index_format="%2C | %Z [%d] %-$my_col_from.${my_col_from}F (%-4.4c) %?M?<%M> ?%-$my_col_subject.${my_col_subject}s"'
set my_index_format_pre='set my_col_from = `echo $((30 * ($(tput cols)-35-24) / 100))`; set my_col_subject = `echo $((70 * ($(tput cols)-35-24) / 100))`; set index_format="%2C | %Z [%d] %-$my_col_from.${my_col_from}'
set my_index_format_post=' (%-4.4c) %?M?<%M> ?%-$my_col_subject.${my_col_subject}s"'
folder-hook .*[sS]ent.* "$my_index_format_pre"t"$my_index_format_post"
folder-hook ! .*[sS]ent.* "$my_index_format_pre"F"$my_index_format_post"
## Original status_format, with dash line removed.
set status_format="-%r-Mutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?] (%s/%S) %> (%P) "
## This will redraw screen while refreshing the new cols value. Since there
## seems to be no way to check what folder is the current, this will not behave
## like the above hooks and will set the index_format correctly for non Sent
## folders only.
macro pager \CL '<enter-command>set my_col_from = `echo $((30 * ($(tput cols)-35-24) / 100))`; set my_col_subject = `echo $((70 * ($(tput cols)-35-24) / 100))`; set index_format="%2C | %Z [%d] %-$my_col_from.${my_col_from}F (%-4.4c) %-$my_col_subject.${my_col_subject}s"<enter><redraw-screen>'
## This will redraw screen and justify the index.
macro index,pager \CL "<enter-command>$my_index_format_pre"F"$my_index_format_post<enter><redraw-screen>"
## Colors
# source "/usr/share/doc/mutt/samples/colors.default"
# source "/usr/share/doc/mutt/samples/colors.linux"
# source "~/.mutt/colors.classic.sh|"
source "~/.mutt/colors.zenburn.sh|"
source "~/.mutt/colors.fallback.sh|"
source "~/.mutt/mutt.colors"
## Set color variables from a theme.
# source "~/.mutt/colors.classic"
source "~/.mutt/colors.zenburn"
## Fallback for terminals without 256 colors. This needs to be a shell script so
## that it can check for terminal capabilities.
source "~/.mutt/colors.fallback.sh |"
## Apply theme.
source "~/.mutt/theme"
################################################################################
## Sidebar
## Sidebar.
## We use a script to test if sidebar is installed. Needs to be loaded _after_
## the theme.

View File

@ -1,13 +1,14 @@
#!/bin/sh
## Purge old message in Mutt's message cache.
## Purge old messages in Mutt's message cache.
## "$1" is cache location.
## This is intended to be run at startup, but can be run manually anytime.
## It should not output anything to stdout.
## In KB.
CACHE_LIMIT=51200
cd ~/.cache/mutt_msg 2>/dev/null
cd "$1" 2>/dev/null
[ $? -ne 0 ] && exit
[ $(du -s . | cut -f1 -d' ') -lt $CACHE_LIMIT ] && exit

View File

@ -20,10 +20,7 @@ bind index,pager \CP sidebar-prev
bind index,pager \CN sidebar-next
bind index,pager \CO sidebar-open
## Toggle sidebar visibility
# macro index b '<enter-command>toggle sidebar_visible<enter>'
# macro pager b '<enter-command>toggle sidebar_visible<enter>'
## Prevent messy output
## Toggle sidebar visibility. Screen might get messed up, hence the refresh.
macro index b '<enter-command>toggle sidebar_visible<enter><refresh>'
macro pager b '<enter-command>toggle sidebar_visible<enter><redraw-screen>'
EOF

View File

@ -7,7 +7,6 @@ set -- "$HOME/.cache/dwb" \
"$HOME/.cache/emacs/ido.last" \
"$HOME/.cache/emacs/saveplace" \
"$HOME/.cache/mutt" \
"$HOME/.cache/mutt_msg" \
"$HOME/.cache/rtorrent" \
"$HOME/.cache/zsh" \
"$HOME/.cmus/autosave" \

View File

@ -20,7 +20,8 @@ fi
if command -v mutt >/dev/null 2>&1; then
echo "==> Mutt"
[ -d "$SOURCEDIR" ] && ln -snf "$SOURCEDIR/mails" "$HOME/.mutt.d"
mkdir -p "$HOME/.cache/mutt/"
mkdir -p "$HOME/.cache/mutt/headers"
mkdir -p "$HOME/.cache/mutt/messages"
echo
fi