]> Sergey Matveev's repositories - public-inbox.git/commitdiff
mda: hoist out List-ID handling and reuse in -learn
authorEric Wong <e@80x24.org>
Mon, 28 Oct 2019 10:45:20 +0000 (10:45 +0000)
committerEric Wong <e@80x24.org>
Wed, 30 Oct 2019 08:48:14 +0000 (08:48 +0000)
It's now possible to inject false-positive ham into an inbox
the same way -mda does via List-ID.

lib/PublicInbox/MDA.pm
script/public-inbox-learn [changed mode: 0755->0644]
script/public-inbox-mda

index 9cafda13997f68229d8f6f4f0b1dc34ce4bc3b93..ce2c870f89edcd353d263d1c8fed28a0d08ede1f 100644 (file)
@@ -83,4 +83,19 @@ sub set_list_headers {
        }
 }
 
+# TODO: deal with multiple List-ID headers?
+sub inbox_for_list_id ($$) {
+       my ($klass, $config, $simple) = @_;
+
+       # newer Email::Simple allows header_raw, as does Email::MIME:
+       my $list_id = $simple->can('header_raw') ?
+                       $simple->header_raw('List-Id') :
+                       $simple->header('List-Id');
+       my $ibx;
+       if (defined $list_id && $list_id =~ /<[ \t]*(.+)?[ \t]*>/) {
+               $ibx = $config->lookup_list_id($1);
+       }
+       $ibx;
+}
+
 1;
old mode 100755 (executable)
new mode 100644 (file)
index 56739f8..79f3ead
@@ -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 => <PublicInbox::Inbox|0(false)>
@@ -89,10 +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
+               next if $seen{"$ibx"}++;
                remove_or_add($ibx, $train, $addr);
        }
+       my $ibx = PublicInbox::MDA->inbox_for_list_id($pi_config, $mime);
+       if ($ibx && !$seen{"$ibx"}) {
+               remove_or_add($ibx, $train, $ibx->{-primary_address});
+       }
 }
 
 if ($err) {
index 584218b54c5a179d9b4adb86e0ef0caabf40f8de..3ff318c916007f2f19751b51a241ecb22fca2819 100755 (executable)
@@ -43,10 +43,7 @@ if (defined $recipient) {
        $dst = $config->lookup($recipient); # first check
 }
 if (!defined $dst) {
-       my $list_id = $simple->header('List-Id');
-       if (defined $list_id && $list_id =~ /<[ \t]*(.+)?[ \t]*>/) {
-               $dst = $config->lookup_list_id($1);
-       }
+       $dst = PublicInbox::MDA->inbox_for_list_id($config, $simple);
        if (!defined $dst && !defined $recipient) {
                die "ORIGINAL_RECIPIENT not defined in ENV\n";
        }