INN-config/contrib/suck-postfilter.pl
Thomas Hochstein 4fe932925b Add suck-postfilter.pl
Signed-off-by: Thomas Hochstein <thh@thh.name>
2026-06-04 16:20:46 +02:00

56 lines
1.2 KiB
Perl

#! /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;