#!/bin/sh

# Copyright (c) 1998 Software in the Public Interest <http://www.debian.org>
# written by Philip Hands <phil@hands.com> (2 April 1998), inspired by a
# script by Timothy L. Mayo <tmayo@mayod.nb.net>, distributed under the GPL

EMPTY="d41d8cd98f00b204e9800998ecf8427e"
SUM="md5sum"
# if you don't have md5sum, use something like these two lines instead
# EMPTY="00000     0"
# SUM="sum -r"

MAILSUM="`ls $HOME/Maildir/new | $SUM`"

# if "new" is empty, remove the debris, and exit
if [ "$MAILSUM" = "$EMPTY" ]; then
    test -f $HOME/.prevmail && rm $HOME/.prevmail
    exit 2
fi

# check if the sums are unchanged
if [ -f $HOME/.prevmail ] && [ "$MAILSUM" = "`cat $HOME/.prevmail`" ]; then
    exit 1
fi

# otherwise new mail has arrived
echo -n $MAILSUM > $HOME/.prevmail
exit 0

# End of Script
