2 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
3 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
5 # One-off script to convert an slrnpull news spool from gmane, usage:
7 mkdir -p $HOME/.public-inbox
8 MAINREPO=/path/to/your/repo.git
9 export ORIGINAL_RECIPIENT='list@example.com'
10 git init --bare $MAINREPO
11 export GIT_CONFIG=$HOME/.public-inbox/config
12 git config publicinbox.$LISTNAME.address $ORIGINAL_RECIPIENT
13 git config publicinbox.$LISTNAME.mainrepo $MAINREPO
15 ./import_gmane_spool SLRNPULL_ROOT/news/foo/bar
20 use PublicInbox::Filter;
21 use PublicInbox::Config;
23 sub usage { "Usage:\n".join("",grep(/\t/, `head -n 24 $0`)) }
24 my $spool = shift @ARGV or die usage();
25 defined $ENV{ORIGINAL_RECIPIENT} or die usage();
26 my @args = ('public-inbox-mda');
28 chdir $spool or die "chdir $spool failed: $!\n";
30 foreach my $n (sort { $a <=> $b } grep(/\d+\z/, glob("*"))) {
31 if (open my $fh, '<', $n) {
34 Email::Simple->new(<$fh>);
37 # gmane rewrites Received headers, which increases spamminess
38 my @h = $s->header("Original-Received");
40 $s->header_set("Received", @h);
41 $s->header_set("Original-Received");
44 # this is needed for "git rev-list --since=..." to work
45 local $ENV{GIT_COMMITTER_DATE} = $s->header('Date');
47 # triggers for the SA HEADER_SPAM rule
48 foreach my $drop (qw(Approved)) { $s->header_set($drop) }
50 # appears to be an old gmane bug:
51 $s->header_set("connect()");
53 my $orig = $s->as_string;
54 close $fh or die "close failed: $!\n";
55 eval { run(\@args, \$orig) };
56 die "fail $n: $?\n" if $?;
57 die "fail $n: $@\n" if $@;
59 warn "Failed to open $n: $!\n";