mail jig



In the same vein as That Stupid Thing I Wrote The Other Day series; maybe this will be useful to someone:


# On my desktop,  I only want mail to be checked if I'm using the
# machine. Otherwise I want it to leave the mail on the server so my
# laptop can fetch it.

# idletime gets touched every three minutes while idle
xautolock -time 3 -locker "touch ~/.idle" &

# keep the mail on the server if i'm on my laptop
if [ `hostname` = "vannevar" ] ; then

while [ 1 ]
    touch ~/.three.minutes.old
    sleep 3m

    if [ ~/.idle -ot ~/.three.minutes.old ]; then
        # not idle!
        fetchmail -k >/dev/null 2>&1

        if [ "$?" = "0" ]; then
            notify-send -u low "New mail"

I've got a laptop and a desktop. I want to check mail on the desktop and have that act as the definitive copy. So when the desktop pulls in mail, it deletes it off the server. I want to use the laptop to pull in mail, but only when I'm not at my desktop. It keeps a non-authoritative copy that may have vast holes in its archives; no big deal.

The problem is, I don't want mail to get checked when I'm away from my desktop. I could just manually start and stop the fetchmail dæmon, but that's tacky. This script uses xautolock to determine the idle time of X. If it's been active in the last three minutes, it should pull in the mail; otherwise leave it alone. If it's on my laptop (vannevar) then keep mail on the server for my desktop to consume.

As you can see, I'm no shell wizard. Using hidden files is slightly tacky, but it gets the job done.

« older | 2007-10-13T07:00:01Z | newer »