#!/usr/bin/perl -w
-# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# Incremental (or one-shot) importer of a slrnpull news spool
use strict;
use warnings;
use PublicInbox::Config;
-use PublicInbox::MIME;
+use PublicInbox::Eml;
use PublicInbox::Import;
use PublicInbox::Git;
sub usage { "Usage:\n".join('',grep(/\t/, `head -n 10 $0`)) }
my $ibx = $config->lookup($recipient);
my $git = $ibx->git;
my $im;
-if (($ibx->{version} || 1) == 2) {
+if ($ibx->version == 2) {
require PublicInbox::V2Writable;
$im = PublicInbox::V2Writable->new($ibx);
$im->{parallel} = 0; # pointless to be parallel for a single message
$ibx->{-primary_address});
}
+$ibx->{filter} ||= 'PublicInbox::Filter::Gmane';
+my $filter = $ibx->filter;
+
sub key {
"publicinbox.$ibx->{name}.importslrnspoolstate";
}
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;
}
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 = 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 = $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;