mail: Fix checkmail script password bugging

Fixed script to only ask for password once before understanding that the
user does not want to provide it.

Since gpg seems to not differentiate between a *wrongly* entered
password and one entered not at all, we have to assume the user canceled
the password prompt and not bug him again until the next time the script
is invoked.
It will, however, at least notify the user that the process is aborted
in a quick notification message, so that if it was done on accident the
user will still know what's up.
This commit is contained in:
Marty Oehme 2021-08-19 00:15:44 +02:00
parent f94759697d
commit 78b47a35b2
Signed by: Marty
GPG key ID: B7538B8F50A1C800

View file

@ -68,17 +68,27 @@ checkonline() {
checkwarnuser() { checkwarnuser() {
agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode cancel "$PASSWORD_FILE" 2>&1) agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode cancel "$PASSWORD_FILE" 2>&1)
if echo "$agt" | grep -qE 'No secret key'; then if echo "$agt" | grep -qE 'No secret key'; then
notify "Mail: Password phrase needed!" notify "Mail" "Password phrase needed!"
sleep 2.5 sleep 2.5
fi fi
} }
enablegpgagent() {
## get password from user
agt=$(gpg2 --decrypt --no-tty --quiet --no-verbose --for-your-eyes-only --pinentry-mode ask "$PASSWORD_FILE" 2>&1)
## exit program after first failed attempt
if echo "$agt" | grep -qE 'decryption failed'; then
notify "Mail" "Process aborted."
exit 1
fi
}
# send out a notification on new mail, to libnotify and stdout # send out a notification on new mail, to libnotify and stdout
notifymail() { notifymail() {
[ "${MBSYNC_NOTIFY:-1}" -eq 0 ] && return [ "${MBSYNC_NOTIFY:-1}" -eq 0 ] && return
if [ "${HASMAIL:-0}" -gt 0 ]; then if [ "${HASMAIL:-0}" -gt 0 ]; then
notify "($HASMAIL) new mail" notify "Mail" "New Mail ($HASMAIL)"
fi fi
} }
@ -100,6 +110,8 @@ fi
main() { main() {
checkwarnuser checkwarnuser
enablegpgagent
prehook prehook
tries=0 tries=0