2 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
3 # License: AGPLv3 or later (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 Email::LocalDelivery;
16 sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
18 my $sighandler = sub { $exit = 1 };
19 $SIG{INT} = $sighandler;
20 $SIG{TERM} = $sighandler;
21 my $spool = shift @ARGV or die usage();
22 my $recipient = $ENV{ORIGINAL_RECIPIENT};
23 defined $recipient or die usage();
24 my $config = PublicInbox::Config->new;
25 my $cfg = $config->lookup($recipient);
26 defined $cfg or exit(1);
29 @mda = qw(public-inbox-mda);
31 @mda = (qw(ssoma-mda -1), $cfg->{mainrepo});
36 "publicinbox.$cfg->{inbox}.importslrnspoolstate";
40 my $f = PublicInbox::Config->default_file;
41 my @cmd = (qw/git config/, "--file=$f", key($cfg));
46 unless (run(\@cmd, \$in, \$out)) {
54 my $f = PublicInbox::Config->default_file;
55 my @cmd = (qw/git config/, "--file=$f", key($cfg), $num);
56 system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n";
62 my $max = $n + $max_gap;
64 for (; $exit == 0 && $n < $max; $n++) {
66 print STDERR $fn, "\n";
67 open(my $fh, '<', $fn) or next;
70 # prevent process growth by forking a new process for each message
72 die "failed to fork: $!\n" unless defined $pid;
75 my $f = Email::Filter->new(data => eval { local $/; <$fh> });
80 # gmane rewrites Received headers, which increases spamminess
81 # Some older archives set Original-To
82 foreach my $x (qw(Received To)) {
83 my @h = $s->header("Original-$x");
85 $s->header_set($x, @h);
86 $s->header_set("Original-$x");
90 # triggers for the SA HEADER_SPAM rule
91 foreach my $drop (qw(Approved)) { $s->header_set($drop) }
93 # appears to be an old gmane bug:
94 $s->header_set('connect()');
102 die "error: $?\n" if $?;