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/');
});
|