X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=scripts%2Fimport_slrnspool;h=1a7d77a4d767d5d69f5e9a1b341dffa2841e7e56;hp=e55c96c7dcde95b376db44f5934bf96fe4d22286;hb=8d562ac834d69e18030cb2969a827b121aa4324a;hpb=8cd7dbc96254f6c19990fc28c266e274cc80ddfb diff --git a/scripts/import_slrnspool b/scripts/import_slrnspool index e55c96c7..1a7d77a4 100755 --- a/scripts/import_slrnspool +++ b/scripts/import_slrnspool @@ -1,18 +1,19 @@ #!/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-2018 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::MIME; +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 }; @@ -22,71 +23,75 @@ my $spool = shift @ARGV or die usage(); my $recipient = $ENV{ORIGINAL_RECIPIENT}; defined $recipient or die usage(); my $config = PublicInbox::Config->new; -my $cfg = $config->lookup($recipient); -defined $cfg or exit(1); -my @mda; -if ($ENV{'FILTER'}) { - @mda = qw(public-inbox-mda); +my $ibx = $config->lookup($recipient); +my $git = $ibx->git; +my $im; +if (($ibx->{version} || 1) == 2) { + require PublicInbox::V2Writable; + $im = PublicInbox::V2Writable->new($ibx); + $im->{parallel} = 0; # pointless to be parallel for a single message } else { - @mda = (qw(ssoma-mda -1), $cfg->{mainrepo}); + $im = PublicInbox::Import->new($git, $ibx->{name}, + $ibx->{-primary_address}); } sub key { - my ($cfg) = @_; - "publicinbox.$cfg->{listname}.importslrnspoolstate"; + "publicinbox.$ibx->{name}.importslrnspoolstate"; } sub get_min { my $f = PublicInbox::Config->default_file; - my @cmd = (qw/git config/, "--file=$f", key($cfg)); - use IPC::Run qw/run/; - - my $in = ''; - my $out = ''; - unless (run(\@cmd, \$in, \$out)) { - $out = 0; - } - int($out); + my $out = $git->qx('config', "--file=$f", key($ibx)); + $out ||= 0; + chomp $out; + $out =~ /\A\d+\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", key($cfg), $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 (; $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; + print STDERR $fn, "\n"; + + my $mime = PublicInbox::MIME->new(eval { local $/; <$fh> }); + my $hdr = $mime->header_obj; # 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"); + my @h = $hdr->header_raw("Original-$x"); if (@h) { - $s->header_set($x, @h); - $s->header_set("Original-$x"); + $hdr->header_set($x, @h); + $hdr->header_set("Original-$x"); } } - # triggers for the SA HEADER_SPAM rule - foreach my $drop (qw(Approved)) { $s->header_set($drop) } + # Approved triggers for the SA HEADER_SPAM rule, + # X-From is gmane specific + foreach my $drop (qw(Approved X-From)) { + $hdr->header_set($drop); + } # appears to be an old gmane bug: - $s->header_set('connect()'); + $hdr->header_set('connect()'); + $im->add($mime); - $f->exit(0); - $f->pipe(@mda); $ok = $n + 1; - set_min($cfg, $ok); + set_min($ok); } + +$im->done;