|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# This script has the lofty goal of becoming a full configuration utility for mutt.
|
|
|
|
|
# Written by Storm Dragon: https://social.stormdragon.tk/storm
|
|
|
|
@ -6,61 +6,29 @@
|
|
|
|
|
# Contributions by Kyle: https://kyle.tk
|
|
|
|
|
# Released under the terms of the WTFPL: http://wtfpl.net
|
|
|
|
|
|
|
|
|
|
# Setup for gettext localization
|
|
|
|
|
export TEXTDOMAIN=fleacollar.sh
|
|
|
|
|
export TEXTDOMAINDIR=/usr/share/locale
|
|
|
|
|
. gettext.sh
|
|
|
|
|
|
|
|
|
|
# Settings to improve accessibility of dialog.
|
|
|
|
|
export DIALOGOPTS='--insecure --no-lines --visit-items'
|
|
|
|
|
|
|
|
|
|
# Use the cli entry system for gpg keys.
|
|
|
|
|
export PINENTRY_USER_DATA="USE_CURSES=1"
|
|
|
|
|
|
|
|
|
|
# Array of command line arguments
|
|
|
|
|
declare -A command=(
|
|
|
|
|
[h]="Show this help information."
|
|
|
|
|
[t]="Test mode. Use ~/mutt_test instead of ~/.mutt for configuration."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
|
muttHome=~/.mutt
|
|
|
|
|
fileDir="$(dirname "$(realpath "$0")")/files"
|
|
|
|
|
testMode=false
|
|
|
|
|
|
|
|
|
|
# Process command line arguments
|
|
|
|
|
# Convert the keys of the associative array to a format usable by getopts
|
|
|
|
|
args="${!command[*]}"
|
|
|
|
|
args="${args//[[:space:]]/}"
|
|
|
|
|
while getopts "${args}" i ; do
|
|
|
|
|
case "$i" in
|
|
|
|
|
h) help ;;
|
|
|
|
|
t)
|
|
|
|
|
testMode=true
|
|
|
|
|
muttHome=~/mutt_test
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Functions
|
|
|
|
|
help() {
|
|
|
|
|
echo "fleacollar.sh"
|
|
|
|
|
echo "Released under the terms of the WTFPL: http://wtfpl.net"
|
|
|
|
|
echo -e "A configuration utility for mutt.\n"
|
|
|
|
|
echo -e "Usage:\n"
|
|
|
|
|
echo "With no arguments, run the configuration utility."
|
|
|
|
|
for i in "${!command[@]}" ; do
|
|
|
|
|
echo "-${i}: ${command[${i}]}"
|
|
|
|
|
done | sort
|
|
|
|
|
exit 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_dependancies()
|
|
|
|
|
{
|
|
|
|
|
local dep
|
|
|
|
|
for dep in dialog gpg2 mutt pass w3m ; do
|
|
|
|
|
for dep in dialog gettext gpg mutt ; do
|
|
|
|
|
if ! command -v $dep &> /dev/null ; then
|
|
|
|
|
echo "$dep is not installed. Please install $dep and run this script again."
|
|
|
|
|
echo "$(eval_gettext "\$dep is not installed. Please install $dep and run this script again.")"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if ! [ -d ~/.gnupg ]; then
|
|
|
|
|
read -p "No configuration for GPG was found. To have Fleacollar configure this for you press enter. If you would like to configure GPG manually, press control+c. " continue
|
|
|
|
|
read -p "$(eval_gettext "No configuration for GPG was found. To have Fleacollar configure this for you press enter. If you would like to configure GPG manually, press control+c.") " continue
|
|
|
|
|
configure_gpg
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
@ -69,7 +37,7 @@ inputbox() {
|
|
|
|
|
# Returns: text entered by the user
|
|
|
|
|
# Args 1, Instructions for box.
|
|
|
|
|
# args: 2 initial text (optional)
|
|
|
|
|
dialog --backtitle "Enter text and press enter." \
|
|
|
|
|
dialog --backtitle "$(gettext "Enter text and press enter.")" \
|
|
|
|
|
--inputbox "$1" 0 0 "$2" --stdout
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -79,9 +47,9 @@ menulist() {
|
|
|
|
|
local menuList
|
|
|
|
|
ifs="$IFS"
|
|
|
|
|
IFS=$'\n'
|
|
|
|
|
dialog --backtitle "Use the up and down arrow keys to find the option you want, then press enter to select it." \
|
|
|
|
|
dialog --backtitle "$(gettext "Use the up and down arrow keys to find the option you want, then press enter to select it.")" \
|
|
|
|
|
--no-tags \
|
|
|
|
|
--menu "Please select one" 0 0 0 $@ --stdout
|
|
|
|
|
--menu "$(gettext "Please select one")" 0 0 0 $@ --stdout
|
|
|
|
|
IFS="$ifs"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -95,7 +63,7 @@ passwordbox() {
|
|
|
|
|
# Returns: text entered by the user
|
|
|
|
|
# Args 1, Instructions for box.
|
|
|
|
|
# args: 2 initial text (optional)
|
|
|
|
|
dialog --backtitle "Enter text and press enter." \
|
|
|
|
|
dialog --backtitle "$(gettext "Enter text and press enter.")" \
|
|
|
|
|
--passwordbox "$1" 0 0 "$2" --stdout
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,8 +72,8 @@ yesno() {
|
|
|
|
|
# Args: Question to user.
|
|
|
|
|
# Called in if $(yesno) == "Yes"
|
|
|
|
|
# Or variable=$(yesno)
|
|
|
|
|
dialog --backtitle "Press 'Enter' for \"yes\" or 'Escape' for
|
|
|
|
|
\"no\"." --yesno "$*" 0 0 --stdout
|
|
|
|
|
dialog --backtitle "$(gettext "Press 'Enter' for \"yes\" or 'Escape' for
|
|
|
|
|
\"no\".")" --yesno "$*" 0 0 --stdout
|
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
|
echo "Yes"
|
|
|
|
|
else
|
|
|
|
@ -120,50 +88,123 @@ initialize_directory()
|
|
|
|
|
if ! [ -f "$muttHome/aliases" ]; then
|
|
|
|
|
touch "$muttHome/aliases"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Copy the add_address.sh script
|
|
|
|
|
# Create scripts
|
|
|
|
|
if ! [ -f "$muttHome/scripts/add_address.sh" ]; then
|
|
|
|
|
cp "$fileDir/add_address.sh" "$muttHome/scripts/add_address.sh"
|
|
|
|
|
cat << EOF > "$muttHome/scripts/add_address.sh"
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
message=\$(cat)
|
|
|
|
|
|
|
|
|
|
newAlias=\$(echo "\${message}" | grep ^"From: " | sed -e s/[\,\"\']//g -e s/'From: '//g | awk -F" " '{if (NF == 1) {print "alias UNNAMED UNNAMED " \$0;} else if (NF == 2) {print "alias " \$1" " toupper(substr(\$0,1,1)) tolower(substr(\$0,2));} else if (NF >= 3) {print "alias ", tolower(\$1)"-"tolower(\$(NF-1))" " toupper(substr(\$0,1,1)) tolower(substr(\$0,2));}}')
|
|
|
|
|
emailAddress="<\${newAlias##*<}"
|
|
|
|
|
|
|
|
|
|
if ! grep -Fq "\$emailAddress" \$HOME/.mutt/aliases; then
|
|
|
|
|
echo "\$newAlias" >> \$HOME/.mutt/aliases
|
|
|
|
|
sort -u ~/.mutt/aliases -o ~/.mutt/aliases
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "\${message}"
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
chmod 700 "$muttHome/scripts/add_address.sh"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create mailcap file (now always using w3m)
|
|
|
|
|
# End of add_address script
|
|
|
|
|
if ! [ -f "$muttHome/mailcap" ]; then
|
|
|
|
|
cp "$fileDir/mailcap" "$muttHome/mailcap"
|
|
|
|
|
# Find desired browser
|
|
|
|
|
local x=0
|
|
|
|
|
for i in\
|
|
|
|
|
$BROWSER\
|
|
|
|
|
chromium\
|
|
|
|
|
elinks\
|
|
|
|
|
epiphany\
|
|
|
|
|
firefox\
|
|
|
|
|
google-chrome\
|
|
|
|
|
links\
|
|
|
|
|
lynx\
|
|
|
|
|
midori\
|
|
|
|
|
seamonkey\
|
|
|
|
|
w3m
|
|
|
|
|
do
|
|
|
|
|
unset browserPath
|
|
|
|
|
browserPath="$(command -v $i)"
|
|
|
|
|
if [ -n "$browserPath" ]; then
|
|
|
|
|
browsers[$x]="$browserPath"
|
|
|
|
|
((x++))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo "$(gettext "Select browser for viewing html email:")"
|
|
|
|
|
browserPath="$(menulist $(for i in "${browsers[@]##*/}" ; do echo "$i";echo "$i";done))"
|
|
|
|
|
if [ -z "$browserPath" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
case "${browserPath##*/}" in
|
|
|
|
|
"elinks")
|
|
|
|
|
echo "text/html; $browserPath %s; nametemplate=%s.html; needsterminal" > "$muttHome/mailcap"
|
|
|
|
|
;;
|
|
|
|
|
"lynx|w3m")
|
|
|
|
|
echo "text/html; $browserPath -I %{charset} -T text/html %s; nametemplate=%s.html; copiousoutput" > "$muttHome/mailcap"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "text/html; $browserPath %s; nametemplate=%s.html; needsterminal" > "$muttHome/mailcap"
|
|
|
|
|
esac
|
|
|
|
|
echo 'audio/*; mpv --quiet %s; needsterminal' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/msword; soffice --cat %s 2> /dev/null; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/vnd.openxmlformats-officedocument.wordprocessingml.document; soffice --cat %s 2> /dev/null; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/vnd.ms-excel; xls2csv %s; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; xlsx2csv --all %s; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/rtf; soffice --cat %s 2> /dev/null; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/vnd.oasis.opendocument.text; soffice --cat %s 2> /dev/null; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/vnd.oasis.opendocument.spreadsheet;soffice --cat --convert-to csv:"Text - txt - csv (StarCalc)":"59,ANSI,1" %s 2> /dev/null; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'application/pdf; pdftotext %s -; copiousoutput' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'video/*; mpv --quiet %s; test=test -n "$DISPLAY"; needsterminal' >> "$muttHome/mailcap"
|
|
|
|
|
echo 'video/*; mpv --quiet --no-video %s; needsterminal' >> "$muttHome/mailcap"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create gpg.rc file
|
|
|
|
|
if ! [ -f "$muttHome/gpg.rc" ]; then
|
|
|
|
|
if ! cp "/usr/share/doc/mutt/samples/gpg.rc" "$muttHome/" ; then
|
|
|
|
|
find /usr -name gpg.rc -exec cp "{}" "$muttHome/" \; 2> /dev/null
|
|
|
|
|
fi
|
|
|
|
|
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 | wc -l) -eq 0 ]]; then
|
|
|
|
|
read -p "No gpg key was found. Type your name and press enter to generate a PGP key. Control+c if you would like to create it manually. " continue
|
|
|
|
|
# Try to use quick key generation, and fall back to the more verbose version for legacy systems.
|
|
|
|
|
if ! gpg2 --quick-gen-key "${continue:-${USER}}"; then
|
|
|
|
|
gpg2 --gen-key
|
|
|
|
|
read -p "$(gettext "No gpg key was found. Type your name and press entr to generate a PGP key.control+c if you would like to create it manually.") " continue
|
|
|
|
|
gpg --gen-key
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
PS3="Select the key you want to use for encryption/signing:"
|
|
|
|
|
PS3="$(gettext "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="$(gpg2 --list-secret-keys --keyid-format short | grep -B1 ^uid | head -n1 | rev | cut -c -8 | rev)"
|
|
|
|
|
keyName="$(gpg --list-secret-keys --keyid-format short | grep -B1 ^uid | head -n1 | rev | cut -c -8 | rev)"
|
|
|
|
|
echo "set pgp_sign_as=$keyName" >> "$muttHome/gpg.rc"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create or update macro file
|
|
|
|
|
cp "$fileDir/macros" "$muttHome/macros"
|
|
|
|
|
echo "macro index 'c' '<change-folder>?<change-dir><home>^K=<enter>'" >> "$muttHome/macros"
|
|
|
|
|
echo "bind index \"^\" imap-fetch-mail\"" >> "$muttHome/macros"
|
|
|
|
|
echo "macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'" >> "$muttHome/macros"
|
|
|
|
|
echo "macro attach 'B' \"<pipe-entry>cat >~/.cache/mutt/mail.html && $BROWSER ~/.cache/\"" >> "$muttHome/macros"
|
|
|
|
|
echo "macro index,pager b '<enter-command>source $muttHome/aliases<enter><bounce-message>'" >> "$muttHome/macros"
|
|
|
|
|
echo "macro index,pager f '<enter-command>source $muttHome/aliases<enter><forward-message>'" >> "$muttHome/macros"
|
|
|
|
|
echo "macro index,pager m '<enter-command>source $muttHome/aliases<enter><mail>'" >> "$muttHome/macros"
|
|
|
|
|
|
|
|
|
|
# Create basic muttrc
|
|
|
|
|
if ! [ -f "$muttHome/muttrc" ]; then
|
|
|
|
|
# Find desired editor
|
|
|
|
|
x=0
|
|
|
|
|
for i in nano vim ; do
|
|
|
|
|
for i in\
|
|
|
|
|
emacs\
|
|
|
|
|
geany\
|
|
|
|
|
gedit\
|
|
|
|
|
leafpad\
|
|
|
|
|
mousepad\
|
|
|
|
|
nano\
|
|
|
|
|
ne\
|
|
|
|
|
pluma\
|
|
|
|
|
vi\
|
|
|
|
|
vim
|
|
|
|
|
do
|
|
|
|
|
unset editorPath
|
|
|
|
|
editorPath="$(command -v $i)"
|
|
|
|
|
if [ -n "$editorPath" ]; then
|
|
|
|
@ -171,23 +212,47 @@ initialize_directory()
|
|
|
|
|
((x++))
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
echo "Select editor for email composition:"
|
|
|
|
|
echo "$gettext "Select editor for email composition:")"
|
|
|
|
|
i="$(menulist ${EDITOR} ${EDITOR} $(for i in "${editors[@]##*/}" ; do echo "$i";echo "$i";done))"
|
|
|
|
|
if [ -z "$i" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Copy base muttrc
|
|
|
|
|
cp "$fileDir/muttrc" "$muttHome/muttrc"
|
|
|
|
|
|
|
|
|
|
# Set editor in muttrc
|
|
|
|
|
# Try to handle special cases like with ne and nano skipping headers and line wrapping.
|
|
|
|
|
case "$i" in
|
|
|
|
|
"nano") sed -i "1s|^|set editor = '$i +7 -r 72'\n|" "$muttHome/muttrc" ;;
|
|
|
|
|
"vim") sed -i "1s|^|set editor = \"vim -c 'set spell spelllang=${LANG::2}'\"\n|" "$muttHome/muttrc" ;;
|
|
|
|
|
"nano") echo "set editor = '$i +7 -r 72'" > "$muttHome/muttrc";;
|
|
|
|
|
"ne") echo "set editor = '$i +7'" > "$muttHome/muttrc";;
|
|
|
|
|
"vim") echo "set editor = \"vim -c 'set spell spelllang=${LANG::2}'\"" > "$muttHome/muttrc";;
|
|
|
|
|
*) echo "set editor = '$i'" > "$muttHome/muttrc";;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# Replace muttHome in muttrc
|
|
|
|
|
sed -i "s|\$muttHome|${muttHome/#$HOME/\~}|g" "$muttHome/muttrc"
|
|
|
|
|
echo "set text_flowed = yes" >> "$muttHome/muttrc"
|
|
|
|
|
# Move the messge index number to the right edge.
|
|
|
|
|
echo "set index_format = '%Z %{%b %d} %-15.15L (%?l?%4l&%4c?) %s %4C'" >> "$muttHome/muttrc"
|
|
|
|
|
# I need to figure out a way to detect and set the language for the next setting.
|
|
|
|
|
echo "set send_charset = us-ascii:utf-8" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set pager = 'builtin'" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set pager_stop = 'yes'" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set sort = threads" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set beep_new = yes" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set display_filter = '$muttHome/scripts/add_address.sh'" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set print = yes" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set imap_check_subscribed = yes" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set sort_alias = alias" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set reverse_alias = yes" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set alias_file = ${muttHome/#$HOME/\~}/aliases" >> "$muttHome/muttrc"
|
|
|
|
|
echo "source ${muttHome/#$HOME/\~}/aliases" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set history_file = ${muttHome/#$HOME/\~}/history" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set history = 1024" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set mailcap_path = ${muttHome/#$HOME/\~}/mailcap" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set header_cache = ${muttHome/#$HOME/\~}/cache/headers" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set message_cachedir = ${muttHome/#$HOME/\~}/cache/bodies" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set certificate_file = ${muttHome/#$HOME/\~}/certificates" >> "$muttHome/muttrc"
|
|
|
|
|
echo "set markers = no" >> "$muttHome/muttrc"
|
|
|
|
|
echo "unset mark_old" >> "$muttHome/muttrc"
|
|
|
|
|
echo "auto_view text/html" >> "$muttHome/muttrc"
|
|
|
|
|
echo "alternative_order text/plain text/enriched text/html" >> "$muttHome/muttrc"
|
|
|
|
|
echo "message-hook '!(~g|~G) ~b\"^ 5 dash charactersBEGIN\\ PGP\\ (SIGNED\\ )?MESSAGE\"' \"exec check-traditional-pgp\"" >> "$muttHome/muttrc"
|
|
|
|
|
echo "source ${muttHome/#$HOME/\~}/gpg.rc" >> "$muttHome/muttrc"
|
|
|
|
|
echo "source ${muttHome/#$HOME/\~}/macros" >> "$muttHome/muttrc"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -197,44 +262,55 @@ configure_gpg()
|
|
|
|
|
if ! grep 'GPG_TTY=$(tty)' ~/.bashrc ; then
|
|
|
|
|
echo -e 'GPG_TTY=$(tty)\nexport GPG_TTY' >> ~/.bashrc
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Make sure the configuration directory exists
|
|
|
|
|
if ! [ -d ~/.gnupg/ ]; then
|
|
|
|
|
gpg2 --list-secret-keys &> /dev/null
|
|
|
|
|
gpg --list-secret-keys &> /dev/null
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ -f ~/.gnupg/gpg.conf ]; then
|
|
|
|
|
read -p "This will overwrite your existing ~/.gnupg/gpg.conf file. Press enter to continue or control+c to abort. " continue
|
|
|
|
|
read -p "$(gettext "This will overwrite your existing ~/.gnupg/gpg.conf file. Press enter to continue or control+c to abort. ")" continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Copy GPG configuration files
|
|
|
|
|
cp "$fileDir/gpg.conf" ~/.gnupg/gpg.conf
|
|
|
|
|
|
|
|
|
|
cat << EOF > ~/.gnupg/gpg.conf
|
|
|
|
|
charset utf-8
|
|
|
|
|
require-cross-certification
|
|
|
|
|
no-escape-from-lines
|
|
|
|
|
no-mangle-dos-filenames
|
|
|
|
|
personal-digest-preferences SHA512
|
|
|
|
|
cert-digest-algo SHA512
|
|
|
|
|
use-agent
|
|
|
|
|
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
|
|
|
|
|
keyserver wwwkeys.pgp.net
|
|
|
|
|
keyserver hkp://pool.sks-keyservers.net
|
|
|
|
|
keyserver pgp.zdv.uni-mainz.de
|
|
|
|
|
keyserver-options auto-key-retrieve
|
|
|
|
|
EOF
|
|
|
|
|
if [ -f ~/.gnupg/gpg-agent.conf ]; then
|
|
|
|
|
read -p "This will overwrite your existing ~/.gnupg/gpg-agent.conf file. Press enter to continue or control+c to abort. " continue
|
|
|
|
|
read -p "$(gettext "This will overwrite your existing ~/.gnupg/gpg-agent.conf file. Press enter to continue or control+c to abort. ")" continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cp "$fileDir/gpg-agent.conf" ~/.gnupg/gpg-agent.conf
|
|
|
|
|
cat << EOF > ~/.gnupg/gpg-agent.conf
|
|
|
|
|
default-cache-ttl 300
|
|
|
|
|
max-cache-ttl 999999
|
|
|
|
|
allow-loopback-pinentry
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_email_address()
|
|
|
|
|
{
|
|
|
|
|
read -p "Please enter your email address: " emailAddress
|
|
|
|
|
read -p "$(gettext "Please enter your email address: ")" emailAddress
|
|
|
|
|
if ! [[ "$emailAddress" =~ .*@.*\..* ]]; then
|
|
|
|
|
read -p "This appears to be an invalid email address. Continue anyway? (y/n) " continue
|
|
|
|
|
read -p "$(gettext "this appears to be an invalid email address. Continue anyway? (y/n) ")" continue
|
|
|
|
|
if [ "${continue^}" != "Y" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ -f "$muttHome/$emailAddress" ]; then
|
|
|
|
|
read -p "This email address already exists. Overwrite the existing settings? (y/n) " continue
|
|
|
|
|
read -p "$(gettext "This email address already exists. Overwrite the existing settings? (y/n) ")" continue
|
|
|
|
|
if [ "${continue^}" != "Y" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
else
|
|
|
|
|
sed -i "/$emailAddress/d" "$muttHome/muttrc"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
read -p "Enter your name as you want it to appear in emails. From: " realName
|
|
|
|
|
read -p "$(gettext "Enter your name as you want it to appear in emails. From: ")" realName
|
|
|
|
|
echo "set realname=\"$realName\"" > "$muttHome/$emailAddress"
|
|
|
|
|
echo "set from=\"$emailAddress\"" >> "$muttHome/$emailAddress"
|
|
|
|
|
echo "set use_from = \"yes\"" >> "$muttHome/$emailAddress"
|
|
|
|
@ -247,78 +323,82 @@ add_email_address()
|
|
|
|
|
configure_hotmail "$emailAddress"
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
continue="$(yesno "Is this a gmail account?")"
|
|
|
|
|
continue="$(yesno "$(gettext "Is this a gmail account?")")"
|
|
|
|
|
if [[ "$continue" == "Yes" ]]; then
|
|
|
|
|
configure_gmail "$emailAddress"
|
|
|
|
|
else
|
|
|
|
|
configure_generic "$emailAddress"
|
|
|
|
|
fi
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# Password storage with pass
|
|
|
|
|
# Password encryption with gpg
|
|
|
|
|
passOne=a
|
|
|
|
|
passTwo=b
|
|
|
|
|
until [ "$passOne" = "$passTwo" ]; do
|
|
|
|
|
passOne="$(passwordbox "Please enter the password for $emailAddress:")"
|
|
|
|
|
passTwo="$(passwordbox "Please enter the password again: ")"
|
|
|
|
|
passOne="$(passwordbox "$(gettext "Please enter the password for $emailAddress:")")"
|
|
|
|
|
passTwo="$(passwordbox "$(gettext "Please enter the password again: ")")"
|
|
|
|
|
if [ "$passOne" != "$passTwo" ]; then
|
|
|
|
|
echo "The passwords do not match."
|
|
|
|
|
echo "$(gettext "The passwords do not match.")"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Store password in pass
|
|
|
|
|
pass insert -f "email/$emailAddress" <<< "$passOne"
|
|
|
|
|
|
|
|
|
|
# Add configuration to retrieve password from pass
|
|
|
|
|
echo "set imap_pass=\"`pass show email/$emailAddress`\"" >> "$muttHome/$emailAddress"
|
|
|
|
|
echo "set smtp_pass=\"`pass show email/$emailAddress`\"" >> "$muttHome/$emailAddress"
|
|
|
|
|
|
|
|
|
|
keyName="$(gpg --list-secret-keys --keyid-format short | grep -B1 ^uid | head -n1 | rev | cut -c -8 | rev)"
|
|
|
|
|
# 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"
|
|
|
|
|
mv "$passwordFile.gpg" "$muttHome/$emailAddress.gpg"
|
|
|
|
|
shred -fuzn 10 "$passwordFile"
|
|
|
|
|
echo "source \"gpg -d ${muttHome/#$HOME/\~}/${emailAddress}.gpg|\"" >> "$muttHome/$emailAddress"
|
|
|
|
|
add_keybinding
|
|
|
|
|
echo "folder-hook .*$emailAddress/ 'source ${muttHome/#$HOME/\~}/$emailAddress'" >> "$muttHome/$emailAddress"
|
|
|
|
|
msgbox "Email address added, press enter to continue."
|
|
|
|
|
msgbox "$(gettext "Email address added, press enter to continue.")"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configure_gmail()
|
|
|
|
|
{
|
|
|
|
|
# Copy the Gmail template and replace placeholders
|
|
|
|
|
cp "$fileDir/gmail.template" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Replace email placeholder in the template
|
|
|
|
|
sed -i "s|EMAIL_ADDRESS|$1|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|USERNAME|${1%@*}|g" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Append the template to the existing config
|
|
|
|
|
cat "$muttHome/$1.tmp" >> "$muttHome/$1"
|
|
|
|
|
rm "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Handle goobook integration if available
|
|
|
|
|
# This is just to create the base file with settings common to all gmail 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 imap_user=$1" >> "$muttHome/$1"
|
|
|
|
|
echo "set smtp_url=\"smtp://${1%@*}@smtp.gmail.com:587/" >> "$muttHome/$1"
|
|
|
|
|
echo "set folder=imaps://${1%@*}@imap.gmail.com/" >> "$muttHome/$1"
|
|
|
|
|
echo "set spoolfile = +INBOX" >> "$muttHome/$1"
|
|
|
|
|
echo "mailboxes = +INBOX" >> "$muttHome/$1"
|
|
|
|
|
echo "set postponed = +[Gmail]/Drafts" >> "$muttHome/$1"
|
|
|
|
|
echo "set record=+[Gmail]/Sent" >> "$muttHome/$1"
|
|
|
|
|
echo "set imap_keepalive=300" >> "$muttHome/$1"
|
|
|
|
|
echo "set mail_check=300" >> "$muttHome/$1"
|
|
|
|
|
unset continue
|
|
|
|
|
if command -v goobook &> /dev/null ; then
|
|
|
|
|
read -p "Goobook is installed, would you like to use it as your addressbook for the account $1? " continue
|
|
|
|
|
read -p "$(eval_gettext "Goobook is installed, would you like to use it as your addressbook for the account \$1? ")" continue
|
|
|
|
|
fi
|
|
|
|
|
if [ "${continue^}" = "Y" ]; then
|
|
|
|
|
echo "set query_command=\"goobook query %s\"" >> "$muttHome/$1"
|
|
|
|
|
# Normally macros go in muttHome/macros, but this may be a gmail specific setting
|
|
|
|
|
echo "macro index,pager a \"<pipe-message>goobook add<return>\" \"add sender to google contacts\"" >> "$muttHome/$1"
|
|
|
|
|
else
|
|
|
|
|
echo "source ~/${muttHome#/home/*/}/aliases" >> "$muttHome/$1"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "source ~/${muttHome#/home/*/}/aliases" >> "$muttHome/$1"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
configure_hotmail()
|
|
|
|
|
{
|
|
|
|
|
# Copy the Hotmail template and replace placeholders
|
|
|
|
|
cp "$fileDir/hotmail.template" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Replace email placeholder in the template
|
|
|
|
|
sed -i "s|EMAIL_ADDRESS|$1|g" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Append the template to the existing config
|
|
|
|
|
cat "$muttHome/$1.tmp" >> "$muttHome/$1"
|
|
|
|
|
rm "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Add source for aliases
|
|
|
|
|
# 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 imap_user=$1" >> "$muttHome/$1"
|
|
|
|
|
echo "set smtp_url=\"smtp://$1@smtp-mail.outlook.com:587/" >> "$muttHome/$1"
|
|
|
|
|
echo "set folder=imaps://$1@imap-mail.outlook.com/" >> "$muttHome/$1"
|
|
|
|
|
echo "set ssl_force_tls=yes" >> "$muttHome/$1"
|
|
|
|
|
echo "set spoolfile=+Inbox" >> "$muttHome/$1"
|
|
|
|
|
echo "mailboxes = +Inbox" >> "$muttHome/$1"
|
|
|
|
|
echo "set postponed=+Drafts" >> "$muttHome/$1"
|
|
|
|
|
echo "set record=+Sent" >> "$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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -333,38 +413,28 @@ configure_generic()
|
|
|
|
|
local smtpHost
|
|
|
|
|
local smtpUser
|
|
|
|
|
local smtpPort
|
|
|
|
|
|
|
|
|
|
# Gather input
|
|
|
|
|
read -p "Enter imap host: " -e -i imap.$hostName imapHost
|
|
|
|
|
read -p "Enter imap user: " -e -i $1 imapUser
|
|
|
|
|
read -p "Enter imap port: " -e -i 993 imapPort
|
|
|
|
|
read -p "Enter smtp host: " -e -i smtp.$hostName smtpHost
|
|
|
|
|
read -p "Enter smtp user: " -e -i $userName smtpUser
|
|
|
|
|
read -p "Enter smtp port: " -e -i 587 smtpPort
|
|
|
|
|
|
|
|
|
|
# Copy the generic template
|
|
|
|
|
cp "$fileDir/generic.template" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Replace placeholders
|
|
|
|
|
sed -i "s|IMAP_HOST|$imapHost|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|IMAP_USER|$imapUser|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|IMAP_PORT|$imapPort|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|SMTP_HOST|$smtpHost|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|SMTP_USER|$smtpUser|g" "$muttHome/$1.tmp"
|
|
|
|
|
sed -i "s|SMTP_PORT|$smtpPort|g" "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Append the template to the existing config
|
|
|
|
|
cat "$muttHome/$1.tmp" >> "$muttHome/$1"
|
|
|
|
|
rm "$muttHome/$1.tmp"
|
|
|
|
|
|
|
|
|
|
# Add any extra settings
|
|
|
|
|
read -p "Enter extra settings, one line at a time, just press enter when done: " extraSettings
|
|
|
|
|
local extraSettings
|
|
|
|
|
read -p "$(gettext "Enter imap host: ")" -e -i imap.$hostName imapHost
|
|
|
|
|
read -p "$(gettext "Enter imap user: ")" -e -i $1 imapUser
|
|
|
|
|
read -p "$(gettext "Enter imap port: ")" -e -i 993 imapPort
|
|
|
|
|
read -p "$(gettext "Enter smtp host: ")" -e -i smtp.$hostName smtpHost
|
|
|
|
|
read -p "$(gettext "Enter smtp user: ")" -e -i $userName smtpUser
|
|
|
|
|
read -p "$(gettext "Enter smtp port: ")" -e -i 587 smtpPort
|
|
|
|
|
read -p "$(gettext "Enter extra settings, one line at a time, just press enter when done: ")" extraSettings
|
|
|
|
|
while [ "$extraSettings" != "" ]; do
|
|
|
|
|
echo "$extraSettings" >> "$muttHome/$1"
|
|
|
|
|
read extraSettings
|
|
|
|
|
read $extreSettings
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Add source for aliases
|
|
|
|
|
echo "unset imap_passive" >> "$muttHome/$1"
|
|
|
|
|
echo "unset record" >> "$muttHome/$1"
|
|
|
|
|
echo "set smtp_url=\"smtp://$smtpUser@$smtpHost:$smtpPort/" >> "$muttHome/$1"
|
|
|
|
|
echo "set folder=imaps://$imapUser@$imapHost:$imapPort/" >> "$muttHome/$1"
|
|
|
|
|
echo "mailboxes = +INBOX" >> "$muttHome/$1"
|
|
|
|
|
echo "set spoolfile = +INBOX" >> "$muttHome/$1"
|
|
|
|
|
echo "set postponed = +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"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -380,7 +450,7 @@ add_keybinding()
|
|
|
|
|
echo "macro generic,index <F$fNumber> '<sync-mailbox><enter-command>source ${muttHome/#$HOME/\~}/$emailAddress<enter><change-folder>!<enter>'" >> "$muttHome/muttrc"
|
|
|
|
|
echo "mail account $emailAddress bound to F$fNumber."
|
|
|
|
|
if ! grep "^source.*@.*\..*" "$muttHome/muttrc" &> /dev/null ; then
|
|
|
|
|
continue="$(yesno "Make $emailAddress the default account?")"
|
|
|
|
|
continue="$(yesno "$(eval_gettext "Make \$emailAddress the default account?")")"
|
|
|
|
|
if [ "$continue" = "Yes" ]; then
|
|
|
|
|
echo "source ${muttHome/#$HOME/\~}/$emailAddress" >> "$muttHome/muttrc"
|
|
|
|
|
fi
|
|
|
|
@ -389,36 +459,30 @@ add_keybinding()
|
|
|
|
|
|
|
|
|
|
new_contact()
|
|
|
|
|
{
|
|
|
|
|
contactName="$(inputbox "Enter the contact's first and last name..")"
|
|
|
|
|
contactName="$(inputbox "$(gettext "Enter the contact's first and last name..")")"
|
|
|
|
|
if [ -z "$contactName" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
contactEmail="$(inputbox "Enter the email address for $contactName")"
|
|
|
|
|
contactEmail="$(inputbox "$(gettext "Enter the email address for") $contactName")"
|
|
|
|
|
if [ -z "$contactEmail" ]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
contactAlias="${contactName,,}"
|
|
|
|
|
contactAlias="${contactAlias// /-}"
|
|
|
|
|
if grep "<$contactEmail>\| $contactAlias " "$muttHome/aliases" &> /dev/null ; then
|
|
|
|
|
[[ "$(yesno "This email address already exists in your contacts. Continue anyway?")" != "Yes" ]] && exit 0
|
|
|
|
|
[[ "$(yesno "$(gettext "This email address already exists in your contacts. Continue anyway?")")" != "Yes" ]] && exit 0
|
|
|
|
|
fi
|
|
|
|
|
echo "alias $contactAlias $contactName <$contactEmail>" >> "$muttHome/aliases"
|
|
|
|
|
sort -u "$muttHome/aliases" -o "$muttHome/aliases"
|
|
|
|
|
msgbox "$contactName added to your address book."
|
|
|
|
|
msgbox "$contactName $(gettext "added to your address book")."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# This is the main loop of the program
|
|
|
|
|
# Call functions to be ran every time the script is ran.
|
|
|
|
|
check_dependancies
|
|
|
|
|
initialize_directory
|
|
|
|
|
|
|
|
|
|
# If in test mode, display a notification
|
|
|
|
|
if [ "$testMode" = true ]; then
|
|
|
|
|
echo "Running in test mode. Using $muttHome for configuration."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Let's make a mainmenu variable to hold all the options for the select loop.
|
|
|
|
|
mainmenu=("Add Email Address" "Configure GPG" "New Contact" "Exit")
|
|
|
|
|
mainmenu=("$(gettext "Add Email Address")" "$(gettext "Configure GPG")" "$(gettext "New Contact")" "$(gettext "Exit")")
|
|
|
|
|
while : ; do
|
|
|
|
|
i="$(IFS=$'\n';menulist $(for i in "${mainmenu[@]}" ; do echo "$i";echo "$i";done))"
|
|
|
|
|
[[ -z "$i" ]] && continue
|
|
|
|
|