More work done, got a couple small bugs to fix though, so it's in a broken state atm.
This commit is contained in:
parent
874123d706
commit
f48d108407
@ -10,7 +10,15 @@
|
||||
muttHome=~/.muttest
|
||||
|
||||
# Functions
|
||||
create_mailcap()
|
||||
check_dependancies()
|
||||
{
|
||||
if ! command -v gpg &> /dev/null ; then
|
||||
echo "gpg is not installed. Please install gnupg and run this script again."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
initialize_directory()
|
||||
{
|
||||
if ! [ -d "$muttHome" ]; then
|
||||
mkdir -p "$muttHome"
|
||||
@ -57,6 +65,25 @@ create_mailcap()
|
||||
echo "application/msword; $(command -v antiword) %s; copiousoutput" >> "$muttHome/mailcap"
|
||||
fi
|
||||
fi
|
||||
if ! [ -f "$muttHome/gpg.rc" ]; then
|
||||
cp "/usr/share/doc/mutt/samples/gpg.rc" "$muttHome/"
|
||||
echo "set pgp_autosign=yes" >> "$muttHome/gpg.rc"
|
||||
echo "set crypt_autosign=yes" >> "$muttHome/gpg.rc"
|
||||
echo "set pgp_replyencrypt=yes" >> "$muttHome/gpg.rc"
|
||||
echo "set pgp_timeout=1800" >> "$muttHome/gpg.rc"
|
||||
if ! gpg --list-secret-keys | grep '.*@.*' &> /dev/null ; then
|
||||
read -p "No gpg key was found. Press enter to generate one now, or control+c if you would like to do so manually. Note, the default values are usually what you want." continue
|
||||
gpg --gen-key
|
||||
fi
|
||||
echo "Select the key you want to use for encryption/signing:"
|
||||
select key in $(gpg --list-secret-keys | grep '.*@.*' | cut -d '<' -f2 | cut -d '>' -f1) ; do
|
||||
if [ -n "$key" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
keyName="$(gpg --fingerprint $key | head -n 2 | tail -n 1 | rev | cut -d ' ' -f-2 | tr -d "[:space:]" | rev)"
|
||||
echo "set pgp_sign_as=$keyName" >> "$muttHome/gpg.rc"
|
||||
fi
|
||||
}
|
||||
|
||||
add_email_address()
|
||||
@ -78,7 +105,24 @@ add_email_address()
|
||||
*gmail.com)
|
||||
configure_gmail "$emailAddress"
|
||||
;;
|
||||
*hotmail.com)
|
||||
configure_hotmail "$emailAddress"
|
||||
;;
|
||||
esac
|
||||
# Password encryption with gpg
|
||||
until [ "$passOne" = "passTwo" ]; do
|
||||
read -sp "Please enter the password for $1: " passOne
|
||||
read -sp "Please enter the password again: " passTwo
|
||||
if [ "$passOne" != "passTwo" ]; then
|
||||
echo "The passwords do not match."
|
||||
fi
|
||||
done
|
||||
keyName="$(grep 'pgp_sign_as=' "$muttHome/pgp.rc" | cut -d '=' -f2)"
|
||||
# I wish it were possible to just echo the password through gpg and not have an unencrypted file at all.
|
||||
# but either it's not, or I just can't figure out how to do it. So we'll use mktemp and shred.
|
||||
passwordFile="$(mktemp)"
|
||||
echo -e "set imap_pass=\"$passOne\"\nset smtp_pass=\"$passOne\"" > "$passwordFile"
|
||||
gpg -r $keyName -e "$passwordFile" --output "$muttHome/$emailAddress.gpg"
|
||||
}
|
||||
|
||||
configure_gmail()
|
||||
@ -108,9 +152,29 @@ echo "bind editor <Tab> complete-query" >> "$muttHome/$1"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_hotmail()
|
||||
{
|
||||
# This is just to create the base file with settings common to all hotmail accounts
|
||||
# I decided to do these in functions so as to not have a truly giagantic case statement in the add email function
|
||||
echo "unset imap_passive" > "$muttHome/$1"
|
||||
echo "unset record" >> "$muttHome/$1"
|
||||
echo "set from=$1" >> "$muttHome/$1"
|
||||
echo "set imap_user=$1" >> "$muttHome/$1"
|
||||
echo "set smtp_url=\"smtp://$1@smtp.live.com:587/" >> "$muttHome/$1"
|
||||
echo "set folder=imaps://$1@imap.live.com/" >> "$muttHome/$1"
|
||||
echo "set ssl_force_tls=yes" >> "$muttHome/$1"
|
||||
echo "mailboxes=+INBOX" >> "$muttHome/$1"
|
||||
echo "set postponed=+[hotmail]/Drafts" >> "$muttHome/$1"
|
||||
echo "set imap_keepalive=300" >> "$muttHome/$1"
|
||||
echo "set mail_check=300" >> "$muttHome/$1"
|
||||
echo "bind editor <Tab> complete-query" >> "$muttHome/$1"
|
||||
echo "source ~/${muttHome#/home/*/}/aliases" >> "$muttHome/$1"
|
||||
}
|
||||
|
||||
# This is the main loop of the program
|
||||
# Call functions to be ran every time the script is ran: checks for things like mailcap
|
||||
create_mailcap
|
||||
# Call functions to be ran every time the script is ran.
|
||||
check_dependancies
|
||||
initialize_directory
|
||||
# Let's make a mainmenu variable to hold all the options for the select loop.
|
||||
mainmenu=('Add Email Address' 'Exit')
|
||||
select i in "${mainmenu[@]}" ; do
|
||||
|
Loading…
x
Reference in New Issue
Block a user