lib/PublicInbox/Import.pm | 6 +++--- lib/PublicInbox/LeiSearch.pm | 2 +- lib/PublicInbox/OverIdx.pm | 6 ++++-- lib/PublicInbox/Smsg.pm | 2 +- t/lei-import.t | 21 +++++++++++++++++++++ diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 347382791c3c5bea4401aa8c17262d2296c8ca0d..46f57e27c2b452d13f31cb3a08111620bb1308a8 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -510,8 +510,8 @@ close $self->{$f} or die "failed to close import[$f]: $!\n"; } } -sub digest2mid ($$) { - my ($dig, $hdr) = @_; +sub digest2mid ($$;$) { + my ($dig, $hdr, $fallback_time) = @_; my $b64 = $dig->clone->b64digest; # Make our own URLs nicer: # See "Base 64 Encoding with URL and Filename Safe Alphabet" in RFC4648 @@ -520,7 +520,7 @@ # Add a date prefix to prevent a leading '-' in case that trips # up some tools (e.g. if a Message-ID were a expected as a # command-line arg) - my $dt = msg_datestamp($hdr); + my $dt = msg_datestamp($hdr, $fallback_time); $dt = POSIX::strftime('%Y%m%d%H%M%S', gmtime($dt)); "$dt.$b64" . '@z'; } diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm index 69ba8303189fda562b9f6a83eb8df1adf1f24ab1..148aa18510546f603ef9fa6b98790ea8fa4925fe 100644 --- a/lib/PublicInbox/LeiSearch.pm +++ b/lib/PublicInbox/LeiSearch.pm @@ -58,7 +58,7 @@ my $mids = mids_in($eml, qw(Message-ID X-Alt-Message-ID Resent-Message-ID)); unless (@$mids) { $eml->{-lei_fake_mid} = $mids->[0] = - PublicInbox::Import::digest2mid($dig, $eml); + PublicInbox::Import::digest2mid($dig, $eml, 0); } ($chash, $mids); } diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm index e1cd31b909bd0f173df3af3f069f01ff1e716847..66dec0999acf58f39af23d79f213bfdb739eaf02 100644 --- a/lib/PublicInbox/OverIdx.pm +++ b/lib/PublicInbox/OverIdx.pm @@ -264,8 +264,10 @@ my ($self, $eml, $smsg) = @_; $smsg->{lines} = $eml->body_raw =~ tr!\n!\n!; my $mids = mids_for_index($eml); my $refs = $smsg->parse_references($eml, $mids); - $mids->[0] //= $smsg->{mid} //= $eml->{-lei_fake_mid}; - $smsg->{mid} //= ''; + $mids->[0] //= do { + $smsg->{mid} //= ''; + $eml->{-lei_fake_mid}; + }; my $subj = $smsg->{subject}; my $xpath; if ($subj ne '') { diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm index b4cc2ecb1afe6e4b2a224138cb39a6eff8bdca18..da8ce590991a3e40522bcab2bc0c561d5aa5683f 100644 --- a/lib/PublicInbox/Smsg.pm +++ b/lib/PublicInbox/Smsg.pm @@ -76,7 +76,7 @@ push(@$refs, @$mids) if scalar(@$mids) > 1; return $refs if scalar(@$refs) == 0; # prevent circular references here: - my %seen = ( $smsg->{mid} => 1 ); + my %seen = ( ($smsg->{mid} // '') => 1 ); my @keep; foreach my $ref (@$refs) { if (length($ref) > PublicInbox::MID::MAX_MID_SIZE) { diff --git a/t/lei-import.t b/t/lei-import.t index 99289748d7ba295c6146c305819fd101c4d21a19..9bb4e1fab97a951a7decb5ec6c926bafcddec605 100644 --- a/t/lei-import.t +++ b/t/lei-import.t @@ -79,6 +79,27 @@ is($res->[1], undef, 'only one result'); is($res->[0]->{'m'}, 'k@y', 'got expected message'); is_deeply($res->[0]->{kw}, ['seen'], "`seen' keywords set"); +# no From, Sender, or Message-ID +$eml_str = <<'EOM'; +Subject: draft message with no sender +References: + +No use for a name +EOM +lei_ok([qw(import -F eml -)], undef, { %$lei_opt, 0 => \$eml_str }); +lei_ok(['q', 's:draft message with no sender']); +my $draft_a = json_utf8->decode($lei_out); +ok(!exists $draft_a->[0]->{'m'}, 'no fake mid stored or exposed'); +lei_ok([qw(tag -F eml - +kw:draft)], undef, { %$lei_opt, 0 => \$eml_str }); +lei_ok(['q', 's:draft message with no sender']); +my $draft_b = json_utf8->decode($lei_out); +my $kw = delete $draft_b->[0]->{kw}; +is_deeply($kw, ['draft'], 'draft kw set'); +is_deeply($draft_a, $draft_b, 'fake Message-ID lookup') or + diag explain($draft_a, $draft_b); +lei_ok('blob', '--mail', $draft_b->[0]->{blob}); +is($lei_out, $eml_str, 'draft retrieved by blob'); + # see t/lei_to_mail.t for "import -F mbox*" }); done_testing;