#
# $Id: filter_nnrpd.pl,v 1.1.1.1 1997/08/04 04:03:49 gpalmer Exp $
#
# Sample perl filtering code for nnrpd hook.
#

#
# This file is loaded when nnrpd starts up. If it defines a sub named
# `filter_post', then that function will be called during processing of a
# posting. It has access to the headers of the article via the associative
# array `%hdr'. If it returns a null string then the article is accepted
# for posting. A non-null stringrejects it, and the value returned is used
# in the rejection message.
#

# Sample filter
#
#sub filter_post {
#    my $rval = "" ;		# assume we'll accept.
#
### Uncomment this next block to reject articles that have 'make money'
### in their subject, or which have a "Re: " subject, but no References:
### header, or which have an invalid From.
#
##    if ($hdr{"Subject"} =~ /make.*money/i) {
##	$rval = "Spam is not acceptable here..." ;
##    } elsif ($hdr{'Subject'} =~ /^Re: /o and $hdr{'References'} eq "") {
##	$rval = "Followup without References:";
##    } elsif ($hdr{'From'} =~ /^\w*$/o or
##	$hdr{'From'} !~ /^(.+?)\@([-\w\d]+\.)*([-\w\d]+)\.([-\w\d]{2,})$/o) {
##	$rval = "From: is invalid, must be user\@[host.]domain.tld";
##    }
#
#	$rval ;
#}
#

my $lasttime = 0;
my $serial = 0;

sub filter_post {
    my $rval = "";


        if ($hdr{'Path'} =~ /unwanted/) {
         $rval = "You are not allowed to post";
         }
	elsif ($hdr{'Message-ID'} =~ /unwanted/) {
	$rval = "Non puoi farlo";
	} 
	elsif ($hdr{'Newsgroups'} =~ /./) {

#       # Disallow crossposting to avoid unforeseen abuses
#       if ($hdr{"Newsgroups"} ne "test") {
#           $rval = "No crossposting between test and other groups";
#       }
#       else {
        
	   $modify_headers = 1;
           $hdr{'X-Trace'} = "";
	   $hdr{'NNTP-Posting-Host'} = "";
	   $hdr{'X-Newsreader'} = "";
           $hdr{'X-MSMail-Priority'} = "";
           $hdr{'X-Priority'} = "";
           $hdr{'X-Mailer'} = "";
	   $hdr{'X-MimeOLE'} = "";
	   $hdr{'Sender'} = "";
	   $hdr{'X-Sender'} = "";
	   $rval = "";
	} elsif ($hdr{"Newsgroups"} =~ /^anon/) {
           $modify_headers = 1;
           # Give everyone the same From: header.
           $hdr{'From'} = "Anonymous ";

           # Hide the originating host.
           $hdr{'X-Trace'} = "";
           $hdr{'NNTP-Posting-Host'} = "";
           $hdr{'Organization'} = "";
           $hdr{'User-Agent'} = "anon v.666";
           $hdr{'Reply-To'} = "";
           $hdr{'X-Newsreader'} = "";
           $hdr{'X-MSMail-Priority'} = "";
           $hdr{'X-Priority'} = "";
           $hdr{'X-Mailer'} = "";
           $hdr{'X-MimeOLE'} = "";


           # Clobber the Message-ID
           my $thistime = time();
           if ($thistime != $lasttime) {
               $serial = 1;
           }
           else {
               $serial++;
           }
           $lasttime = $thistime;
           $hdr{'Message-ID'} = "<$thistime.$$.$serial\@" . localhost . ">";
    	} $rval;
}