chiark / gitweb /
Allow suppressing publication of posted messages according to rejection reason
[modbot-mtm.git] / xlog / bin / record
index 7b6cf6035f796b2ca0fed0f17c08fc08db55a623..2e9bc7003ebfcb810df69bfc3f6700bdb2f3381f 100755 (executable)
@@ -2,13 +2,18 @@
 
 use strict (qw(vars));
 use IO::Handle;
+use POSIX;
 
 our %f;
 
+my $publish_rejections_patfile= '/dev/null';
 my $publish_rejections= 0;
 if ($ARGV[0] eq '-P') {
     $publish_rejections= 1;
     shift @ARGV;
+} elsif ($ARGV[0] =~ s/^\-P//) {
+    $publish_rejections= 1;
+    $publish_rejections_patfile= shift @ARGV;
 }
 
 our ($how) = @_;
@@ -134,8 +139,32 @@ STDIN->error and die $!;
 
 $f{Now}= time;
 
+sub want_publish_rejection_kind ($) {
+    my ($kind) = @_;
+    return 1 if $publish_rejections_patfile eq '';
+    if (!open PF, '<', $publish_rejections_patfile) {
+       return 1 if $!==&ENOENT;
+       die "$publish_rejections_patfile: $!";
+    }
+    while (<PF>) {
+       s/^\s+//;
+       s/\s+$//;
+       next if m/^\#/;
+       next unless m/\S/;
+       my $yn = !s/^\!//;
+       s/[^0-9a-zA-Z*?]/\\$&/g;
+       s/\*/.*/g;
+       s/\?/./g;
+        return $yn if $kind =~ m/^$_$/;
+    }
+    close PF or die $!;
+    return 1;
+}
+
 if ($publish_rejections &&
-    $f{Event} =~ m/^notify reject /) {
+    $f{Event} =~ m/^notify reject (\S+)/ &&
+    want_publish_rejection_kind($1))
+{
     $f{CopyRef}= $f{MessageNum} || $f{MessageID};
     $f{CopyRef} =~ s/\W/ sprintf '-%02x', ord($&) /ge;
     open I, ">$dir/public/nr-$f{CopyRef}.txt" or die $!;