dotfiles/bin/scripts/check-email
2021-02-28 15:01:49 +03:00

27 lines
692 B
Bash
Executable file

#!/bin/bash
export DISPLAY=:0
CHECK_FILE="/home/pavel/Mail/.last_check"
QUERY="tag:unread"
ALL_QUERY="tag:unread"
if [ -f "$CHECK_FILE" ]; then
DATE=$(cat "$CHECK_FILE")
QUERY="$QUERY and date:@$DATE.."
fi
notmuch new
NEW_UNREAD=$(notmuch count "$QUERY")
ALL_UNREAD=$(notmuch count "$ALL_QUERY")
if [ $NEW_UNREAD -gt 0 ]; then
MAIN_UNREAD=$(notmuch count "tag:unread AND tag:main")
PROGIN_UNREAD=$(notmuch count "tag:unread AND tag:progin")
read -r -d '' NOTIFICATION <<EOM
$NEW_UNREAD new messages
$MAIN_UNREAD thexcloud@gmail.com
$PROGIN_UNREAD progin6304@gmail.com
$ALL_UNREAD total
EOM
notify-send "New Mail" "$NOTIFICATION"
fi
echo "$(date +%s)" > $CHECK_FILE