#!/usr/bin/perl

use strict;
use warnings;
use Sys::Syslog;

# $Id: read_excess.pl 147 2008-06-22 22:08:36Z ed $
# $URL: svn+ssh://fw/repos/code/perl/qmail/read_excess.pl $

sub log_excess {
	my $excess = shift;

	open( F, ">>/tmp/excess" )
		or syslog( 'LOG_DEBUG', "cannot open /tmp/excess:$!" );
	print( F $excess, ":deny", "\n" );
	close(F);
}

openlog( "read_excess[$$]", "LOG_PID", "LOG_DAEMON" );
syslog( 'LOG_DEBUG', "running" );

while( my $l = <STDIN> ) {
	chomp $l;

	if( $l =~ /validrcptto \[(.+)\] excessive violations, hanging up/ ) {
		log_excess( $1 );
		syslog( 'LOG_DEBUG', "$1 found" );
	}
	print( STDOUT "$l\n" );
}

open( F, ">/etc/tcp.smtp" ) or exit;
open( FF, "</etc/tcp.smtp.old" ) or exit;

while( <FF> ) {
	print( F $_ );
}
close(FF);

open( FF, "</tmp/excess" ) or exit;

while( <FF> ) {
	print( F $_ );
}
close(FF);

close(F);

