about summary refs log tree commit homepage
path: root/scripts/slrnspool2maildir
blob: b321db1964e3ebcf8bc191b9653ab104525db6ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl -w
# Copyright (C) 2013-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# 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";
	}
}