mail: HACK mailcheck update

Update `mail-check` script to notify the user both of newly arrived
mail, and in case he has to enter his password to sync the mail.

HACK the paths and ways of finding out if passwords can be decrypted are
static and only applicable to my set up. This needs to be completely
revised and newly approached.
This commit is contained in:
Marty Oehme 2020-09-24 14:23:06 +02:00
parent c5cd2b6a8d
commit 3fa7f8a6db
Signed by: Marty
GPG key ID: B7538B8F50A1C800

View file

@ -11,7 +11,11 @@
# for more advanced, per-account/channel hooks, see
# https://sourceforge.net/p/isync/feature-requests/8/
MBSYNC_MAX_TRIES=3
# available env vars:
# MBSYNC_MAX_TRIES=3
# MBSYNC_PRE="/bin/usr/cmd-to-run"
# MBSYNC_POST="/bin/usr/cmd-to-run"
# MBSYNC_NOTIFY=1
prehook() {
if [ -n "$MBSYNC_PRE" ]; then
@ -26,8 +30,17 @@ posthook() {
eval "$MBSYNC_POST"
return 0
fi
notmuch new --quiet 2>/dev/null
afew --tag --new
notmuch new 2>/dev/null
afew --tag --new -C "${XDG_CONFIG_HOME:-/home/marty/.config}/notmuch/config"
countnew
}
# use notmuch to index incoming mail and set the
# correct number of mails if new ones arrived for notifications
countnew() {
num=$(notmuch count tag:unread and tag:inbox)
HASMAIL="${num:-0}"
}
# fail the routine and optionally send a message why
@ -37,7 +50,7 @@ fail() {
}
checkmail() {
mbsync -c "$XDG_CONFIG_HOME/isync/mbsyncrc" -a
mbsync -c "${XDG_CONFIG_HOME:-$HOME/.config}/isync/mbsyncrc" -a
}
checkonline() {
@ -45,6 +58,30 @@ checkonline() {
ping -c 1 "1.1.1.1" >/dev/null 2>/dev/null || fail "checkmail can not access the internet."
}
# warn user that he has to enter his password in a moment
# to stop catching him offguard or entering something by accident
checkwarnuser() {
agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode cancel ~/.local/share/pass/misc/aerc-gmail-app-password.gpg 2>&1)
if echo "$agt" | grep -qE 'No secret key'; then
notify "Mail: Password phrase needed!"
sleep 2.5
fi
}
# send out a notification on new mail, to libnotify and stdout
notifymail() {
[ "${MBSYNC_NOTIFY:-1}" -eq 0 ] && return
if [ "${HASMAIL:-0}" -gt 0 ]; then
notify "($HASMAIL) new mail"
fi
}
notify() {
command -v notify-send >/dev/null && notify-send "$@"
echo "$@"
}
# Routine start
# check
@ -56,6 +93,8 @@ if [ "$1" = "raw" ]; then
fi
main() {
checkwarnuser
prehook
tries=0
@ -65,13 +104,15 @@ main() {
fi
tries=$((tries + 1))
if [ $tries -gt $MBSYNC_MAX_TRIES ]; then
if [ $tries -gt "${MBSYNC_MAX_TRIES:-3}" ]; then
fail "maximum retries reached without success."
fi
done
unset tries
posthook
notifymail
}
notmuch_foldertags() {
@ -81,4 +122,3 @@ notmuch_foldertags() {
}
main
notmuch_foldertags