about summary refs log tree commit homepage
path: root/lib/PublicInbox/Import.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-19 08:14:46 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-19 08:16:34 +0000
commit12c3eb5b2b0860292a32d5743ea0157996e9a4b9 (patch)
treee77046682726121988548e0ef968cf33233f3d6d /lib/PublicInbox/Import.pm
parent1cc19f3f8ffe37e341e219884c6856210ba6fa52 (diff)
downloadpublic-inbox-12c3eb5b2b0860292a32d5743ea0157996e9a4b9.tar.gz
This allows us to share code for generating Message-IDs
between v1 and v2 repos.

For v1, this introduces a slight incompatibility in message
removal iff the original message lacked a Message-ID AND
the training request came from a message which did not
pass through the public-inbox:

The workaround for this would be to reuse the bad message from
the archive itself.
Diffstat (limited to 'lib/PublicInbox/Import.pm')
-rw-r--r--lib/PublicInbox/Import.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 12df7d59..4c007b61 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -9,9 +9,10 @@ use strict;
 use warnings;
 use Fcntl qw(:flock :DEFAULT);
 use PublicInbox::Spawn qw(spawn);
-use PublicInbox::MID qw(mid_mime mid2path);
+use PublicInbox::MID qw(mids mid_mime mid2path);
 use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp);
+use PublicInbox::ContentId qw(content_digest);
 
 sub new {
         my ($class, $git, $name, $email, $ibx) = @_;
@@ -308,7 +309,12 @@ sub add {
 
         my $path;
         if ($path_type eq '2/38') {
-                $path = mid2path(mid_mime($mime));
+                my $mids = mids($mime->header_obj);
+                if (!scalar(@$mids)) {
+                        my $dig = content_digest($mime);
+                        @$mids = (digest2mid($dig));
+                }
+                $path = mid2path($mids->[0]);
         } else { # v2 layout, one file:
                 $path = 'm';
         }
@@ -393,6 +399,11 @@ sub atfork_child {
         }
 }
 
+sub digest2mid ($) {
+        my ($dig) = @_;
+        $dig->clone->hexdigest . '@localhost';
+}
+
 1;
 __END__
 =pod