#! /bin/bash
# © 2006 Heiko Schlittermann
# You may use this script on you own risk.  It is published here under
# the terms of the GNU Copyright.

# Example:
# defer	condition = ${run{.../unseen $sender_host_address 300}{$value}}
#	log_message = gray unseen ($sender_host_address)

test -t 0 && trap "echo" EXIT

NAME="$1"; shift
DELAY="${1:-600}"; shift
BASE="${1:-/var/run/exim/grey.d}"; shift

NAME=${NAME//.//}
DIR=$BASE/${NAME%/*}
FILE=$DIR/${NAME##*/}


test -d "$DIR" || mkdir -p "$DIR"

test -f "$FILE" || {
	> "$FILE"
	echo -n yes
	exit 0 
}

# AGE = (current time) - (time of last modification of "$FILE")
# please check your systems 'stat' command!
AGE=$(($(date +%s) - $(stat -c '%Y' "$FILE")))

test $AGE -lt $DELAY && {
	echo -n yes
	exit 0
}

read <"$FILE"
echo -n no
exit 0
