2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
7 use PublicInbox::MsgIter qw(msg_part_text);
8 use PublicInbox::LeiToMail;
9 my $eml2mboxcl2 = PublicInbox::LeiToMail->can('eml2mboxcl2');
10 my $git_dir = $ENV{GIANT_GIT_DIR};
11 plan 'skip_all' => "GIANT_GIT_DIR not defined for $0" unless defined($git_dir);
13 $Data::Dumper::Useqq = 1;
15 if (my $out = $ENV{DEBUG_MBOXCL2}) {
16 BAIL_OUT("$out exists") if -s $out;
17 open $mboxfh, '>', $out or BAIL_OUT "open $out: $!";
19 diag "DEBUG_MBOXCL2 unset, not saving debug output";
22 my $git = PublicInbox::Git->new($git_dir);
23 my @cat = qw(cat-file --buffer --batch-check --batch-all-objects);
24 if (require_git(2.19, 1)) {
25 push @cat, '--unordered';
27 warn "git <2.19, cat-file lacks --unordered, locality suffers\n";
29 my ($errs, $ok, $tot);
30 $errs = $ok = $tot = 0;
31 my $ep = sub { # eml->each_part callback
32 my ($part, $level, @ex) = @{$_[0]};
34 my $ct = $part->content_type // return;
35 $ct =~ m!\bapplication/octet-stream\b!i or return;
36 my ($s, $err) = msg_part_text($part, $ct);
42 my $x = eval { $part->body };
44 warn "decode totally failed: $@";
46 my ($bad) = ($x =~ m/([\p{XPosixPrint}\s]{0,10}
48 [\p{XPosixPrint}\s]{0,10})/sx);
52 push @{$_[1]}, $err; # $fail
57 my ($bref, $oid) = @_;
58 my $eml = PublicInbox::Eml->new($bref);
59 local $SIG{__WARN__} = sub { diag("$oid ", @_) };
60 $eml->each_part($ep, my $fail = []);
61 if (@$fail && $mboxfh) {
63 print $mboxfh ${$eml2mboxcl2->($eml, { blob => $oid })} or
67 my $cat = $git->popen(@cat);
69 my ($oid, $type, $size) = split(/ /);
70 $git->cat_async($oid, $cb) if $size && $type eq 'blob';
74 note "$ok/$tot messages had text as application/octet-stream";