#!/usr/bin/perl -s
# Original von Chris Manly newsmgr@cornell.edu 1.5.96
# angepasst von Uwe@Debacher.de
# letzte Aenderung 6.10.98

$tmp_posting = "/tmp/post2news.$$";
$tmp_inews = "/tmp/inews.$$";
$dest = $ARGV[0];
$gatewayaddress = "news\@gyloh.hh.schule.de\n";

open (INLIST, "cat >>".$tmp_posting." -|") || die "$!\n";
sleep(2);
close(INLIST);

open (DATAFILE, "<".$tmp_posting) || die "$!\n";
open (OUTFILE, ">".$tmp_inews) || die "$!\n";

while(<DATAFILE>) {
    if(/^Path: server.gyloh.hh.schule.de!mail-to-news/) {
	close(DATAFILE);
	close(OUTFILE);
	unlink($tmp_posting);
	unlink($tmp_inews);
	exit 0;
    } elsif (/^From:/) {
	print OUTFILE "Resent-From:     ",$gatewayaddress;
	print OUTFILE $_;
	($from,$sender) = split(' ',$_,2);
    } elsif (/^Reply/) {				
	$reply = 1;
	print OUTFILE $_;
    } elsif (/^\s*$/ && !$reply) {	# End of headers and no Reply to header
	print OUTFILE "Reply-to: $sender\n\n";
	$reply = 1;
    } else {
	print OUTFILE $_;
    }
}			       
close (OUTFILE);
system( "/usr/lib/sendmail $dest < $tmp_inews");

#unlink($tmp_posting);
#unlink($tmp_inews);


