mutt-wizard

fork of Luke Smiths mutt-wizard
git clone git://git.jakekoroman.com/mutt-wizard
Log | Files | Refs | README | LICENSE

commit cd13ef20f085012bf4bc4adecf3474038932ef8f
parent 71c80b72d555a84b1b66ced9c25b72e57b48f0c0
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Fri, 22 Feb 2019 12:25:37 -0500

shellchecked

Diffstat:
Mbin/mailsync | 2+-
Mmw | 29+++++++++++++++--------------
2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/bin/mailsync b/bin/mailsync @@ -16,7 +16,7 @@ if [ "$(uname)" = "Darwin" ] then notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} else - notify() { mpv --really-quiet ~/.config/mutt/bin/notify.opus & pgrep -x dunst && notify-send -i ~/.config/mutt/bin/email.gif "$2 new mail(s) in \`$1\` account." ;} + notify() { mpv --really-quiet "$HOME/.config/mutt/bin/notify.opus" & pgrep -x dunst && notify-send -i "$HOME/.config/mutt/bin/email.gif" "$2 new mail(s) in \`$1\` account." ;} fi echo " 🔃" > /tmp/imapsyncicon diff --git a/mw b/mw @@ -18,7 +18,7 @@ case "$(uname)" in esac getprofiles() { \ - printf "Creating profiles for \`$title\`..." + printf "Creating profiles for \`%s\`..." "$title" offlineimap_header="[general] accounts = starttls = yes @@ -111,14 +111,14 @@ addaccount() { \ read -r sport 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 service imap iport smtp sport <<EOF + IFS=, read -r service imap iport smtp sport <<EOF $serverinfo EOF printf "\\n\033[3;33mCongrats!\033[0m Server info has automatically be found, so you won't have to look anything up!\\n\t\033[1mIMAP server\033[0m: %s\\n\t\033[1mIMAP port\033[0m: %s\\n\t\033[1mSMTP server\033[0m: %s\\n\t\033[1mSMTP port\033[0m: %s\\nThis data will be used by the wizard.\\n" "$imap" "$iport" "$smtp" "$sport" fi printf "\\nPress enter to continue.\\n" stty -echo - read wait + read -r stty echo printf "Enter the \033[35mfull name\033[0m you want to be identified by on this account.\\n\tReal name: " read -r realname @@ -142,7 +142,7 @@ EOF idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}') getpass "$title" getprofiles - mkdir -p "$accdir" + mkdir -p "$accdir/$title/cache/bodies" mkdir -p "$HOME/.config/offlineimap/" "$HOME/.config/msmtp" [ ! -f "$HOME/.config/offlineimap/config" ] && echo "$offlineimap_header" > "$HOME/.config/offlineimap/config" [ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config" @@ -161,7 +161,7 @@ getpass() { \ read -r password stty echo echo "$password" > "$tmpdir/$1" - printf "Encrypting your password with %s..." + printf "Encrypting your password with %s..." "$GPG" "$GPG" -r "$gpgemail" --encrypt "$tmpdir/$1" printf "DONE\\nShredding all memory of your password for safety's sake..." unset password @@ -188,7 +188,7 @@ askgpg() { \ } formatShortcut() { \ - while read data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\" # autogenerated" + while read -r data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\" # autogenerated" echo "macro index,pager M$1 \"<save-message>$data<enter>\" \"Move mail to $2.\" # autogenerated" echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"Copy mail to $2.\" # autogenerated"; } >> "$muttdir/accounts/$3.muttrc" done ;} @@ -203,14 +203,14 @@ gen_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 "mutt-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." + 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." stty -echo - read wait + read -r stty echo - mkdir -p "$maildir" (sleep 15; killall offlineimap; killall offlineimap; killall offlineimap)>/dev/null 2>&1 & + mkdir -p "$maildir" offlineimap -qoa "$title" - if ls -d "$maildir/$1/"* >/dev/null 2>&1; then + if ls -d "$maildir/$title/"* >/dev/null 2>&1; then printf "\033[32mSync successful.\033[0m\\n"; return else printf "\033[31m\033[31mSync not successful.\033[0m Try running offlineimap manually after double-checking your password and server settings.\\nThen select to finalize the account.\\n"; return 1 @@ -218,7 +218,7 @@ trysync() { \ } finalize() { \ - boxes="$(ls -d "$maildir/$title/"* 2>/dev/null | sed "s/.*\///;s/^/=/")" + boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")" [ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that offlineimap has not been successfully run.\\nRun offlineimap, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return echo "$boxes" > "$tmpdir/title_boxes" printf "Setting up the mutt sidebar...\\n" @@ -256,9 +256,10 @@ pick() { \ printf "Select (an) account(s) to %s.\\n" "$1" echo "$numbered" read -r input + [ -z "$input" ] && return 1 title="$(echo "$numbered" | grep "$input" | awk '{print $2}')" [ -z "$title" ] && printf "Invalid response." && return 1 - [ ! -z "$2" ] && printf "Are you sure you want to %s the \`%s\` account?" "$1" "$title" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null + [ -n "$2" ] && printf "Are you sure you want to %s the \`%s\` account?" "$1" "$title" && read -r input && echo "$input" | grep -i "y\(es\)*" >/dev/null } delete() { sed -i " @@ -268,7 +269,7 @@ delete() { sed -i " s/=$1\(,\|$\)/=/g s/,$//g " "$HOME/.config/offlineimap/config" - rm -rf "$accdir/$1" "$creddir/$1.gpg" "$accdir/$1.muttrc" + rm -rf "${accdir:?}/${1:?}" "$creddir/$1.gpg" "$accdir/$1.muttrc" sed -i "/$1.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";} @@ -288,7 +289,7 @@ Input a number to continue or press ctrl-c.\\n" case "$choice" in 1) addaccount ;; 2) pick finalize && finalize "$title" ;; - 2) break ;; + 3) break ;; 4) pick delete yes && delete "$title" ;; 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." ;;