A wizard that autocreates an offline email setup for (neo)mutt with isync/mbsync
Log | Files | Refs | README | LICENSE

commit d951fb64c587bf909fe6e0130a689a94c4055296
parent ce78b37dc21ebe8436e1f0639942847ef56d8f4c
Author: Luke Smith <>
Date:   Tue, 12 Nov 2019 06:17:45 -0500

Merge branch 'master' of

MMakefile | 1+ | 4++--
Mbin/mailsync | 5+++--
Mbin/mw | 18++++++++++++++++--
Mshare/domains.csv | 14++++++++++----
Mshare/mutt-wizard.muttrc | 4++--
6 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile @@ -30,5 +30,6 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/$$script; \ done rm -rf $(DESTDIR)$(PREFIX)/share/mutt-wizard + rm -f $(DESTDIR)$(MANPREFIX)/man1/mw.1 .PHONY: install uninstall diff --git a/ b/ @@ -110,9 +110,9 @@ mutt-wizard is free/libre software, licensed under the GPLv3. - In `/usr/share/mutt-wizard` are several global config files, including `mutt-wizard`'s default settings. You can overwride this in your `muttrc` if you wish. ## Watch out for these things: - -- For Gmail accounts, remember also to enable third-party ("""less secure""") applications before attempting installation. You might also need to manually "Enable IMAP" in the settings. +- Gmail accounts can now create 'App Password' to use with """less secure""" applications. This password is single use (ie. for setup) and will be stored and encrypted locally. Enabling third-party applications requires turning off two-factor authentication and this will circumvent that. You might also need to manually "Enable IMAP" in the settings. - Protonmail accounts will require you to set up "Protonmail Bridge" to access PM's IMAP and SMTP servers. Configure that before running mutt-wizard. +- Protonmail bridge is prone to timing out. Watch out for this while adding an account. If the bridge times out, try again. - If you have a university email, or enterprise-hosted email for work, there might be other hurdles or two-factor authentication you have to jump through. Some, for example, will want you to create a separate IMAP password, etc. - `isync` is not fully UTF-8 compatible, so non-Latin characters may be garbled (although sync should succeed). `mw` will also not autocreate mailbox shortcuts since it is looking for English mailbox names. I strongly recommend you to set your email language to English on your mail server to avoid these problems. diff --git a/bin/mailsync b/bin/mailsync @@ -2,12 +2,13 @@ # Sync mail and give notification if there is new mail. export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus +DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus +export DBUS_SESSION_BUS_ADDRESS export DISPLAY=:0.0 [ -d "$HOME/.local/share/password-store" ] && export PASSWORD_STORE_DIR="$HOME/.local/share/password-store" # Run only if user logged in (prevent cron errors) -pgrep -u "$USER" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;} +pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;} # Run only if not already running in other instance pgrep -x mbsync >/dev/null && { echo "mbsync is already running." ; exit ;} diff --git a/bin/mw b/bin/mw @@ -134,8 +134,22 @@ askinfo() { \ printf "\033[0m" done domain="$(echo "$fulladdr" | sed "s/.*@//")" + search_query=$domain + case "$domain" in +|| + search_query='' && break;; + *) + while : ; do + printf "\nIs your email hosted with Protonmail? [yes/no] " + read -r is_protonmail + case $is_protonmail in + [Yy][Ee][Ss]) search_query='' && break;; + [Nn][Oo]) break;; + *) printf 'Please answer Yes or No' + esac; done; + esac printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain" - serverinfo="$(grep "^$domain" "$muttshare/domains.csv" 2>/dev/null)" + serverinfo="$(grep "^$search_query" "$muttshare/domains.csv" 2>/dev/null)" if [ -z "$serverinfo" ]; then printf "Your email domain is not in mutt-wizard's database yet.\\nmutt-wizard will still autoconfigure everything, but you will have to manually type in your service's IMAP and SMTP server information.\\nYou can usually quickly find this by internet searching for it.\\n" printf "Insert the IMAP server for your email provider (excluding the port number)\\n\033[36m\t" @@ -194,7 +208,7 @@ EOF } protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n" - fingerprint="$(msmtp --serverinfo --host= --port=1025 --tls --tls-certcheck=off)" || return 1 + fingerprint="$(msmtp --serverinfo --host= --port=1025 --tls --tls-certcheck=off | grep SHA256: | sed 's/^.*: //')" sed -ibu "s/account $title/&\ntls_trust_file\ntls_fingerprint $fingerprint/" "$msmtprc" ; rm -f "$msmtprc"bu } diff --git a/share/domains.csv b/share/domains.csv @@ -60,7 +60,7 @@,,993,,587,,993,,465,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587 @@ -129,7 +129,7 @@,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587 @@ -143,6 +143,7 @@,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,465,,993,,465,,993,,587 @@ -170,6 +171,7 @@,,993,,587,,993,,587,,993,,465,,993,,587,,993,,587,,993,,465,,993,,587,,993,,465 @@ -212,18 +214,20 @@,,1143,,1025,,1143,,1025,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,465,,993,,587,,993,,587,,993,,465,,993,,465,,993,,587,,993,,587,,993,,587,,993,,587,,993,,587,,993,,25,,993,,465 @@ -238,7 +242,6 @@,,993,,587,,993,,465,,993,,587,,993,,587,,993,,587,,993,,587,,993,,25,,993,,587 @@ -259,6 +262,7 @@,,993,,465,,993,,587,,993,,587,,993,,587,,993,,587,,993,,465,,993,,587,,993,,587 @@ -272,3 +276,5 @@,,993,,587,,993,,587,,993,,587,,993,,465,,993,,465,,993,,587 diff --git a/share/mutt-wizard.muttrc b/share/mutt-wizard.muttrc @@ -60,9 +60,9 @@ bind pager \031 previous-line # Mouse wheel bind pager \005 next-line # Mouse wheel bind editor <Tab> complete-query -macro index,pager a "|abook --add-email\n" 'add sender to abook' +macro index,pager a "<enter-command>set my_pipe_decode=\$pipe_decode pipe_decode<return><pipe-message>abook --add-email<return><enter-command>set pipe_decode=\$my_pipe_decode; unset my_pipe_decode<return>" "add the sender address to abook" macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read" -macro index O "<shell-escape>mailsync -Va<enter>" "run offlineimap to sync all mail" +macro index O "<shell-escape>mailsync -Va<enter>" "run mbsync to sync all mail" macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'Enter a search term to find with notmuch: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;s/\^id:// for@a;$,=\"|\";print@a' | perl -le '@a=<>; chomp@a; s/\\+/\\\\+/ for@a;print@a' \`\"<enter>" "show only messages matching a notmuch pattern" macro index A "<limit>all\n" "show all messages (undo limit)"