#!/usr/bin/perl

@lines = <>;
$fnshow = 'queueshow.pl';
$ct = 3;
$i = 0;
$j = 0;
@Days = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
#print $Days[$wday];

$sw = $ARGV[0];

foreach $line (@lines)
{
#	print "$i $line";$i++;
	if ( $line =~ /(^-|^[\ \s\t]*$)/ ) { }
	elsif ( $i == 0 ) {
		$l1 = $line;
		($id,$d,$mday,$d,$d,$d,$mail) = split(/[\ ]+/,$line);
		$mail =~ s/\n//;
		$dnum = &chDay($mday);
		if ( $wday == $dnum ) {}
		elsif ( $wday > $dnum ) {
			if ($wday > ($dnum + $ct)) { $job = "remove"; }
		}
		else {
			if ( ($wday + 7) > ($dnum + $ct) ) { $job = "remove"; }
		}
		$i++;
	}
	elsif ($i == 1) {
		if ($line =~ /^\(service\ unavailable\.\ Command\ output\:\ \[spam words detected/) {
			$spam = 1;
		}
		$i++;
	}
	else { $i++;  }
	if ($i > 2) {
		if ( $0 =~ /$fnshow$/ ) {
			if ($job) { $prec = "*"; $postc = "*" }
			if ($spam) { print "$prec$id $mday $mail $job$postc\n"; $j++;}
		}
		else {
			if ($job && $spam) { print "$id\n"; }
		}
		$i = 0;
		$spam = 0;
		$job = "";
		$prec = "";
		$postc = "";
	}
}
if ( $j ) { print "total $j\n"; }
exit;

sub chDay () {
	my($i) = 0;
	$dayt = @_[0];
	foreach $dayl (@Days)
	{
		if ($dayl eq $dayt) {
			return $i;
		}
		$i++;
	}
	exit 1;
}
