From 06f416f5eb73c4d01df25046d17a1cfdbfb116ae Mon Sep 17 00:00:00 2001 From: Jonassenher Date: Sun, 30 Aug 2020 18:28:21 +0200 Subject: [PATCH 1/5] Support for XDG Base Directory Today's mutt-wizard does not support the XDG Base Directory specifications (https://wiki.archlinux.org/index.php/XDG_Base_Directory) because it says the user should be able to change the config, cache, data folders etc. using the environmental variables XDG_CONFIG_HOME, XDG_CACHE_HOME, and XDG_DATA_HOME, and instead hard codes the default paths ~/.config, ~/.cache, and ~/.local/share. My commit corrects this. --- bin/mw | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/mw b/bin/mw index 9f39cc4..fffc965 100755 --- a/bin/mw +++ b/bin/mw @@ -10,17 +10,17 @@ command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2" ! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit prefix="/usr/local" -muttdir="$HOME/.config/mutt" # Main mutt config location +muttdir="${XDG_CONFIG_HOME:-$HOME/.config}/mutt" # Main mutt config location accdir="$muttdir/accounts" # Directory for account settings -maildir="$HOME/.local/share/mail" # Location of mail storage +maildir="${XDG_DATA_HOME:-$HOME/.local/share}/mail" # Location of mail storage namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username emailre=".+@.+\..+" # Regex to confirm valid email address muttshare="$prefix/share/mutt-wizard" -mbsyncrc="$HOME/.mbsyncrc" +mbsyncrc="${MBSYNCRC_HOME:-$HOME/.mbsyncrc}" mwconfig="$muttshare/mutt-wizard.muttrc" -cachedir="$HOME/.cache/mutt-wizard" +cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard" muttrc="$muttdir/muttrc" -msmtprc="$HOME/.config/msmtp/config" +msmtprc="${XDG_CACHE_HOME:-$HOME/.config}/msmtp/config" ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail for x in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/" @@ -38,7 +38,7 @@ msmtp_header="defaults auth on tls on tls_trust_file $sslcert -logfile ~/.config/msmtp/msmtp.log +logfile $XDG_CONFIG_HOME/msmtp/msmtp.log " msmtp_profile="account $title host $smtp @@ -59,8 +59,8 @@ CertificateFile $sslcert MaildirStore $title-local Subfolders Verbatim -Path ~/.local/share/mail/$title/ -Inbox ~/.local/share/mail/$title/INBOX +Path $XDG_DATA_HOME/mail/$title/ +Inbox $XDG_DATA_HOME/mail/$title/INBOX Flatten . Channel $title From d60d2398869796ee1fd7e6c424afe11654e2e702 Mon Sep 17 00:00:00 2001 From: Jonassenher Date: Sun, 30 Aug 2020 19:02:15 +0200 Subject: [PATCH 2/5] Fixed the case for no environmental variables --- bin/mw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/mw b/bin/mw index fffc965..5e5a610 100755 --- a/bin/mw +++ b/bin/mw @@ -38,7 +38,7 @@ msmtp_header="defaults auth on tls on tls_trust_file $sslcert -logfile $XDG_CONFIG_HOME/msmtp/msmtp.log +logfile ${XDG_CONFIG_HOME/:-$HOME/.config}/msmtp/msmtp.log " msmtp_profile="account $title host $smtp @@ -59,8 +59,8 @@ CertificateFile $sslcert MaildirStore $title-local Subfolders Verbatim -Path $XDG_DATA_HOME/mail/$title/ -Inbox $XDG_DATA_HOME/mail/$title/INBOX +Path ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$title/ +Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$title/INBOX Flatten . Channel $title From f00fa04f15c479dd32dbd9802602f6adbcefbbed Mon Sep 17 00:00:00 2001 From: Jonassenher Date: Sun, 30 Aug 2020 19:26:10 +0200 Subject: [PATCH 3/5] Fixed mbsync using the correct rc file --- bin/mw | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/mw b/bin/mw index 5e5a610..c0c6f7a 100755 --- a/bin/mw +++ b/bin/mw @@ -10,11 +10,11 @@ command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2" ! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit prefix="/usr/local" -muttdir="${XDG_CONFIG_HOME:-$HOME/.config}/mutt" # Main mutt config location -accdir="$muttdir/accounts" # Directory for account settings +muttdir="${XDG_CONFIG_HOME:-$HOME/.config}/mutt" # Main mutt config location +accdir="$muttdir/accounts" # Directory for account settings maildir="${XDG_DATA_HOME:-$HOME/.local/share}/mail" # Location of mail storage -namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username -emailre=".+@.+\..+" # Regex to confirm valid email address +namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username +emailre=".+@.+\..+" # Regex to confirm valid email address muttshare="$prefix/share/mutt-wizard" mbsyncrc="${MBSYNCRC_HOME:-$HOME/.mbsyncrc}" mwconfig="$muttshare/mutt-wizard.muttrc" @@ -22,6 +22,7 @@ cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard" muttrc="$muttdir/muttrc" msmtprc="${XDG_CACHE_HOME:-$HOME/.config}/msmtp/config" ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail +alias mbsync='mbsync -c "$mbsyncrc"' for x in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/" do From 8b1ba846d03009e4e771725727856f58be1c33cf Mon Sep 17 00:00:00 2001 From: Jonassenher Date: Sun, 30 Aug 2020 21:22:35 +0200 Subject: [PATCH 4/5] fix --- bin/mw | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/mw b/bin/mw index c0c6f7a..57fd7b5 100755 --- a/bin/mw +++ b/bin/mw @@ -20,7 +20,7 @@ mbsyncrc="${MBSYNCRC_HOME:-$HOME/.mbsyncrc}" mwconfig="$muttshare/mutt-wizard.muttrc" cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard" muttrc="$muttdir/muttrc" -msmtprc="${XDG_CACHE_HOME:-$HOME/.config}/msmtp/config" +msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config" ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail alias mbsync='mbsync -c "$mbsyncrc"' @@ -193,7 +193,7 @@ EOF echo "$maxmes" | grep "[1-9]" >/dev/null || maxmes="0" getpass getprofiles - mkdir -p "$muttdir" "$accdir" "$cachedir/$title/bodies" "$HOME/.config/msmtp" + mkdir -p "$muttdir" "$accdir" "$cachedir/$title/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" getaccounts for x in $(seq 1 9); do echo "$accounts" | grep "$x" >/dev/null 2>&1 || { export idnum="$x"; break ;}; done [ ! -f "$msmtprc" ] && echo "$msmtp_header" > "$msmtprc" @@ -203,6 +203,7 @@ EOF protonmail.ch|protonmail.com|pm.me) protonfinger || return 1 ;; esac echo "$mutt_profile" > "$accdir/$idnum-$title.muttrc" + mkdir -p "${mbsyncrc%/*}" echo "$mbsync_profile" >> "$mbsyncrc" notmuchauto [ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" && echo "muttrc created." @@ -289,7 +290,7 @@ asktype() { while : ; do esac; done ;} purge() { confirm "delete all account data" || exit - rm -rf "$mbsyncrc" "$accdir" "$HOME/.config/msmtp" "$cachedir" + rm -rf "$mbsyncrc" "$accdir" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$cachedir" echo "All configs and account settings have been purged." sed -ibu "/\# mw-autogenerated/d" "$muttrc" ; rm -f "$muttrc"bu } From 113499cf740a7a4473ac33414ec833d4fd9c9633 Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Mon, 31 Aug 2020 16:57:19 -0400 Subject: [PATCH 5/5] tweaks --- bin/mw | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/mw b/bin/mw index 57fd7b5..ca090c3 100755 --- a/bin/mw +++ b/bin/mw @@ -16,11 +16,12 @@ maildir="${XDG_DATA_HOME:-$HOME/.local/share}/mail" # Location of mail storage namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username emailre=".+@.+\..+" # Regex to confirm valid email address muttshare="$prefix/share/mutt-wizard" -mbsyncrc="${MBSYNCRC_HOME:-$HOME/.mbsyncrc}" +mbsyncrc="${MBSYNCRC:-$HOME/.mbsyncrc}" mwconfig="$muttshare/mutt-wizard.muttrc" cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard" muttrc="$muttdir/muttrc" msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config" +msmtplog="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/msmtp.log" ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail alias mbsync='mbsync -c "$mbsyncrc"' @@ -39,7 +40,7 @@ msmtp_header="defaults auth on tls on tls_trust_file $sslcert -logfile ${XDG_CONFIG_HOME/:-$HOME/.config}/msmtp/msmtp.log +logfile $msmtplog " msmtp_profile="account $title host $smtp @@ -328,7 +329,7 @@ case "$1" in add) asktype && askinfo && tryconnect && finalize || delete ;; pass) pick "change the password of" && getpass ;; delete) pick delete && confirm "delete the \`$title\` profile" && delete ;; - sync) syncwrapper $2 ;; + sync) syncwrapper "$2" ;; purge) purge ;; *) cat << EOF mw: mutt-wizard, auto-configure email accounts for mutt