chiark / gitweb /
unfolding: do not introduce additional lwsp
[modbot-urcm.git] / stump / bin / submission.pl
index f31961774a9fafbee80594f9f3735d81c8abe477..d19c3ba9eaa08d6f64a8d94964b3d759889dd2ca 100755 (executable)
@@ -133,7 +133,10 @@ print STDERR "Too many newsgroups\n";
 # checks if poster needs acknowledgment of receipt
 #
 sub checkAck {
-  if( &nameIsInListExactly( $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";
@@ -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;
 }
@@ -304,9 +309,70 @@ sub readMessage {
   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( $_ ) ) {