public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob 25108b678859a08f757fd796e5d7adcf7021a9f4 1397 bytes (raw)
$ git show ci-WIP:scripts/slrnspool2maildir	# shows this blob on the CLI

 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-2018 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";
	}
}

git clone https://public-inbox.org/public-inbox.git
git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git