I’m using dovecot’s sieve to filter incoming mail into different folders. As this works in the backround (through fetchmail + procmail + dovecot’s deliver), I may not know that new mail is available until I check in Gnus or notmuch.
So I’d like to be notified by notification popups in my Gnome desktop (I’m using gnome3′s fallback session, FWIW).
I’ve added the following crontab (crontab -e) :
* * * * * ~/bin/dovecot-logs-stats.sh
This is a shell script that will check the new lines added to dovecot’s sieve log file, counting how much new mails have been added in each folder.
It then uses a
~/bin/notify-send.sh wrapper around notify-send to send the notifications to Gnome (actually, this should work with any other Desktop environment, via small adjustments).
Here’s a copy of the scripts :
# depends on since in package since (apt-get install sinnce)
mailboxes=$(echo "$messages" | grep 'stored mail into mailbox' | sed 's/.*stored mail into mailbox //g' | sed "s/'//g" | sort -u)
for i in $mailboxes
count=$(echo "$messages" | grep "stored mail into mailbox '$i'" | wc -l)
msg="$msg$i : $count\n"
if [ "x$msg" != "x" ]
~/bin/notify-send.sh "new mail" "$msg"
Note that this script depends on the
since command (from the Debian package since), which is a great tool that displays additions to a
(log) file since its last execution.
You may wish to adjust to the path of your dovecot deliver’s logs.
# from http://gnome-hacks.jodrell.net/hacks.html?id=82
# modified for GNOME-2.14
pids=`pgrep -u $THEUSER gnome-panel`
for pid in $pids; do
# find DBUS session bus for this session
DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
/proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
# use it
DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send -u normal -t 2000 "$1" "$2"
This was borrowed from a post somewhere, which credited an original post again (see URL above). Of course, you need to adjust to your username or the proper process whose environment will be inspected in case you don’t run gnome-panel.