]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: consolidate mid prepend logic, here
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Thu, 22 Mar 2018 18:21:54 +0000 (18:21 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Thu, 22 Mar 2018 18:21:54 +0000 (18:21 +0000)
This also quiets down warnings from -watch when spam training
happens on messages without Message-Id.

lib/PublicInbox/Import.pm
lib/PublicInbox/V2Writable.pm

index 5d116a1c7207b9ea4c0b1f74b0a10ecba46f7e3c..6824faca21dc3205ecd12be9899cb1e14f0e3834 100644 (file)
@@ -203,7 +203,7 @@ sub remove {
        my ($r, $w) = $self->gfi_start;
        my $tip = $self->{tip};
        if ($path_type eq '2/38') {
-               $path = mid2path(mid_mime($mime));
+               $path = mid2path(v1_mid0($mime));
                ($err, $cur) = check_remove_v1($r, $w, $tip, $path, $mime);
                return ($err, $cur) if $err;
        } else {
@@ -296,6 +296,28 @@ sub drop_unwanted_headers ($) {
        $mime->header_set($_) for @PublicInbox::MDA::BAD_HEADERS;
 }
 
+# used by V2Writable, too
+sub prepend_mid ($$) {
+       my ($hdr, $mid0) = @_;
+       # @cur is likely empty if we need to call this sub, but it could
+       # have random unparseable crap which we'll preserve, too.
+       my @cur = $hdr->header_raw('Message-Id');
+       $hdr->header_set('Message-Id', "<$mid0>", @cur);
+}
+
+sub v1_mid0 ($) {
+       my ($mime) = @_;
+       my $hdr = $mime->header_obj;
+       my $mids = mids($hdr);
+
+       if (!scalar(@$mids)) { # spam often has no Message-Id
+               my $mid0 = digest2mid(content_digest($mime));
+               prepend_mid($hdr, $mid0);
+               return $mid0;
+       }
+       $mids->[0];
+}
+
 # returns undef on duplicate
 # returns the :MARK of the most recent commit
 sub add {
@@ -313,12 +335,7 @@ sub add {
 
        my $path;
        if ($path_type eq '2/38') {
-               my $mids = mids($mime->header_obj);
-               if (!scalar(@$mids)) {
-                       my $dig = content_digest($mime);
-                       @$mids = (digest2mid($dig));
-               }
-               $path = mid2path($mids->[0]);
+               $path = mid2path(v1_mid0($mime));
        } else { # v2 layout, one file:
                $path = 'm';
        }
index 20c27363c3bb55290ef8a1b6c98144f0621e4f4d..b04e6fbfe892dc1227b43c119f93713f38008a86 100644 (file)
@@ -173,8 +173,7 @@ sub num_for_harder {
                        $num = $self->{skel}->{mm}->mid_insert($$mid0);
                }
        }
-       my @cur = $hdr->header_raw('Message-Id');
-       $hdr->header_set('Message-Id', "<$$mid0>", @cur);
+       PublicInbox::Import::prepend_mid($hdr, $$mid0);
        $num;
 }