2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 One-off script to convert an slrnpull spool from gmane to Maildir
6 Note: this contains Gmane-specific header munging to workaround
7 the munging done by Gmane.
9 ./slrnspool2maildir SLRNPULL_ROOT/news/foo/bar /path/to/maildir/
11 A generic replacement w/o Gmane-specific munging could treat
12 the slrnpull spool as an MH folder with lei:
14 lei convert mh:SLRNPULL_ROOT/news/foo/bar -o /path/to/maildir
15 # (and `lei daemon-kill' if you don't want the daemon to linger)
19 # warning: unstable internal APIs:
21 use PublicInbox
::LeiToMail
;
22 use PublicInbox
::MHreader
;
23 use PublicInbox
::IO
qw(read_all);
24 use File
::Path
qw(make_path);
27 open my $fh, '<', __FILE__
;
28 ("Usage:\n", grep { /^=begin usage/../^=cut/ and !/^=/m } <$fh>);
30 my $spool = shift @ARGV or die usage
();
31 my $dst = shift @ARGV or die usage
();
32 $dst .= '/' unless $dst =~ m
!/\z
!;
33 File
::Path
::make_path
(map { $dst.$_ } qw(tmp new cur));
34 $dst = File
::Spec
->rel2abs($dst).'/';
35 opendir my $cwdfh, '.';
36 my $mhr = PublicInbox
::MHreader
->new($spool, $cwdfh);
38 $mhr->mh_each_eml(sub {
39 my ($d, $n, $kw, $eml) = @_;
40 # gmane rewrites Received headers, which increases spamminess
41 # Some older archives set Original-To
42 for my $x (qw(Received To)) {
43 my @h = $eml->header_raw("Original-$x");
45 $eml->header_set($x, @h);
46 $eml->header_set("Original-$x");
49 # `Approved' triggers the SA HEADER_SPAM rule
50 # `connect()' appears to be an old gmane bug:
51 $eml->header_set($_) for ('Approved', 'connect()');
52 my $buf = $eml->as_string;
54 PublicInbox
::LeiToMail
::_buf2maildir
($dst, \
$buf, $smsg, 'new/');