X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=scripts%2Fimport_slrnspool;h=bdcc605c245434bc5ca6c47524d09ce6aef45147;hb=03c9119ec613fa43dcf0a50b5f35754f13228bc8;hp=98850591e0963eb0c24fa5b98290107c4bdc5e2b;hpb=843214095571db4ae68f5e92b8ef6057e1e6eba0;p=public-inbox.git
diff --git a/scripts/import_slrnspool b/scripts/import_slrnspool
index 98850591..bdcc605c 100755
--- a/scripts/import_slrnspool
+++ b/scripts/import_slrnspool
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# Copyright (C) 2015-2016 all contributors
+# Copyright (C) 2015-2020 all contributors
# License: AGPL-3.0+
#
# Incremental (or one-shot) importer of a slrnpull news spool
@@ -11,7 +11,7 @@
use strict;
use warnings;
use PublicInbox::Config;
-use Email::MIME;
+use PublicInbox::Eml;
use PublicInbox::Import;
use PublicInbox::Git;
sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
@@ -25,7 +25,18 @@ defined $recipient or die usage();
my $config = PublicInbox::Config->new;
my $ibx = $config->lookup($recipient);
my $git = $ibx->git;
-my $im = PublicInbox::Import->new($git, $ibx->{name}, $ibx->{-primary_address});
+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";
@@ -36,7 +47,7 @@ sub get_min {
my $out = $git->qx('config', "--file=$f", key($ibx));
$out ||= 0;
chomp $out;
- $out =~ /\A\d+\z/ and return $out;
+ $out =~ /\A[0-9]+\z/ and return $out;
0;
}
@@ -51,34 +62,16 @@ my $n = get_min();
my $ok;
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;
+ print STDERR $fn, "\n";
- my $mime = Email::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 = $hdr->header_raw("Original-$x");
- if (@h) {
- $hdr->header_set($x, @h);
- $hdr->header_set("Original-$x");
- }
- }
-
- # 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:
- $hdr->header_set('connect()');
+ my $mime = PublicInbox::Eml->new(do { local $/; <$fh> });
+ $filter->scrub($mime);
$im->add($mime);
$ok = $n + 1;