#!/usr/bin/perl -w
# Copyright (C) 2013-2019 all contributors
# License: AGPL-3.0+
#
# One-off script to convert an slrnpull news spool to Maildir
=begin usage
./slrnspool2maildir SLRNPULL_ROOT/news/foo/bar /path/to/maildir/
=cut
use strict;
use warnings;
use Email::Filter;
use Email::LocalDelivery;
sub usage { "Usage:\n".join('',grep(/\t/, `head -n 12 $0`)) }
my $spool = shift @ARGV or die usage();
my $dir = shift @ARGV or die usage();
-d $dir or die "$dir is not a directory\n";
$dir .= '/' unless $dir =~ m!/\z!;
foreach my $sub (qw(cur new tmp)) {
my $nd = "$dir/$sub";
-d $nd and next;
mkdir $nd or die "mkdir $nd failed: $!\n";
}
foreach my $n (grep(/\d+\z/, glob("$spool/*"))) {
if (open my $fh, '<', $n) {
my $f = Email::Filter->new(data => eval { local $/; <$fh> });
my $s = $f->simple;
# gmane rewrites Received headers, which increases spamminess
# Some older archives set Original-To
foreach my $x (qw(Received To)) {
my @h = $s->header("Original-$x");
if (@h) {
$s->header_set($x, @h);
$s->header_set("Original-$x");
}
}
# triggers for the SA HEADER_SPAM rule
foreach my $drop (qw(Approved)) { $s->header_set($drop) }
# appears to be an old gmane bug:
$s->header_set('connect()');
$f->exit(0);
$f->accept($dir);
} else {
warn "Failed to open $n: $!\n";
}
}