X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-learn;h=a33d813ad01eb389ff5f184f4f98ed6497fba90f;hb=46742d95647c7a80cb2f60d5c134717dd91e22e2;hp=56739f88d720bfc12d344d6e4a2c68b73a28926e;hpb=29beb70160d15ffe46cb07e9d9468acfcda34db7;p=public-inbox.git diff --git a/script/public-inbox-learn b/script/public-inbox-learn old mode 100755 new mode 100644 index 56739f88..a33d813a --- a/script/public-inbox-learn +++ b/script/public-inbox-learn @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright (C) 2014-2019 all contributors +# Copyright (C) 2014-2020 all contributors # License: AGPL-3.0+ # # Used for training spam (via SpamAssassin) and removing messages from a @@ -9,7 +9,7 @@ use strict; use warnings; use PublicInbox::Config; use PublicInbox::InboxWritable; -use PublicInbox::MIME; +use PublicInbox::Eml; use PublicInbox::Address; use PublicInbox::Spamcheck::Spamc; my $train = shift or die "usage: $usage\n"; @@ -20,9 +20,9 @@ if ($train !~ /\A(?:ham|spam|rm)\z/) { my $spamc = PublicInbox::Spamcheck::Spamc->new; my $pi_config = PublicInbox::Config->new; my $err; -my $mime = PublicInbox::MIME->new(eval { +my $mime = PublicInbox::Eml->new(do{ local $/; - my $data = scalar ; + my $data = ; $data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; if ($train ne 'rm') { @@ -36,11 +36,11 @@ my $mime = PublicInbox::MIME->new(eval { }; $err = $@; } - $data + \$data }); -sub remove_or_add ($$$) { - my ($ibx, $train, $addr) = @_; +sub remove_or_add ($$$$) { + my ($ibx, $train, $mime, $addr) = @_; # We do not touch GIT_COMMITTER_* env here so we can track # who trained the message. @@ -77,7 +77,7 @@ if ($train eq 'spam') { $im->done; }); } else { - require PublicInbox::MDA if $train eq "ham"; + require PublicInbox::MDA; # get all recipients my %dests; # address => @@ -89,9 +89,16 @@ if ($train eq 'spam') { } # n.b. message may be cross-posted to multiple public-inboxes + my %seen; while (my ($addr, $ibx) = each %dests) { next unless ref($ibx); # $ibx may be 0 - remove_or_add($ibx, $train, $addr); + next if $seen{"$ibx"}++; + remove_or_add($ibx, $train, $mime, $addr); + } + my $dests = PublicInbox::MDA->inboxes_for_list_id($pi_config, $mime); + for my $ibx (@$dests) { + next if !$seen{"$ibx"}++; + remove_or_add($ibx, $train, $mime, $ibx->{-primary_address}); } }