#!/usr/athena/bin/perl

# $Header: /afs/sipb/service/rtfm-new/src/mail-server/RCS/bounce.plin,v 1.2 1995/10/04 00:00:52 ghudson Exp arolfe $

push(@INC, '/rtfm/mserv');

require 'mservlib.pl';
require 'syslog.pl';
require 'sysexits.ph';

$bounce_new = $lib'bounce_last . "." . $$;

&openlog($logname, 'pid', $lib'logservice);

open(BOUNCE_LOG, ">>$lib'bounce_log") || die;
open(BOUNCE_LAST, ">>$bounce_new") || die;

while (<STDIN>) {
    print BOUNCE_LAST $_;
    if (/^To: / || /^From: /) {
	print BOUNCE_LOG $_;
    }
}

print BOUNCE_LOG "---\n";

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,
$ctime,$blksize,$blocks) = stat($lib'bounce_log);
if ($size > 100000) {
	&syslog('err', "Bounce log size $size, exceeds 100000 bytes.");
}

unlink($lib'bounce_last) && rename($bounce_new, $lib'bounce_last);
unlink($bounce_new); # Don't leave file around if unsuccessful.

