Merge branch 'master' of github.com:LukeSmithxyz/mutt-wizard

This commit is contained in:
Luke Smith 2020-05-31 20:47:38 -04:00
commit 3d320f28c5
No known key found for this signature in database
GPG Key ID: 4C50B54A911F6252
4 changed files with 21 additions and 12 deletions

View File

@ -3,13 +3,13 @@
Get this great stuff without effort: Get this great stuff without effort:
- A full-featured and autoconfigured email client on the terminal with neomutt - A full-featured and autoconfigured email client on the terminal with neomutt
- Mail stored offline so you can view and write email while away from internet and keep backups - Mail stored offline so you can view and write email while you're away from internet and keep backups
Specifically, this wizard: Specifically, this wizard:
- Determines your email server's IMAP and SMTP servers and ports - Determines your email server's IMAP and SMTP servers and ports
- Creates dotfiles for `neomutt`, `isync`, and `msmtp` appropriate for your email address - Creates dotfiles for `neomutt`, `isync`, and `msmtp` appropriate for your email address
- Encrypts and stores locally your password for easy remote access, accessible only by your GPG key - Encrypts and locally stores your password for easy remote access, accessible only by your GPG key
- Handles as many as nine separate email accounts automatically - Handles as many as nine separate email accounts automatically
- Auto-creates bindings to switch between accounts or between mailboxes - Auto-creates bindings to switch between accounts or between mailboxes
- Can automatically set mail updates as often as you want to sync your mail and update you when new mail arrives - Can automatically set mail updates as often as you want to sync your mail and update you when new mail arrives
@ -112,5 +112,5 @@ mutt-wizard is free/libre software, licensed under the GPLv3.
## To-do ## To-do
- Add ~~Mac OS~~/BSD compatibility (the script is confired to work for Mac OS now) - Add ~~Mac OS~~/~~BSD~~ compatibility (the script is confirmed to work for Mac OS and FreeBSD now)
- ~~Out-of-the-box compatibility with Protonmail Bridge~~ (I believe this is done, but more bug-testing is welcome since I don't have PM) - ~~Out-of-the-box compatibility with Protonmail Bridge~~ (I believe this is done, but more bug-testing is welcome since I don't have PM)

View File

@ -12,7 +12,7 @@ ping -q -c 1 1.1.1.1 > /dev/null || { echo "No internet connection detected."; e
command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script." command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script."
# Required to display notifications if run as a cronjob: # Required to display notifications if run as a cronjob:
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
export DISPLAY=:0.0 export DISPLAY=:0.0
# For individual configurations: # For individual configurations:
@ -21,7 +21,7 @@ export DISPLAY=:0.0
# Settings are different for MacOS (Darwin) systems. # Settings are different for MacOS (Darwin) systems.
if [ "$(uname)" = "Darwin" ]; then if [ "$(uname)" = "Darwin" ]; then
notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;}
messageinfo() { osascript "display notification with title \"📧 $from\" subtitle \"$subject\"" ;} messageinfo() { osascript -e "display notification with title \"📧 $from\" subtitle \"$subject\"" ;}
else else
notify() { notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." ;} notify() { notify-send --app-name="mutt-wizard" "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." ;}
messageinfo() { notify-send --app-name="mutt-wizard" "📧$from:" "$subject" ;} messageinfo() { notify-send --app-name="mutt-wizard" "📧$from:" "$subject" ;}
@ -30,7 +30,7 @@ fi
# Check account for new mail. Notify if there is new content. # Check account for new mail. Notify if there is new content.
syncandnotify() { syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")" acc="$(echo "$account" | sed "s/.*\///")"
mbsync $opts "$acc" mbsync "$opts" "$acc"
new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null) new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then if [ "$newcount" -gt "0" ]; then
@ -38,7 +38,7 @@ syncandnotify() {
for file in $new; do for file in $new; do
# Extract subject and sender from mail. # Extract subject and sender from mail.
from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//') from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n-1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n') subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
messageinfo & messageinfo &
done done
fi fi

17
bin/mw
View File

@ -3,11 +3,11 @@
command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2" command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
[ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store" [ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store"
[ -r "$PASSWORD_STORE_DIR/.gpg-id" ] && [ -r "$PASSWORD_STORE_DIR/.gpg-id" ] &&
"$GPG" --list-secret-keys $(cat "$PASSWORD_STORE_DIR/.gpg-id") >/dev/null 2>&1 || { "$GPG" --list-secret-keys "$(cat "$PASSWORD_STORE_DIR/.gpg-id")" >/dev/null 2>&1 || {
printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`%s --full-gen-key\` first.\\n" "$GPG" printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`%s --full-gen-key\` first.\\n" "$GPG"
exit exit
} }
! command -v mbsync >/dev/null && printf "\`mbsync\` must be installed to run mutt-wizard.\\n" && exit ! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit
prefix="/usr/local" prefix="/usr/local"
muttdir="$HOME/.config/mutt" # Main mutt config location muttdir="$HOME/.config/mutt" # Main mutt config location
@ -86,6 +86,9 @@ set folder = \"$maildir/$title\"
set header_cache = $cachedir/$title/headers set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies set message_cachedir = $cachedir/$title/bodies
set mbox_type = Maildir set mbox_type = Maildir
set crypt_opportunistic_encrypt = yes
set pgp_self_encrypt = yes
set pgp_default_key = $keyid
bind index,pager gg noop bind index,pager gg noop
bind index,pager g noop bind index,pager g noop
@ -108,6 +111,11 @@ set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies set message_cachedir = $cachedir/$title/bodies
set imap_pass = \"\`pass mutt-wizard-$title\`\" set imap_pass = \"\`pass mutt-wizard-$title\`\"
set crypt_opportunistic_encrypt = yes
set pgp_self_encrypt = yes
set pgp_default_key = $keyid
set mbox_type = Maildir set mbox_type = Maildir
set ssl_starttls = yes set ssl_starttls = yes
set ssl_force_tls = yes set ssl_force_tls = yes
@ -126,6 +134,7 @@ fi
askinfo() { \ askinfo() { \
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m" printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m"
read -r fulladdr read -r fulladdr
keyid=$( gpg --list-keys --with-colons "$fulladdr" | awk -F: '/^pub:/ { print $5 }')
printf "\033[0m" printf "\033[0m"
while ! echo "$fulladdr" | grep "$emailre" >/dev/null; do while ! echo "$fulladdr" | grep "$emailre" >/dev/null; do
printf "That is not a valid \033[31memail address\033[0m, please retype the desired email.\\n\\nEmail: \033[36m\t" printf "That is not a valid \033[31memail address\033[0m, please retype the desired email.\\n\\nEmail: \033[36m\t"
@ -136,7 +145,7 @@ askinfo() { \
search_query=$domain search_query=$domain
case "$domain" in case "$domain" in
protonmail.com|protonmail.ch|pm.me) protonmail.com|protonmail.ch|pm.me)
search_query='protonmail.com' && break;; search_query='protonmail.com' && return 1;;
*) *)
while : ; do while : ; do
printf "\nIs your email hosted with Protonmail? [yes/no] " printf "\nIs your email hosted with Protonmail? [yes/no] "
@ -330,7 +339,7 @@ synchronize_flags=true
gpg_path=$GPG" gpg_path=$GPG"
echo "$nmbasic" > "$NOTMUCH_CONFIG" ;} echo "$nmbasic" > "$NOTMUCH_CONFIG" ;}
trap 'echo -e "\033[0m\n"; exit' STOP INT ABRT KILL trap 'echo -e "\033[0m\n"; exit' INT ABRT
case "$1" in case "$1" in
ls) list ;; ls) list ;;

2
mw.1
View File

@ -6,7 +6,7 @@ mw \- mutt-wizard \- autoconfigure email accounts for neomutt and isync
<command> <command>
.SH DESCRIPTION .SH DESCRIPTION
.B mw .B mw
takes a user email account and sets up a terminal-based email interface with it for takes a user email account and sets up a terminal-based email interface for it with
.B neomutt. .B neomutt.
This can include offline email with This can include offline email with
.B isync/mbsync .B isync/mbsync