Periodic notification of received mails processed by dovecot’s sieve

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/

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/ 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)
messages=$(since /tmp/dovecot-deliver.log)

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/ "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
# modified for GNOME-2.14
pids=`pgrep -u $THEUSER gnome-panel`

for pid in $pids; do
# find DBUS session bus for this session
/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.

3 thoughts on “Periodic notification of received mails processed by dovecot’s sieve”

  1. If this happens on the same machine you’re working on, can’t you use dbus from procmail to send such a notification in real-time? Or use another pubsub (xmpp comes to mind) if it’s happening on a different host?

  2. Dunno about dbus sending from a shell script, but I guess that’s what notify-send is doing more or less… but it won’t work from a crontab if there’s no DBUS_SESSION_BUS_ADDRESS set… hence the script But YMMV.

    I don’t need remote notification, anyway.

Leave a Reply

Your email address will not be published. Required fields are marked *