Skip to content

Commit 7f90575

Browse files
committed
Add basic mutt account management
.muttrc now selects an account configuration file to use via the ACCOUNT environment variable. To accomplish this, mutt sources .mutt/util/load-account on startup which loads .mutt/accounts/${ACCOUNT} (or ${ACCOUNT}.asc using GnuPG if encrypted). Each account file may contain arbitrary mutt configuration. Per-provider settings are stored in ~/.mutt/providers. Account configuration files may simply source the relevant provider configuration they wish to use to load provider-common settings. This commit adds a provider configuration file for Gmail. For easy account selection, an executable called ml (shortened "mail") is added to .dotfiles/bin. ml accepts a full or partial account configuration file name as the first argument and launches mutt with that account. For example, to launch mutt with an account located in ~/.mutt/accounts/[email protected], ml may be invoked as one of: $ ml [email protected] $ ml example ml exits without launching mutt if no accounts or multiple accounts match the specified argument. If ACCOUNT is unset, mutt will start with the default configuration (opening the current user's local mailbox).
1 parent a4777fc commit 7f90575

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

.dotfiles/bin/ml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
d=~/.mutt/accounts
4+
config=$(find "${d}" -type f -iname "*${1}*" -printf "%f\n" 2>/dev/null)
5+
6+
if [ "${#}" -lt 1 ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then
7+
bn=$(basename "${0}")
8+
{
9+
echo "${bn}: Launch mutt with the specified account configuration file"
10+
echo "Usage: ${bn} account"
11+
if [ -n "${config}" ]; then
12+
echo
13+
echo "Available accounts:"
14+
echo "${config}" | sort
15+
else
16+
echo "No accounts are available."
17+
echo "Place account configuration files in ${d}."
18+
fi
19+
} >&2
20+
exit 1
21+
fi
22+
23+
if [ "$(echo "${config}" | wc -l)" -gt 1 ]; then
24+
{
25+
echo "Multiple accounts found for \"${1}\":"
26+
echo "${config}" | sort
27+
} >&2
28+
exit 1
29+
elif [ -z "${config}" ]; then
30+
echo "No accounts found for \"${1}.\"" >&2
31+
exit 1
32+
fi
33+
34+
ACCOUNT="$(basename "${config}" .asc)" mutt

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
!.mailcap
2727
!.mutt/
2828
.mutt/cache
29+
.mutt/accounts
2930
!.muttrc
3031
!.screenrc
3132
!.tmux.conf

.mutt/providers/gmail.rc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Much of this configuration is from:
2+
# https://dev.mutt.org/trac/wiki/UseCases/Gmail
3+
#
4+
# Before sourcing this file, set the following mutt configuration values:
5+
# $from, $realname, $imap_pass, and $smtp_pass
6+
7+
set imap_user = $from
8+
set smtp_url = "smtp://[email protected]:587/"
9+
10+
set folder = "imaps://imap.gmail.com:993"
11+
set spoolfile = "+INBOX"
12+
set postponed = "+[Gmail]/Drafts"
13+
set record = ""
14+
15+
# Check for new mail in subscribed IMAP folders on initial connection
16+
set imap_check_subscribed
17+
18+
# Use goobook for address book queries
19+
set query_command = "goobook query %s"
20+
bind editor <Tab> complete-query
21+
bind editor ^T complete
22+
23+
set trash = "imaps://imap.gmail.com/[Gmail]/Trash"
24+
25+
# Accept IMAP folder names containing spaces in the line editor
26+
bind editor <space> noop
27+
macro index,pager y "<save-message>=[Gmail]/All Mail<enter><enter>" "Archive"
28+
macro index,pager d "<save-message>=[Gmail]/Trash<enter><enter>" "Trash"
29+
macro index gi "<change-folder>=INBOX<enter>" "Go to inbox"
30+
macro index ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail"
31+
macro index gs "<change-folder>=[Gmail]/Sent Mail<enter>" "Go to sent mail"
32+
macro index gS "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages"
33+
macro index gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts"
34+
35+
# vim: set ft=muttrc fdls=0 fdm=marker:

.mutt/util/load-account

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
a=~/.mutt/accounts/"${ACCOUNT}"
6+
7+
if [ -r "${a}.asc" ]; then
8+
gpg -d "${a}.asc"
9+
elif [ -f "${a}" ] && [ -r "${a}" ]; then
10+
cat "${a}"
11+
fi

.muttrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,10 @@ source ~/.mutt/gpg.rc
194194

195195
# }}}
196196

197+
# Account selection {{{
198+
199+
source "~/.mutt/util/load-account |"
200+
201+
# }}}
202+
197203
# vim: set fdls=0 fdm=marker:

0 commit comments

Comments
 (0)