public-inbox.git  about / heads / tags
an "archives first" approach to mailing lists
blob ba0729ec11e6b7f053ec1e3618a29f47652725c7 1825 bytes (raw)
$ git show HEAD: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
51
52
53
54
55
 
#!/usr/bin/perl -w
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
=begin usage
One-off script to convert an slrnpull spool from gmane to Maildir
Note: this contains Gmane-specific header munging to workaround
the munging done by Gmane.

	./slrnspool2maildir SLRNPULL_ROOT/news/foo/bar /path/to/maildir/

A generic replacement w/o Gmane-specific munging could treat
the slrnpull spool as an MH folder with lei:

	lei convert mh:SLRNPULL_ROOT/news/foo/bar -o /path/to/maildir
	# (and `lei daemon-kill' if you don't want the daemon to linger)
=cut
use v5.12;
use autodie;
# warning: unstable internal APIs:
use PublicInbox::Eml;
use PublicInbox::LeiToMail;
use PublicInbox::MHreader;
use PublicInbox::IO qw(read_all);
use File::Path qw(make_path);
use File::Spec ();
sub usage {
	open my $fh, '<', __FILE__;
	("Usage:\n", grep { /^=begin usage/../^=cut/ and !/^=/m } <$fh>);
}
my $spool = shift @ARGV or die usage();
my $dst = shift @ARGV or die usage();
$dst .= '/' unless $dst =~ m!/\z!;
File::Path::make_path(map { $dst.$_ } qw(tmp new cur));
$dst = File::Spec->rel2abs($dst).'/';
opendir my $cwdfh, '.';
my $mhr = PublicInbox::MHreader->new($spool, $cwdfh);
my $smsg;
$mhr->mh_each_eml(sub {
	my ($d, $n, $kw, $eml) = @_;
	# gmane rewrites Received headers, which increases spamminess
	# Some older archives set Original-To
	for my $x (qw(Received To)) {
		my @h = $eml->header_raw("Original-$x");
		if (@h) {
			$eml->header_set($x, @h);
			$eml->header_set("Original-$x");
		}
	}
	# `Approved' triggers the SA HEADER_SPAM rule
	# `connect()' appears to be an old gmane bug:
	$eml->header_set($_) for ('Approved', 'connect()');
	my $buf = $eml->as_string;
	$smsg->{blob} = $n;
	PublicInbox::LeiToMail::_buf2maildir($dst, \$buf, $smsg, 'new/');
});

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