2 # $Id: filter_nnrpd.pl 5981 2002-12-12 05:01:42Z vinocur $
4 # Sample perl filtering code for nnrpd hook.
8 # This file is loaded when nnrpd starts up. If it defines a sub named
9 # `filter_post', then that function will be called during processing of a
10 # posting. It has access to the headers of the article via the associative
11 # array `%hdr'. If it returns a null string then the article is accepted
12 # for posting. A non-null string rejects it, and the value returned is used
13 # in the rejection message.
17 # Do any initialization steps.
19 my %config = (checkincludedtext => 0,
23 antiquotere => '^[<]', # so as not to reject dict(1) output
31 my $rval = "" ; # assume we'll accept.
33 ### Uncomment this next block to reject articles that have 'make money'
34 ### in their subject, or which have a "Re: " subject, but no References:
35 ### header, or which have an invalid From.
37 ## if ($hdr{"Subject"} =~ /make.*money/i) {
38 ## $rval = "Spam is not acceptable here..." ;
39 ## } elsif ($hdr{'Subject'} =~ /^Re: /o and $hdr{'References'} eq "") {
40 ## $rval = "Followup without References:";
41 ## } elsif ($hdr{'From'} =~ /^\w*$/o or
42 ## $hdr{'From'} !~ /^(.+?)\@([-\w\d]+\.)*([-\w\d]+)\.([-\w\d]{2,})$/o) {
43 ## $rval = "From: is invalid, must be user\@[host.]domain.tld";
47 ### The next block rejects articles with too much quoted text, if the
48 ### config hash directs it to.
50 if ($config{checkincludedtext}) {
51 my ($lines, $quoted, $antiquoted) = analyze($body);
52 if ($lines > $config{includedcutoff}
53 && $quoted - $antiquoted > $lines * $config{includedratio}) {
54 $rval = "Article contains too much quoted text";
62 my ($lines, $quoted, $antiquoted) = (0, 0, 0);
66 if ( /\G$config{quotere}/mgc ) {
68 } elsif ( /\G$config{antiquotere}/mgc ) {
71 } while ( /\G(.*)\n/gc && ++$lines );
73 return ($lines, $quoted, $antiquoted);