-# Copyright (C) 2016-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
# Filter for vger.kernel.org list trailer
package PublicInbox::Filter::Vger;
-use base qw(PublicInbox::Filter::Base);
+use v5.10.1; # check regexps before v5.12
+use parent qw(PublicInbox::Filter::Base);
use strict;
use PublicInbox::Eml;
my $l4 = qr!Please read the FAQ at +http://www\.tux\.org/lkml/!;
sub scrub {
- my ($self, $mime) = @_;
- my $s = $mime->as_string;
+ my ($self, $eml) = @_;
+ my $s = $eml->as_string;
- # the vger appender seems to only work on the raw string,
+ # the old vger appender seemed to only work on the raw string,
# so in multipart (e.g. GPG-signed) messages, the list trailer
# becomes invisible to MIME-aware email clients.
if ($s =~ s/$l0\n$l1\n$l2\n$l3\n(?:$l4\n)?\n*\z//os) {
- $mime = PublicInbox::Eml->new(\$s);
+ $_[1] = $eml= PublicInbox::Eml->new(\$s);
}
- $self->ACCEPT($mime);
+ $self->ACCEPT($eml);
}
sub delivery {
if ($self && (my $filter = $self->filter($im))) {
my $ret = $filter->scrub($eml) or return;
return if $ret == REJECT();
- $eml = $ret;
}
$im->add($eml);
}
if ($filter) {
my $ret = $filter->scrub($eml) or return;
return if $ret == REJECT();
- $eml = $ret;
}
$im->add($eml);
}
eval {
# try to avoid taking a lock or unnecessary spawning
my $im = $self->{importers}->{"$ibx"};
- my $scrubbed;
+ my @eml = ($eml);
+ if (my $filter = $ibx->filter($im)) {
+ my $tmp = PublicInbox::Eml->new(\($eml->as_string));
+ my $ret = $filter->scrub($tmp, 1);
+ push @eml, $tmp if $ret && $ret != REJECT;
+ }
+
if ((!$im || !$im->active) && $ibx->over) {
- if (content_exists($ibx, $eml)) {
- # continue
- } elsif (my $scrub = $ibx->filter($im)) {
- $scrubbed = $scrub->scrub($eml, 1);
- if ($scrubbed && $scrubbed != REJECT &&
- !content_exists($ibx, $scrubbed)) {
- return;
- }
- } else {
- return;
- }
+ @eml = grep { content_exists($ibx, $_) } @eml or return;
}
$im //= _importer_for($self, $ibx); # may spawn fast-import
- $im->remove($eml, 'spam');
- $scrubbed //= do {
- my $scrub = $ibx->filter($im);
- $scrub ? $scrub->scrub($eml, 1) : undef;
- };
- if ($scrubbed && $scrubbed != REJECT) {
- $im->remove($scrubbed, 'spam');
- }
+ $im->remove($_, 'spam') for @eml;
};
if ($@) {
warn "error removing spam at: $loc from $ibx->{name}: $@\n";
}
eval {
my $im = _importer_for($self, $ibx);
- if (my $scrub = $ibx->filter($im)) {
- my $scrubbed = $scrub->scrub($eml) or return;
- $scrubbed == REJECT and return;
- $eml = $scrubbed;
+ if (my $filter = $ibx->filter($im)) {
+ my $ret = $filter->scrub($eml) or return;
+ $ret == REJECT and return;
}
$im->add($eml, $self->{spamcheck});
};
for my $ibx (@$dests) {
mda_filter_adjust($ibx);
my $filter = $ibx->filter;
- my $mime = PublicInbox::Eml->new($str);
- my $ret = $filter->delivery($mime);
- if (ref($ret) && ($ret->isa('PublicInbox::Eml') ||
- $ret->isa('Email::MIME'))) { # filter altered message
- $mime = $ret;
- } elsif ($ret == PublicInbox::Filter::Base::IGNORE) {
- next; # nothing, keep looping
- } elsif ($ret == PublicInbox::Filter::Base::REJECT) {
+ my $eml = PublicInbox::Eml->new($str);
+ my $ret = $filter->delivery($eml) or next; # $ret == IGNORE
+ if ($ret == PublicInbox::Filter::Base::REJECT) {
push @rejects, $filter->err;
next;
- }
+ } # else success
- PublicInbox::MDA->set_list_headers($mime, $ibx);
+ PublicInbox::MDA->set_list_headers($eml, $ibx);
my $im = $ibx->importer(0);
- if (defined $im->add($mime)) {
+ if (defined $im->add($eml)) {
# ->abort is idempotent, no emergency if a single
# destination succeeds
$emm->abort;
} else { # v1-only
- my $mid = $mime->header_raw('Message-ID');
+ my $mid = $eml->header_raw('Message-ID');
# this message is similar to what ssoma-mda shows:
print STDERR "CONFLICT: Message-ID: $mid exists\n";
}
my $n_purged = 0;
foreach my $ibx (@ibxs) {
- my $mime = PublicInbox::Eml->new($data);
+ my $eml = PublicInbox::Eml->new($data);
my $v2w = PublicInbox::V2Writable->new($ibx, 0);
- my $commits = $v2w->purge($mime) || [];
+ my $commits = $v2w->purge($eml) || [];
- if (my $scrub = $ibx->filter($v2w)) {
- my $scrubbed = $scrub->scrub($mime, 1);
+ if (my $filter = $ibx->filter($v2w)) {
+ my $ret = $filter->scrub($eml, 1); # destructive
- if ($scrubbed && $scrubbed != REJECT()) {
- my $scrub_commits = $v2w->purge($scrubbed);
+ if ($ret && $ret != REJECT) {
+ my $scrub_commits = $v2w->purge($eml);
push @$commits, @$scrub_commits if $scrub_commits;
}
}