#!/usr/bin/perl -w # Copyright (C) all contributors # License: AGPL-3.0+ =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/'); });