Add suck-postfilter.pl

Signed-off-by: Thomas Hochstein <thh@thh.name>
This commit is contained in:
Thomas Hochstein 2026-06-04 16:19:45 +02:00
parent 7fb4c9d347
commit 4fe932925b
2 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,56 @@
#! /usr/bin/perl -w
#
# postfilter for rpost, to be called from get-news
#
# add "postfilter: /path/to/this/script" to get-news.conf
use strict;
# set regexp for offending headers
my $headerexp = 'NNTP-Posting-Host|NNTP-Posting-Date|X-Complaints-To|Xref|X-Trace|X-Server-Date|Path|Injection-Info';
# debug switch
my $debug = 0;
# read command line arguments
my $infile = $ARGV[0]; # storage token
my $outfile = $ARGV[1];
$infile =~ s/^[^@]*//;
if (!$outfile) {
print "Usage: $0 infile outfile\n";
exit 2;
}
# open file handles
open INPUT, "/usr/lib/news/bin/sm $infile |" or return $infile;
open OUTPUT, ">${outfile}" or die "Can't create ${outfile}";
# remove offending lines
my $found = 0;
while ( $line = <INPUT> ) {
if($line =~ /^$headerexp: /) {
$found = 1;
print "!! $line" if $debug;
} elsif ($found && $line =~ /^[ \t]+/) {
# continuation line(s)
print "!> $line" if $debug;
} else {
$found = 0;
# write out to file
print OUTPUT $line;
print $line if $debug;
}
# stop parsing after end-of-header
last if ($line =~ /^$/);
}
while ( $line = <INPUT> ) {
print OUTPUT $line;
print $line if $debug;
}
# close file handles
close INPUT;
close OUTPUT;
exit;