muttdir="$HOME/.config/mutt" # Main mutt config location
accdir="$muttdir/accounts" # Directory for account settings
maildir="$HOME/.local/share/mail" # Location of mail storage
creddir="$HOME/.local/share/muttwizard" # Location of encrypted credentials
bindir="$HOME/.config/mutt/bin" # Location of scripts run by mutt or the wizard
namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username
emailre=".\+@.\+\\..\+" # Regex to confirm valid email address
mbsyncrc="$HOME/.mbsyncrc"
[ ! -f "$muttdir/domains.csv" ] || [ ! -d "$bindir" ] && printf "Read the README. Be sure to put the repo in the right place before running.\\n" && exit 1
gpgemail="$(grep "$emailre" "$creddir/gpgemail" 2>/dev/null)" # Get previously set gpg email address
@@ -72,7 +69,8 @@ set folder = \"$maildir/$title\"
set header_cache = $accdir/$title/cache/headers
set message_cachedir = $accdir/$title/cache/bodies
set certificate_file = $accdir/$title/certificates
source \"$bindir/getmuttpass $title |\"
set imap_pass = \`pass mutt-wizard-$title\`
set smtp_pass = \`pass mutt-wizard-$title\`
alias me $realname <$fulladdr>
@@ -177,39 +175,7 @@ EOF
[ "$accounttype" = "offline" ] || sed -i "/IMAPAccount $title$/,/# End profile/d" "$mbsyncrc"
}
getpass() { \
printf "Now enter your password for the \"%s\" account. Don't worry, this will be encrypted and only you with your GPG key can view it.\\n\tPassword: " "$title"
stty -echo
read -r password
stty echo
echo "$password" > "$tmpdir/$title"
printf "Encrypting your password with %s..." "$GPG"
"$GPG" -r "$gpgemail" --encrypt "$tmpdir/$title"
printf "DONE\\nShredding all memory of your password for safety's sake..."
unset password
shred -u "$tmpdir/$title"
mkdir -p "$creddir"
mv "$tmpdir/$title.gpg" "$creddir/"
printf "DONE.\\n"
}
askgpg() { \
printf "To safely encrypt passwords, mutt-wizard requires that you have a GPG public/private key pair.\\n\\nPlease input the email address of your GPG key pair below.\\nEmail: \033[36m\t"
read -r gpgemail
printf "\033[0m"
while ! echo "$gpgemail" | grep "$emailre" >/dev/null; do
printf "That is not a valid email address. Please try again.\\nEmail: \033[36m\t"
read -r gpgemail
printf "\033[0m"
done
if "$GPG" -K | grep "<$gpgemail>" >/dev/null; then
mkdir -p "$creddir"
echo "$gpgemail" > "$creddir/gpgemail"
else
printf "You do not appear to have a private key associated with \033[33m%s\033[0m.\\nPlease generate a GPG key pair by running \`\033[32m%s --full-gen-key\033[0m\` and rerun the wizard.\\n" "$gpgemail" "$GPG"
[ ! -f "$HOME/.password-store/.gpg-id" ] && 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 \`gpg --full-gen-key\` first.\\n" && exit
5) confirm "delete all account data" && rm -ri "$mbsyncrc" "$accdir" "$creddir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged." ;;
5) confirm "delete all account data" && rm -ri "$mbsyncrc" "$accdir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged." ;;