#!/usr/bin/perl

# stopwblue.pl
# Kyoma TAKAHASHI 1999/10/29
#   Thanks for Okuyama's help

$cnt = 0; $mailhb = '';

while (<STDIN>) {
	if (/^To:\s+epmail.+/) { $cnt += 1 }
	if (/^To:\s+postmaster.+/) { $cnt += 1 }
	$mailhb .= $_;
}

if ( $cnt < 2 ) { print $mailhb; exit 0; }
else {
	$from = $ENV{'SENDER'}; $to = $ENV{'RECIPIENT'};
	$ermsg = 'Message from '.$from.' to '.$to.' is going to start chain reaction!! Stopped it.';
	system "/usr/bin/logger -t stopwepmail.pl '$ermsg'";
	open (STOPMAIL,">> /home/epmail/stopped-mail");
	print STOPMAIL $mailhb;
	close (STOPMAIL);
	exit 99;
}

