#!/bin/sh
#
# Checking mail on a remote system
# ================================
# It is possible to use xmailbox to check whether you have mail on another
# host, provided you can check with a finger or something similar.
#
# For example, my mail at university is delivered to a machine called
# hermes.cam.ac.uk; I can check mail on it by telnetting to port 2345. If
# I have mail it says
#
#	v0.04
#	Unread mail for mnb20.
#
# If I don't, it says
#
#	v0.04
#	No unread mail for mnb20.
#
# So I can use this script to check my mail.
#
# If it finds the string Unread, then I definitely have mail, and it returns
# zero; if it finds the string No, then I definitely don't have mail, and it
# returns two; if it doesn't find either, then something isn't working, or is
# disabled because of heavy load on the machine, so it returns one meaning it
# doesn't know.
#
# You should write a script similar to mine, but obviously tailored to your
# environment (exactly the same but with a finger in place of the echo|socket
# seems to work well) and returning the same values.
#
# The script is then installed by setting resources for xmailbox in your
# /etc/X11/Xresources file:
#
#	XMailbox*checkCommand:	/usr/local/bin/yourscript
#	XMailbox*update:	300
#
# The update resouce specifies how often to update it; it isn't necessary to
# set it, but leaving it at the default of 30 seconds isn't very nice to other
# users of your server.

_mail=$(echo $USER|socket hermes.cam.ac.uk 2345)

if [ "$(echo "$_mail" | grep ^Unread)" ]; then
        exit 0
elif [ "$(echo "$_mail" | grep ^No)" ]; then
        exit 2
else
        exit 1
fi
