X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~webstump/git?a=blobdiff_plain;ds=sidebyside;f=stump%2Fbin%2Fsubmission.pl;h=d19c3ba9eaa08d6f64a8d94964b3d759889dd2ca;hb=bf46be8bbf6faf94da6ca687f6a61b1c78a03879;hp=f978a1fb36d526a1f3b2672611a45bf5646ebf6a;hpb=56d8a80761d68c123d55778d73b66268dabd3e34;p=modbot-urcm.git diff --git a/stump/bin/submission.pl b/stump/bin/submission.pl index f978a1f..d19c3ba 100755 --- a/stump/bin/submission.pl +++ b/stump/bin/submission.pl @@ -133,7 +133,10 @@ print STDERR "Too many newsgroups\n"; # checks if poster needs acknowledgment of receipt # sub checkAck { - if( &nameIsInList( $From, "noack.list" ) ) { + my $fromaddr = $From; + $fromaddr =~ s/^[-A-Za-z]+\s*\:\s*//; + print STDERR "checking noack.list for \"$From|$fromaddr\"\n"; + if( &nameIsInListExactly( $fromaddr, "noack.list" ) ) { $needAck = "no"; } else { $needAck = "yes"; @@ -163,8 +166,8 @@ print STDERR "FromSig = $FromSig, good = $good\n" if $FromSig; return "$Command_Reject signature Your PGP signature does NOT match, or is not in our keyring"; } - if( &nameIsInList( $From, $PGPMustList ) || - ($PGPCheckPreapproved && &nameIsInList($From, $goodGuys) ) ) { + if( &nameIsInListRegexp( $From, $PGPMustList ) || + ($PGPCheckPreapproved && &nameIsInListExactly($From, $goodGuys) ) ) { if( $FromSig eq "" ) { return "$Command_Reject signature You are REQUIRED to sign your posts."; } @@ -184,8 +187,8 @@ print STDERR "FromSig = $FromSig, good = $good\n" if $FromSig; # checks charter calling conforms_charter # sub checkCharter { - open( VERIFY, "|conforms_charter" ); - print VERIFY $Body; + open( VERIFY, "|conforms_charter" ) or die $!; + print VERIFY $Body or die $!; close( VERIFY ); return $? == 0; @@ -214,8 +217,8 @@ sub Filter { } } - if( &nameIsInList( $From, $badGuys ) ) { - return "$Command_Reject abuse"; + if( &nameIsInListRegexp( $From, $badGuys ) ) { + return "$Command_Reject blocklist"; } # note that if even a preapproved person uses "BAD words" (that is @@ -223,7 +226,7 @@ sub Filter { # "suspicious" and will be forwarded to a humen mod for review. # As an example of a bad word may be "MAKE MONEY FAST - IT REALLY WORKS!!!" # - if( $badWord = &nameIsInList( $Body, $badWords ) ) { + if( $badWord = &nameIsInListRegexp( $Body, $badWords ) ) { print STDERR "BAD WORD $badWord FOUND!!!\n"; return $Command_Suspicious; # messages from approved guys MAY be # suspicious if they write about @@ -237,7 +240,7 @@ print STDERR "BAD WORD $badWord FOUND!!!\n"; } # Checking preapproved list - if( &nameIsInList( $From, $goodGuys ) ) { + if( &nameIsInListExactly( $From, $goodGuys ) ) { local( $from ) = $From; $from =~ s/^From: //i; print STDERR "$from is a PREAPPROVED person\n"; return $Command_Approve; @@ -267,7 +270,6 @@ sub ignoreHeader { return 1 if( $header =~ /^Supersedes:/i ); return 1 if( $header =~ /^Precedence:/i ); return 1 if( $header =~ /^Apparently-To:/i ); - return 1 if( $header =~ /^Date:/i ); return 1 if( $header =~ /^Expires:/i ); return 1 if( $header =~ /^Distribution:/i ); return 1 if( $header =~ /^Path:/i ); @@ -280,6 +282,9 @@ sub ignoreHeader { return 1 if( $header =~ /^Sender:/i ); return 1 if( $header =~ /^In-Reply-To:/i ); return 1 if( $header =~ /^Originator:/i ); + return 1 if( $header =~ /^X-Trace:/i ); + return 1 if( $header =~ /^X-Complaints-To:/i ); + return 1 if( $header =~ /^NNTP-Posting-Date:/i ); return 0; } @@ -298,22 +303,83 @@ sub ignoreHeader { sub readMessage { -open IWJL, ">>/home/webstump/t.log"; -print IWJL "=========== SUBMISSION READMESSAGE\n"; +#open IWJL, ">>/home/webstump/t.log"; +#print IWJL "=========== SUBMISSION READMESSAGE\n"; - open( TMPFILE, "> $TmpFile" ); + open( TMPFILE, "> $TmpFile" ) or die $!; $IsBody = 0; - - while( <> ) { -print IWJL "SbRm $_\n"; + + my @unfolded; + my $readahead = ''; + + our $warnings=0; + my $warning = sub { + sprintf "X-STUMP-Warning-%d: %s\n", $warnings++, $_[0]; + }; + +#open TTY, ">/home/webstump/t"; + for (;;) { +#print TTY "=| $IsBody | $readahead ...\n"; + if (!defined $readahead) { + # we got EOF earlier; + last; + } + if (length $readahead) { + $_ = $readahead; + $readahead = ''; + } else { + $_ = <>; + last unless defined; + } + if (!$IsBody) { + # right now there is no readahead, since we just consumed it into $_ + if ($_ !~ m/^\r?\n$/) { # blank line ? no... + $readahead = <>; + if (defined $readahead && $readahead =~ m/^[ \t]/) { + # this is a continuation, keep stashing + $readahead = $_.$readahead; + next; + } + # OK, $readahead is perhaps: + # - undef: we got eof + # - empty line: signalling end of (these) headers + # - start of next header + # In these cases, keep that in $readahead for now, + # and process the previous header, which is in $_. + # But, first, a wrinkle ... + if (!m/^(?:References):/i) { + push @unfolded, (m/^[^:]+:/ ? $& : '????') + if s/\n(?=.)//g; + if (length $_ > 505) { #wtf + $_ = substr($_, 0, 500); + $_ =~ s/\n?$/\n/; + $readahead = $_; + $_ = $warning->("Next header truncated!"); + } + } + } else { + # $_ is empty line at end of headers + # (and, there is no $readahead) + if (@unfolded) { + # insert this warning into the right set of headers + $readahead = $_; + $_ = $warning->("Unfolded headers @unfolded"); + @unfolded = (); + } + } + # Now we have in $_ either a complete header, unfolded, + # or the empty line at the end of headers + } +#print TTY "=> $IsBody | $readahead | $_ ...\n"; + $Body .= $_; if( !$IsBody && &ignoreHeader( $_ ) ) { next; } - print TMPFILE; + print TMPFILE or die $!; chop; @@ -367,7 +433,7 @@ print STDERR "BAD NEWSSERVER\n"; } } use IO::Handle; - print IWJL "SbRmE $!\n"; +# print IWJL "SbRmE $!\n"; die "read message $! !" if STDIN->error; close( TMPFILE ); @@ -402,16 +468,15 @@ $command = &Filter; # process print STDERR "command = $command\n"; -open IWJL, ">>/home/webstump/t.log"; -print IWJL "=========== SUBMISSION MAIN\n"; +#open IWJL, ">>/home/webstump/t.log"; +#print IWJL "=========== SUBMISSION MAIN\n"; -open( COMMAND, "| $command" ); +open( COMMAND, "| $command" ) or die $!; open( TMPFILE, "$TmpFile" ) || die "cant open tmpfile"; $IsBody = 0; while( ) { -print IWJL "SbRt $_\n"; if( $BadNewsserver && !(/^$/) ) { next; @@ -427,10 +492,10 @@ print IWJL "SbRt $_\n"; } if( /^From / ) { - print COMMAND; - print COMMAND "X-Origin: $X_Origin, $_" if $X_Origin; + print COMMAND or die $!; + print COMMAND "X-Origin: $X_Origin, $_" or die $! if $X_Origin; print STDERR "Subject =`$Subject'\n"; - print COMMAND "Subject: No subject given\n" if !$Subject; + print COMMAND "Subject: No subject given\n" or die $! if !$Subject; # nothing } elsif( /^From: / && !$IsBody) { next if $FromWasUsed; @@ -440,20 +505,20 @@ print IWJL "SbRt $_\n"; # "From: " to go to headers! if( $From ) { - print COMMAND "$From\n"; + print COMMAND "$From\n" or die $!; $From = ""; } else { - print COMMAND; + print COMMAND or die $!; } } elsif( /^Newsgroups: / && !$IsBody ) { - print COMMAND "Newsgroups: $Newsgroups\n"; + print COMMAND "Newsgroups: $Newsgroups\n" or die $!; } else { - print COMMAND; + print COMMAND or die $!; } } -close( TMPFILE ); -close( COMMAND ); +close( TMPFILE ) or die $!; +close( COMMAND ) or die "$? $!"; ################################################################## Archiving # archive