# Checks for internet connection and set notification script.
ping -q -c 1 1.1.1.1 > /dev/null || { echo "No internet connection detected."; exit ;}
command -v notify-send >/dev/null || echo "Note that \`libnotify\` or \`libnotify-send\` should be installed for pop-up mail notifications with this script."
# Settings are different for MacOS (Darwin) systems.
if [ "$(uname)" = "Darwin" ]; then
notify() { osascript -e "display notification \"$2 in $1\" with title \"You've got Mail\" subtitle \"Account: $1\"" && sleep 2 ;}
else
notify() { notify-send "mutt-wizard" "📬 $2 new mail(s) in \`$1\` account." ;}
fi
# Check account for new mail. Notify if there is new content.
syncandnotify() {
mwacc="$(echo "$mwaccount" | sed "s/.*\///")"
mwaccmaildir="$mwmaildir/$mwacc"
$mwmbsyncbin "$mwacc"
mwnew=$(find "$mwaccmaildir/INBOX/new/" "$mwaccmaildir/Inbox/new/" "$mwaccmaildir/inbox/new/" -type f -newer "$mwlastrun" 2> /dev/null)
newcount=$(echo "$mwnew" | sed '/^\s*$/d' | wc -l)
printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`$GPG --full-gen-key\` first.\\n"
exit
}
! command -v "$prefix/bin/mbsync" >/dev/null && printf "\`mbsync\` must be installed to run mutt-wizard.\\n" && exit
! command -v "$prefix/bin/msmtp" >/dev/null && printf "\`msmtp\` must be installed.\\n" && exit
! ( command -v mutt >/dev/null || command -v neomutt >/dev/null ) && printf "\`mutt\` must be installed.\\n" && exit
for mwcrt in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/"
do
[ -f "$mwcrt" ] && mwsslcert="$mwcrt" && break
done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;}
_mwgetaccounts() {
mwaccounts="$(find "$mwaccmuttdir" -type f | grep -o "[1-9]-.*.muttrc" | sed "s/-/: /;s/\.muttrc//" | sort -n)"
_mwaccs() {
mwaccs="$(find "$mwaccmuttdir" -type f | grep -o "[1-9]-.*.muttrc" | sed "s/-/: /;s/\.muttrc//" | sort -n)"
for mwcrt in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/"
do
[ -f "$mwcrt" ] && mwsslcert="$mwcrt" && break
done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && return 1 ;}
printf "Creating profiles for \`%s\`..." "$mwaddr"
mwmsmtpheader="defaults
auth on
tls on
tls_trust_file $mwsslcert
logfile ${XDG_LOG_HOME:-$HOME}/msmtp.log
authon
tlson
tls_trust_file$mwsslcert
logfile${XDG_LOG_HOME:-$HOME}/msmtp.log
"
mwmsmtpprofile="account $mwacc
host $mwsmtp
@@ -85,8 +75,8 @@ passwordeval \"pass $mwpass\"
$mwstarttlsoff
"
mwmbsyncprofile="IMAPStore $mwacc-remote
Host $mwimap
Port $mwiport
Host $mwserver
Port $mwport
User $mwlogin
PassCmd \"pass $mwpass\"
SSLType $mwssltype
@@ -108,294 +98,246 @@ SyncState *
MaxMessages 0
# End profile
"
if [ "$mwtype" = "offline" ]; then
mwmuttprofile="# vim: filetype=neomuttrc
# muttrc file for account $mwaddr
set realname = \"$mwname\"
set from = \"$mwaddr\"
set sendmail = \"$msmtpbin -a $mwacc\"
alias me $mwname <$mwaddr>
set folder = \"$mwaccmaildir\"
set mbox_type = Maildir
macro index gm \"<shell-escape>mailsync $mwacc<enter>\" \"sync mail $mwaddr\"
printf "Your email domain is not known to mutt-wizard.\\nType in your settings.\\nUsually you find them by an internet search.\\n"
printf "Type the IMAP server (excluding the port number)\\n\033[36m\t"
read -r mwimap
printf "\033[0mIMAP port number (usually 993)\\n\033[36m\t"
read -r mwiport
printf "\033[0mSMTP server (excluding the port number)\\n\033[36m\t"
read -r mwsmtp
printf "\033[0mSMTP port number (usually 587 or 465)\\n\033[36m\t"
read -r mwsport
printf "\033[0m\\nIf you want, you can copy the line below and add it to the \`domains.csv\` file on Github, for others.\\n\\n%s,%s,%s,%s,%s\\n\\nBut be sure the setting works, first! ;-)\\n" "$mwdomain" "$mwimap" "$mwiport" "$mwsmtp" "$mwsport"
printf "Your email domain is not known to mutt-wizard.\\nType in your settings.\\nUsually you find them by an internet search.\\n"
printf "Type the IMAP/POP3 server (excluding the port number)\\n\033[36m\t"
read -r mwserver
printf "\033[0mIMAP port number (usually 993)\\n\033[36m\t"
read -r mwport
printf "\033[0mSMTP server (excluding the port number)\\n\033[36m\t"
read -r mwsmtp
printf "\033[0mSMTP port number (usually 587 or 465)\\n\033[36m\t"
read -r mwsport
printf "\033[0m\\nIf you want, you can copy the line below and add it to the \`domains.csv\` file on Github, for others.\\n\\n%s,%s,%s,%s,%s\\n\\nBut be sure the setting works, first! ;-)\\n" "$mwdomain" "$mwserver" "$mwport" "$mwsmtp" "$mwsport"
printf "\\n\033[3;33mCongrats!\033[0m Server info is known, so you don't need to look it 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\\n" "$mwimap" "$mwiport" "$mwsmtp" "$mwsport"
case "$mwservice" in
gmail.com) printf "\033[31mGmail: \"less secure\" must be enabled before you continue.\\nDo it now, if you have not done it already:\\nhttps://support.google.com/accounts/answer/6010255\\n\033[0m" ;;
protonmail.ch|protonmail.com|pm.me) printf "\033[31mProtonmail: Users must install and configure Protonmail Bridge for the sync to work:\\nhttps://protonmail.com/bridge/\\n\033[0m" && ssltype="None" ;;
printf "Type your account username if different from your email address.\\n\033[34mFor most accounts you can probably leave this blank.\033[0m\\n\tLogin(?): \033[36m"
read -r mwlogin
printf "\033[0m"
[ -z "$mwlogin" ] && mwlogin="$mwaddr"
fi
# if the user has a pass entry he could provide it via mwpass
printf "\\n\033[3;33mCongrats!\033[0m Server info is known, so you don't need to look it 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\\n" "$mwserver" "$mwport" "$mwsmtp" "$mwsport"
case "$mwservice" in
gmail.com) printf "\033[31mGmail: \"less secure\" must be enabled before you continue.\\nDo it now, if you have not done it already:\\nhttps://support.google.com/accounts/answer/6010255\\n\033[0m" ;;
protonmail.ch|protonmail.com|pm.me) printf "\033[31mProtonmail: Users must install and configure Protonmail Bridge for the sync to work:\\nhttps://protonmail.com/bridge/\\n\033[0m" && ssltype="None" ;;
printf "Type your account username if different from your email address.\\n\033[34mFor most accounts you can probably leave this blank.\033[0m\\n\tLogin(?): \033[36m"
read -r mwlogin
printf "\033[0m"
[ -z "$mwlogin" ] && mwlogin="$mwaddr"
fi
# if the user has a pass entry he could provide it via mwpass
printf "\033[31m\033[31mLog-on not successful.\033[0m\\nIt seems that either you inputted the wrong password or server settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
return 1
fi
if [ ! -d "$mwaccmaildir" ]; then
mwaccmaildirWasThere="NO" # we need to remove again for "online"
printf "\033[31m\033[31mLog-on not successful.\033[0m\\nIt seems that either you inputted the wrong password or server settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
return 1
fi
}
_mwfinalize() { # new mwaccmuttrc
mwboxes="$(find "$mwaccmaildir/" -name cur | sed "s,$mwaccmaildir/,,g;s,/cur,,")"
if [[ "$mwboxes" =~ ^[[:space:]]*$ ]]; then
printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that mbsync has not been successfully run.\\nRun mbsync, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$mwacc"
printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`$GPG --full-gen-key\` first.\\n"
exit
}
! command -v "$prefix/bin/mbsync" >/dev/null && printf "\`mbsync\` must be installed to run mutt-wizard.\\n" && exit
! command -v "$prefix/bin/msmtp" >/dev/null && printf "\`msmtp\` must be installed.\\n" && exit
! ( command -v mutt >/dev/null || command -v neomutt >/dev/null ) && printf "\`mutt\` must be installed.\\n" && exit
case "$1" in
ls) _mwlist ;;
add) _mwadd ;;
pass) _mwpick "change the password of" && _mwgetpass ;;