Browse Source

delim and color

tags/v3.1
Luke Smith 5 years ago
parent
commit
ca766e4a12
No known key found for this signature in database GPG Key ID: 4C50B54A911F6252
1 changed files with 50 additions and 31 deletions
  1. +50
    -31
      mw

+ 50
- 31
mw View File

@@ -91,10 +91,14 @@ unmailboxes *


addaccount() { \ addaccount() { \
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/offlineIMAP\\n\\nEmail: " 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 read -r fulladdr
printf "\033[0m"
while ! echo "$fulladdr" | grep "$emailre" >/dev/null; do 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 "That is not a valid \033[31memail address\033[0m, please retype the desired email.\\n\\nEmail: "
printf "\033[36m\t"
read -r fulladdr read -r fulladdr
printf "\033[0m"
done done
domain="$(echo "$fulladdr" | sed "s/.*@//")" domain="$(echo "$fulladdr" | sed "s/.*@//")"
printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain" 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 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 "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 "Insert the IMAP server for your email provider (excluding the port number)\\n"
printf "\033[36m\t"
read -r imap read -r imap
printf "\033[0m"
printf "What is your server's IMAP port number? (Usually something like 993)\\n" printf "What is your server's IMAP port number? (Usually something like 993)\\n"
printf "\033[36m\t"
read -r iport read -r iport
printf "\033[0m"
printf "Insert the SMTP server for your email provider (excluding the port number)\\n" printf "Insert the SMTP server for your email provider (excluding the port number)\\n"
printf "\033[36m\t"
read -r smtp read -r smtp
printf "\033[0m"
printf "What is your server's SMTP port number? (Usually 587 or 465)\\n" printf "What is your server's SMTP port number? (Usually 587 or 465)\\n"
printf "\033[36m\t"
read -r sport 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" 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 else
IFS=, read -r service imap iport smtp sport <<EOF IFS=, read -r service imap iport smtp sport <<EOF
@@ -126,10 +138,14 @@ EOF
read -r title read -r title
while ! echo "$title" | grep "$namere" >/dev/null; do while ! echo "$title" | grep "$namere" >/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[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 read -r title
printf "\033[0m"
done 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 "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 read -r login
printf "\033[0m"
[ -z "$login" ] && login="$fulladdr" [ -z "$login" ] && login="$fulladdr"
if [ "$service" = "gmail.com" ]; then if [ "$service" = "gmail.com" ]; then
type="Gmail"; ifgoogleline="folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']" 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" grep "i[0-9]" "$muttdir/personal.muttrc" | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used"
seq 1 9 > "$tmpdir/mutt_all" seq 1 9 > "$tmpdir/mutt_all"
idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}') idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}')
getpass "$title"
getpass
getprofiles getprofiles
mkdir -p "$accdir/$title/cache/bodies" mkdir -p "$accdir/$title/cache/bodies"
mkdir -p "$HOME/.config/offlineimap/" "$HOME/.config/msmtp" mkdir -p "$HOME/.config/offlineimap/" "$HOME/.config/msmtp"
@@ -156,27 +172,31 @@ EOF
} }


getpass() { \ 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 stty -echo
read -r password read -r password
stty echo stty echo
echo "$password" > "$tmpdir/$1"
echo "$password" > "$tmpdir/$title"
printf "Encrypting your password with %s..." "$GPG" 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..." printf "DONE\\nShredding all memory of your password for safety's sake..."
unset password unset password
shred -u "$tmpdir/$1" #| rm -f "$tmpdir/$1"
shred -u "$tmpdir/$title"
mkdir -p "$creddir" mkdir -p "$creddir"
mv "$tmpdir/$1.gpg" "$creddir/"
mv "$tmpdir/$title.gpg" "$creddir/"
printf "DONE.\\n" printf "DONE.\\n"
} }


askgpg() { \ 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 "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 read -r gpgemail
printf "\033[0m"
while ! echo "$gpgemail" | grep "$emailre" >/dev/null; do while ! echo "$gpgemail" | grep "$emailre" >/dev/null; do
printf "That is not a valid email address. Please try again.\\nEmail: " printf "That is not a valid email address. Please try again.\\nEmail: "
printf "\033[36m\t"
read -r gpgemail read -r gpgemail
printf "\033[0m"
done done
if "$GPG" -K | grep "<$gpgemail>" >/dev/null; then if "$GPG" -K | grep "<$gpgemail>" >/dev/null; then
mkdir -p "$creddir" mkdir -p "$creddir"
@@ -193,14 +213,6 @@ formatShortcut() { \
echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"Copy mail to $2.\" # autogenerated"; } >> "$muttdir/accounts/$3.muttrc" echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"Copy mail to $2.\" # autogenerated"; } >> "$muttdir/accounts/$3.muttrc"
done ;} done ;}


gen_delim() { \
delim="="
for i in $(seq $(( $1 - 1 )))
do
delim="$delim-"
done
echo $delim ;}

trysync() { \ 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 ! 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." 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" echo "$boxes" > "$tmpdir/title_boxes"
printf "Setting up the mutt sidebar...\\n" printf "Setting up the mutt sidebar...\\n"
sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')" 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" 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="$(sed -e "s/^\|$/\"/g" "$tmpdir/title_boxes" | tr "\n" " ")"
oneline="=$title $delim $oneline" oneline="=$title $delim $oneline"
@@ -246,16 +258,21 @@ finalize() { \
printf "All done.\\n" 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() { \ pick() { \
numbered="$(grep "^accounts *=" "$HOME/.config/offlineimap/config" | sed 's/accounts *= *//g;s/,/ /g;s/ \+/\n/g' | nl)" 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 [ "$(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" echo "$numbered"
printf "\033[36m\t"
read -r input read -r input
printf "\033[0m"
[ -z "$input" ] && return 1 [ -z "$input" ] && return 1
title="$(echo "$numbered" | grep "$input" | awk '{print $2}')" title="$(echo "$numbered" | grep "$input" | awk '{print $2}')"
[ -z "$title" ] && printf "Invalid response." && return 1 [ -z "$title" ] && printf "Invalid response." && return 1
@@ -263,19 +280,20 @@ pick() { \
} }


delete() { sed -i " 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 s/,$//g
" "$HOME/.config/offlineimap/config" " "$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 # 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() { \ main() { \
while : ; do while : ; do
[ -z "$gpgemail" ] && askgpg
printf "What would you like \033[32mmutt-wizard\033[0m to do? printf "What would you like \033[32mmutt-wizard\033[0m to do?
\033[31m1 Add an email account\033[0m \033[31m1 Add an email account\033[0m
2 Autodetect mailboxes 2 Autodetect mailboxes
@@ -285,14 +303,16 @@ main() { \
6 Delete all account data 6 Delete all account data
0 Exit 0 Exit
Input a number to continue or press ctrl-c.\\n" Input a number to continue or press ctrl-c.\\n"
printf "\033[36m\t"
read -r choice read -r choice
printf "\033[0m"
case "$choice" in case "$choice" in
1) addaccount ;; 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 ;; 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 ;; 0) break ;;
*) printf "Invalid input.\\n" *) printf "Invalid input.\\n"
esac esac
@@ -300,5 +320,4 @@ done
} }


main main

rm -rf "$tmpdir" rm -rf "$tmpdir"

Loading…
Cancel
Save