From ca766e4a12e222da5f2bec034859e0e343729dfe Mon Sep 17 00:00:00 2001 From: Luke Smith Date: Fri, 22 Feb 2019 13:14:38 -0500 Subject: [PATCH] delim and color --- mw | 81 ++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/mw b/mw index cc3ba9d..1f63fc9 100755 --- a/mw +++ b/mw @@ -91,10 +91,14 @@ unmailboxes * addaccount() { \ printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/offlineIMAP\\n\\nEmail: " + printf "\033[36m\t" read -r fulladdr + printf "\033[0m" 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: " + printf "\033[36m\t" read -r fulladdr + printf "\033[0m" done domain="$(echo "$fulladdr" | sed "s/.*@//")" printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain" @@ -102,13 +106,21 @@ addaccount() { \ 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" + printf "\033[36m\t" read -r imap + printf "\033[0m" printf "What is your server's IMAP port number? (Usually something like 993)\\n" + printf "\033[36m\t" read -r iport + printf "\033[0m" printf "Insert the SMTP server for your email provider (excluding the port number)\\n" + printf "\033[36m\t" read -r smtp + printf "\033[0m" printf "What is your server's SMTP port number? (Usually 587 or 465)\\n" + printf "\033[36m\t" read -r sport + printf "\033[0m" printf "\\nGreat! If you want to be helpful, copy the line below and you can add it to the \`domains.csv\` file on Github.\\nThis will make things easier for others who use your email provider.\\n\\n%s,%s,%s,%s,%s\\n\\nAlthough be sure to test to see if these settings work first! ;-)\\n" "$domain" "$imap" "$iport" "$smtp" "$sport" else IFS=, read -r service imap iport smtp sport </dev/null; do printf "\033[31mTry again\033[0m. Pick a nickname that is one word only including lowercase letters and _ or -.\\n\tAccount name: " + printf "\033[36m\t" read -r title + printf "\033[0m" done printf "If your account has a special username different from your address, insert it now. Otherwise leave this prompt totally blank.\\n\tLogin(?): " + printf "\033[36m\t" read -r login + printf "\033[0m" [ -z "$login" ] && login="$fulladdr" if [ "$service" = "gmail.com" ]; then type="Gmail"; ifgoogleline="folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']" @@ -140,7 +156,7 @@ EOF grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used" seq 1 9 > "$tmpdir/mutt_all" idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}') - getpass "$title" + getpass getprofiles mkdir -p "$accdir/$title/cache/bodies" mkdir -p "$HOME/.config/offlineimap/" "$HOME/.config/msmtp" @@ -156,27 +172,31 @@ EOF } 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: " "$1" + 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/$1" + echo "$password" > "$tmpdir/$title" printf "Encrypting your password with %s..." "$GPG" - "$GPG" -r "$gpgemail" --encrypt "$tmpdir/$1" + "$GPG" -r "$gpgemail" --encrypt "$tmpdir/$title" printf "DONE\\nShredding all memory of your password for safety's sake..." unset password - shred -u "$tmpdir/$1" #| rm -f "$tmpdir/$1" + shred -u "$tmpdir/$title" mkdir -p "$creddir" - mv "$tmpdir/$1.gpg" "$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: " + printf "\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: " + printf "\033[36m\t" read -r gpgemail + printf "\033[0m" done if "$GPG" -K | grep "<$gpgemail>" >/dev/null; then mkdir -p "$creddir" @@ -193,14 +213,6 @@ formatShortcut() { \ echo "macro index,pager C$1 \"$data\" \"Copy mail to $2.\" # autogenerated"; } >> "$muttdir/accounts/$3.muttrc" done ;} -gen_delim() { \ - delim="=" - for i in $(seq $(( $1 - 1 ))) - do - delim="$delim-" - done - echo $delim ;} - trysync() { \ ! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning offlineimap manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" && return 1 printf "\033[32mYou must have an internet connection to continue.\033[0m\\nmutt-wizard will run offlineimap briefly to (1) ensure that login details are functional and (2) allow offlineimap to tell us what mailboxes your email account has.\\nAfter around 15 seconds, mutt-wizard will kill the process and continue.\\nYou can run offlineimap manually to finish the mail sync later.\\nPress enter to continue.\\n." @@ -223,7 +235,7 @@ finalize() { \ echo "$boxes" > "$tmpdir/title_boxes" printf "Setting up the mutt sidebar...\\n" sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')" - delim="$(gen_delim "$sidebar_width")" + delim="$(head -c "$sidebar_width" < /dev/zero | tr '\0' =)" printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n" oneline="$(sed -e "s/^\|$/\"/g" "$tmpdir/title_boxes" | tr "\n" " ")" oneline="=$title $delim $oneline" @@ -246,16 +258,21 @@ finalize() { \ printf "All done.\\n" } -wipe () { rm -rf "$HOME/.config/offlineimap/config" "$accdir" "$creddir" "$muttdir/personal.muttrc" ;} - -[ -z "$gpgemail" ] && askgpg +wipe () { \ + printf "Are you \033[31;1mreally\033[0m sure you want to delete all email accounts?\\n" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 + printf "Are you really, really sure?" && read -r input && ! echo "$input" | grep -i "y\(es\)*" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 + #rm -rf "$HOME/.config/offlineimap/config" "$accdir" "$creddir" "$muttdir/personal.muttrc" + echo deleted +} pick() { \ numbered="$(grep "^accounts *=" "$HOME/.config/offlineimap/config" | sed 's/accounts *= *//g;s/,/ /g;s/ \+/\n/g' | nl)" [ "$(echo "$numbered" | wc -w)" = 0 ] && printf "No accounts to delete.\\n" && return 1 - printf "Select (an) account(s) to %s.\\n" "$1" + printf "Select an accounts to %s:\\n" "$1" echo "$numbered" + printf "\033[36m\t" read -r input + printf "\033[0m" [ -z "$input" ] && return 1 title="$(echo "$numbered" | grep "$input" | awk '{print $2}')" [ -z "$title" ] && printf "Invalid response." && return 1 @@ -263,19 +280,20 @@ pick() { \ } delete() { sed -i " - /Account $1]/,/Account/{//!d} - /Account $1]/d - s/ $1\(,\|$\)//g - s/=$1\(,\|$\)/=/g + /Account $title]/,/Account/{//!d} + /Account $title]/d + s/ $title\(,\|$\)//g + s/=$title\(,\|$\)/=/g s/,$//g " "$HOME/.config/offlineimap/config" - rm -rf "${accdir:?}/${1:?}" "$creddir/$1.gpg" "$accdir/$1.muttrc" - sed -i "/$1.muttrc/d" "$muttdir/personal.muttrc" + rm -rf "${accdir:?}/${title:?}" "$creddir/$title.gpg" "$accdir/$title.muttrc" + sed -i "/$title.muttrc/d" "$muttdir/personal.muttrc" # Delete from the line matching the account name, until the next account or empty line - sed -i "/account $1/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config";} + sed -i "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config";} main() { \ while : ; do + [ -z "$gpgemail" ] && askgpg printf "What would you like \033[32mmutt-wizard\033[0m to do? \033[31m1 Add an email account\033[0m 2 Autodetect mailboxes @@ -285,14 +303,16 @@ main() { \ 6 Delete all account data 0 Exit Input a number to continue or press ctrl-c.\\n" + printf "\033[36m\t" read -r choice + printf "\033[0m" case "$choice" in 1) addaccount ;; - 2) pick finalize && finalize "$title" ;; - 3) break ;; - 4) pick delete yes && delete "$title" ;; + 2) pick finalize && finalize ;; + 3) pick "change the password of" yes && getpass ;; + 4) pick delete yes && delete ;; 5) askgpg ;; - 6) printf "Are you \033[31;1mreally\033[0m sure you want to delete all email accounts?\\n" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null && wipe && printf "Account data purged." ;; + 6) wipe && printf "Account data purged." ;; 0) break ;; *) printf "Invalid input.\\n" esac @@ -300,5 +320,4 @@ done } main - rm -rf "$tmpdir"