2 # Copyright (C) 2015-2016 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
5 # Incremental (or one-shot) importer of a slrnpull news spool
7 export ORIGINAL_RECIPIENT=address@example.com
8 public-inbox-init $INBOX $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT
9 ./import_slrnspool SLRNPULL_ROOT/news/foo/bar
13 use PublicInbox::Config;
15 use PublicInbox::Import;
17 sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
19 my $sighandler = sub { $exit = 1 };
20 $SIG{INT} = $sighandler;
21 $SIG{TERM} = $sighandler;
22 my $spool = shift @ARGV or die usage();
23 my $recipient = $ENV{ORIGINAL_RECIPIENT};
24 defined $recipient or die usage();
25 my $config = PublicInbox::Config->new;
26 my $ibx = $config->lookup($recipient);
28 my $im = PublicInbox::Import->new($git, $ibx->{name}, $ibx->{-primary_address});
31 "publicinbox.$ibx->{name}.importslrnspoolstate";
35 my $f = PublicInbox::Config->default_file;
36 my $out = $git->qx('config', "--file=$f", key($ibx));
39 $out =~ /\A\d+\z/ and return $out;
45 my $f = PublicInbox::Config->default_file;
46 my @cmd = (qw/git config/, "--file=$f", key($ibx), $num);
47 system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n";
53 my $max = $n + $max_gap;
55 for (; $exit == 0 && $n < $max; $n++) {
57 print STDERR $fn, "\n";
58 open(my $fh, '<', $fn) or next;
61 my $mime = Email::MIME->new(eval { local $/; <$fh> });
62 my $hdr = $mime->header_obj;
64 # gmane rewrites Received headers, which increases spamminess
65 # Some older archives set Original-To
66 foreach my $x (qw(Received To)) {
67 my @h = $hdr->header_raw("Original-$x");
69 $hdr->header_set($x, @h);
70 $hdr->header_set("Original-$x");
74 # Approved triggers for the SA HEADER_SPAM rule,
75 # X-From is gmane specific
76 foreach my $drop (qw(Approved X-From)) {
77 $hdr->header_set($drop);
80 # appears to be an old gmane bug:
81 $hdr->header_set('connect()');