scripts/mail-notify.bash
2016-07-27 19:18:44 +02:00

43 lines
965 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/bash
# Settings
MAILDIRNEW="$HOME/Downloads/Mail/*/INBOX/new/"
TMPFILE="/tmp/mail-notify.stat"
SOUNDFILE="$HOME/.local/share/sounds/mail-received.wav"
# run mail sync
$@
# Get modification date
MODOLD=0
if [ -f "$TMPFILE" ]; then
MODOLD="$(cat $TMPFILE)"
fi
MODNEW="$(find $MAILDIRNEW -type d -printf '%T@\n' | sort -n | tail -1 | cut -d "." -f 1)"
if [ $MODNEW -le $MODOLD ]; then
exit 0
fi
echo "$MODNEW" > "$TMPFILE"
# Count new mails
MAILNEW="$(find $MAILDIRNEW -type f | wc -l)"
# Notify
if [ $MAILNEW -gt 0 ]
then
# Send text
if [ $MAILNEW -gt 1 ]; then
notify-send -a "Mail" -c "email.arrived" -i "mail-message-new" "Neue EMails" "$MAILNEW neue EMails sind eingetroffen!"
else
notify-send -a "Mail" -c "email.arrived" -i "mail-message-new" "Neue EMails" "$MAILNEW neue EMail ist eingetroffen!"
fi
# Play sound
if [ -e "$SOUNDFILE" ]; then
paplay "$SOUNDFILE"
fi
fi