2 # Copyright (C) 2015-2020 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);
29 if ($ibx->version == 2) {
30 require PublicInbox::V2Writable;
31 $im = PublicInbox::V2Writable->new($ibx);
32 $im->{parallel} = 0; # pointless to be parallel for a single message
34 $im = PublicInbox::Import->new($git, $ibx->{name},
35 $ibx->{-primary_address});
38 $ibx->{filter} ||= 'PublicInbox::Filter::Gmane';
39 my $filter = $ibx->filter;
42 "publicinbox.$ibx->{name}.importslrnspoolstate";
46 my $f = PublicInbox::Config->default_file;
47 my $out = $git->qx('config', "--file=$f", key($ibx));
50 $out =~ /\A[0-9]+\z/ and return $out;
56 my $f = PublicInbox::Config->default_file;
57 my @cmd = (qw/git config/, "--file=$f", key($ibx), $num);
58 system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n";
64 my $max = $n + $max_gap;
67 for (; $exit == 0 && $n < $max; $n++) {
69 open(my $fh, '<', $fn) or next;
71 print STDERR $fn, "\n";
73 my $mime = PublicInbox::Eml->new(do { local $/; <$fh> });
74 $filter->scrub($mime);