X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=scripts%2Fimport_slrnspool;h=d9a35dfdfa86b817018540bf3450ffbbbf289f94;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=ea7a97bf69689bdf85950264d9919cd1fccd5b17;hpb=4438f547ecbb52d900dcc73fe4c03cb2e7d5562c;p=public-inbox.git diff --git a/scripts/import_slrnspool b/scripts/import_slrnspool index ea7a97bf..d9a35dfd 100755 --- a/scripts/import_slrnspool +++ b/scripts/import_slrnspool @@ -1,72 +1,81 @@ #!/usr/bin/perl -w -# Copyright (C) 2015, all contributors -# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) +# Copyright (C) 2015-2021 all contributors +# License: AGPL-3.0+ # # Incremental (or one-shot) importer of a slrnpull news spool =begin usage export ORIGINAL_RECIPIENT=address@example.com - public-inbox-init $LISTNAME $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT + public-inbox-init $INBOX $GIT_DIR $HTTP_URL $ORIGINAL_RECIPIENT ./import_slrnspool SLRNPULL_ROOT/news/foo/bar =cut use strict; use warnings; use PublicInbox::Config; -use Email::Filter; -use Email::LocalDelivery; +use PublicInbox::Eml; +use PublicInbox::Import; +use PublicInbox::Git; sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) } +my $exit = 0; +my $sighandler = sub { $exit = 1 }; +$SIG{INT} = $sighandler; +$SIG{TERM} = $sighandler; my $spool = shift @ARGV or die usage(); my $recipient = $ENV{ORIGINAL_RECIPIENT}; defined $recipient or die usage(); -my @mda = qw(public-inbox-mda); -my $config = PublicInbox::Config->new; -my $cfg = $config->lookup($recipient); -defined $cfg or exit(1); -use Data::Dumper; print STDERR Dumper($cfg); +my $cfg = PublicInbox::Config->new; +my $ibx = $cfg->lookup($recipient); +my $git = $ibx->git; +my $im; +if ($ibx->version == 2) { + require PublicInbox::V2Writable; + $im = PublicInbox::V2Writable->new($ibx); + $im->{parallel} = 0; # pointless to be parallel for a single message +} else { + $im = PublicInbox::Import->new($git, $ibx->{name}, + $ibx->{-primary_address}); +} + +$ibx->{filter} ||= 'PublicInbox::Filter::Gmane'; +my $filter = $ibx->filter; + +sub key { + "publicinbox.$ibx->{name}.importslrnspoolstate"; +} sub get_min { - my ($cfg) = @_; - $cfg->{importslrnspoolstate} || 0; + my $f = PublicInbox::Config->default_file; + my $out = $git->qx('config', "--file=$f", key($ibx)); + $out ||= 0; + chomp $out; + $out =~ /\A[0-9]+\z/ and return $out; + 0; } sub set_min { - my ($cfg, $num) = @_; + my ($num) = @_; my $f = PublicInbox::Config->default_file; - my @cmd = (qw/git config/, "--file=$f", - "publicinbox.$cfg->{listname}.importslrnspoolstate", $num); + my @cmd = (qw/git config/, "--file=$f", key($ibx), $num); system(@cmd) == 0 or die join(' ', @cmd). " failed: $?\n"; } my $n = get_min(); my $ok; -my $max_gap = 10000; +my $max_gap = 200000; my $max = $n + $max_gap; +$spool =~ s!/+\z!!; -for (; $n < $max; $n++) { +for (; $exit == 0 && $n < $max; $n++) { my $fn = "$spool/$n"; - print STDERR $fn, "\n"; open(my $fh, '<', $fn) or next; $max = $n + $max_gap; - my $f = Email::Filter->new(data => eval { local $/; <$fh> }); - my $s = $f->simple; - - # gmane rewrites Received headers, which increases spamminess - # Some older archives set Original-To - foreach my $x (qw(Received To)) { - my @h = $s->header("Original-$x"); - if (@h) { - $s->header_set($x, @h); - $s->header_set("Original-$x"); - } - } - - # triggers for the SA HEADER_SPAM rule - foreach my $drop (qw(Approved)) { $s->header_set($drop) } + print STDERR $fn, "\n"; - # appears to be an old gmane bug: - $s->header_set('connect()'); + my $mime = PublicInbox::Eml->new(do { local $/; <$fh> }); + $filter->scrub($mime); + $im->add($mime); - $f->exit(0); - $f->pipe(@mda); $ok = $n + 1; - set_min($cfg, $ok); + set_min($ok); } + +$im->done;