# A popup from .procmailrc



> Note: this is an older article that I've revived.
> Also note: in todays email flood I don't know if such
> a popup is something you want to use...

#intro
I've used `gnubiff`, `xbiff` and God knows what to
provide a simple notify when receiving mail. But I wanted more.
I want to be able to tweak certain settings, without going in to
the source code of the application. Also the way mail notifiers
mess with your mailbox is not something I particularly like.

what then?
I wanted something that runs from `.procmailrc`, so that every time
an *email comes in* an action is undertaken. This means no
fiddling with your mailbox, because it just runs from the .procmailrc.

using procmail to notify you
First I just played a sound from .procmail, but I also wanted some 
popup which could display the `From:` and/or the `Subject`
field(s).

GNOME notify popup
I wanted to use the `notify-send` to give me the mailpopups as these
are much more slicker than a gmessage. The `.procmail` part is the
same as described below, only the script is different. The program
`notify-send` is part of the package `libnotify-bin`

I now call a script called `mailpop.sh` which looks like this:

    #!/bin/bash
    # popup a small notification with 'notify-send'
    dis=`formail -X From: -X Subject:`
    # sometimes the order is difference - in very short headers
    # check for both
    if [[ "$dis" =~ "From:(.+)Subject:(.+)" ]]; then
	    from=${BASH_REMATCH[1]}
	    sub=${BASH_REMATCH[2]}
    fi
    if [[ "$dis" =~ "Subject:(.+)From:(.+)" ]]; then
	    from=${BASH_REMATCH[2]}
	    sub=${BASH_REMATCH[1]}
    fi

    # tweaks < > are special
    from=${from//</\(}
    from=${from//>/\)}
    from=${from//&/\.}
    sub=${sub//</\(}
    sub=${sub//>/\)}
    sub=${sub//&/\.}

    sub=${sub:0:75}
    from=${from:0:75}
    TM=2000

    # from http://gnome-hacks.jodrell.net/hacks.html?id=82
    # modified for GNOME-2.14
    pids=`pgrep -u miekg 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 $TM "$sub" "$from"
    done

The tricky part was getting the `SESSION_BUS_ADDRRESS` thingy.

hooking up .procmailrc
That is a bit of a no brainer, just add something like the following:

    # notify the user
    :0 c
    * 
    | $HOME/bin/mailpop.sh

In your `.procmailrc`. 
That's it. When ever a mail comes in a popup is displayed and a sound is heard,
and you can tweak this is much as you like.

