viewvcs: handle exceptions in on_destroy cb
[public-inbox.git] / scripts / slrnspool2maildir
blobba0729ec11e6b7f053ec1e3618a29f47652725c7
1 #!/usr/bin/perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 =begin usage
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)
16 =cut
17 use v5.12;
18 use autodie;
19 # warning: unstable internal APIs:
20 use PublicInbox::Eml;
21 use PublicInbox::LeiToMail;
22 use PublicInbox::MHreader;
23 use PublicInbox::IO qw(read_all);
24 use File::Path qw(make_path);
25 use File::Spec ();
26 sub usage {
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);
37 my $smsg;
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");
44 if (@h) {
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;
53 $smsg->{blob} = $n;
54 PublicInbox::LeiToMail::_buf2maildir($dst, \$buf, $smsg, 'new/');
55 });