From 9897f7372b11dceed762a8419e76e2a6b8dd0ef0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 23 Nov 2012 17:50:02 +0000 Subject: [PATCH] Allow suppressing publication of posted messages according to rejection reason This is done by creating BASEDIR/settings.publish-rejection-kinds with a series of lines of the form [!] where may contain * and ? and matches the short rejection reason keyword. First match wins; ! means do not publish; if file does not exist or we run off the end, we do publish. All of this depends on PUBLISHREJECTIONS=true in settings. --- .gitignore | 1 + get-settings | 2 +- xlog/bin/record | 31 ++++++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 62f0c85..1b1e591 100644 --- a/.gitignore +++ b/.gitignore @@ -41,5 +41,6 @@ /README.auto /settings +/settings.publish-rejections-kinds /moderators /persistent-autosettings diff --git a/get-settings b/get-settings index 1848cea..3250905 100644 --- a/get-settings +++ b/get-settings @@ -25,7 +25,7 @@ export BASEDIR PUBREJOPT='' if $PUBLISHREJECTIONS; then - PUBREJOPT=-P + PUBREJOPT="-P$BASEDIR/settings.publish-rejection-kinds" fi export PUBREJOPT diff --git a/xlog/bin/record b/xlog/bin/record index 7b6cf60..2e9bc70 100755 --- a/xlog/bin/record +++ b/xlog/bin/record @@ -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 () { + 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 $!; -- 2.30.2