X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-q-kw.t;h=4edee72a54b733a6237261a98b6c86b352939843;hb=4eee5af6011cc8cdefb66c9729952c7eff5c0b0b;hp=b5e22e9bd368918bebb67cb270f116a0e0aaba60;hpb=bd287d742b81dab13e936727724e5c4de55c44c7;p=public-inbox.git diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t index b5e22e9b..4edee72a 100644 --- a/t/lei-q-kw.t +++ b/t/lei-q-kw.t @@ -14,14 +14,13 @@ my $exp = { '' => eml_load('t/utf8.eml'), }; $exp->{''}->header_set('Status', 'RO'); -$exp->{''}->header_set('Status', 'O'); test_lei(sub { lei_ok(qw(import -F eml t/plack-qp.eml)); my $o = "$ENV{HOME}/dst"; lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com)); my @fn = glob("$o/cur/*:2,"); -scalar(@fn) == 1 or BAIL_OUT "wrote multiple or zero files: ".explain(\@fn); +scalar(@fn) == 1 or xbail $lei_err, 'wrote multiple or zero files:', \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; lei_ok(qw(q -o), "maildir:$o", qw(m:bogus-noresults@example.com)); @@ -29,7 +28,8 @@ ok(!glob("$o/cur/*"), 'last result cleared after augment-import'); lei_ok(qw(q -o), "maildir:$o", qw(m:qp@example.com)); @fn = glob("$o/cur/*:2,S"); -is(scalar(@fn), 1, "`seen' flag set on Maildir file"); +is(scalar(@fn), 1, "`seen' flag set on Maildir file") or + diag "$o contents: ", explain([glob("$o/*/*")]); # ensure --no-import-before works my $n = $fn[0]; @@ -49,6 +49,7 @@ SKIP: { my $cat = popen_rd(['cat', $o]); ok(!lei(qw(q --import-before bogus -o), "mboxrd:$o"), '--import-before fails on non-seekable output'); + like($lei_err, qr/not seekable/, 'unseekable noted in error'); is(do { local $/; <$cat> }, '', 'no output on FIFO'); close $cat; $cat = popen_rd(['cat', $o]); @@ -105,9 +106,19 @@ for my $sfx ('', '.gz') { my %res; PublicInbox::MboxReader->mboxrd($fh, sub { my ($eml) = @_; - $res{$eml->header_raw('Message-ID')} = $eml; + my $mid = $eml->header_raw('Message-ID'); + if ($mid eq '') { + is_deeply([$eml->header('Status')], [], + "no status $sfx"); + $eml->header_set('Status'); + } elsif ($mid eq '') { + is($eml->header('Status'), 'RO', 'status preserved'); + } else { + fail("unknown mid $mid"); + } + $res{$mid} = $eml; }); - is_deeply(\%res, $exp, '--augment worked'); + is_deeply(\%res, $exp, '--augment worked') or diag $lei_err; lei_ok(qw(q -o), "mboxrd:/dev/stdout", qw(m:qp@example.com)) or diag $lei_err; @@ -124,7 +135,7 @@ lei_ok(qw(q -o), $o, "m:$m", @inc); # emulate MUA marking a Maildir message as read: @fn = glob("$o/cur/*"); -scalar(@fn) == 1 or BAIL_OUT "wrote multiple or zero files: ".explain(\@fn); +scalar(@fn) == 1 or xbail $lei_err, 'wrote multiple or zero files:', \@fn; rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; lei_ok(qw(q -o), $o, 'bogus', \'clobber output dir to import keywords'); @@ -161,5 +172,80 @@ like($s, qr/^Status: O\nX-Status: AF\n/ms, lei_ok(qw(q --pretty), "m:$m", @inc); like($lei_out, qr/^ "kw": \["answered", "flagged"\],\n/sm, '--pretty JSON output shows kw: on one line'); + +# ensure import on previously external-only message works +lei_ok('q', "m:$m"); +is_deeply(json_utf8->decode($lei_out), [ undef ], + 'to-be-imported message non-existent'); +lei_ok(qw(import -F eml t/x-unknown-alpine.eml)); +is($lei_err, '', 'no errors importing previous external-only message'); +lei_ok('q', "m:$m"); +$res = json_utf8->decode($lei_out); +is($res->[1], undef, 'got one result'); +is_deeply($res->[0]->{kw}, [ qw(answered flagged) ], 'kw preserved on exact'); + +# ensure fuzzy match import works, too +$m = 'multipart@example.com'; +$o = "$ENV{HOME}/fuzz"; +lei_ok('q', '-o', $o, "m:$m", @inc); +@fn = glob("$o/cur/*"); +scalar(@fn) == 1 or xbail $lei_err, "wrote multiple or zero files", \@fn; +rename($fn[0], "$fn[0]S") or BAIL_OUT "rename $!"; +lei_ok('q', '-o', $o, "m:$m"); +is_deeply([glob("$o/cur/*")], [], 'clobbered output results'); +my $eml = eml_load('t/plack-2-txt-bodies.eml'); +$eml->header_set('List-Id', ''); +my $in = $eml->as_string; +lei_ok([qw(import -F eml --stdin)], undef, { 0 => \$in, %$lei_opt }); +is($lei_err, '', 'no errors from import'); +lei_ok(qw(q -f mboxrd), "m:$m"); +open $fh, '<', \$lei_out or BAIL_OUT $!; +my @res; +PublicInbox::MboxReader->mboxrd($fh, sub { push @res, shift }); +is($res[0]->header('Status'), 'RO', 'seen kw set'); +$res[0]->header_set('Status'); +is_deeply(\@res, [ $eml ], 'imported message matches w/ List-Id'); + +$eml->header_set('List-Id', ''); +$in = $eml->as_string; +lei_ok([qw(import -F eml --stdin)], undef, { 0 => \$in, %$lei_opt }); +is($lei_err, '', 'no errors from 2nd import'); +lei_ok(qw(q -f mboxrd), "m:$m", 'l:another.example.com'); +my @another; +open $fh, '<', \$lei_out or BAIL_OUT $!; +PublicInbox::MboxReader->mboxrd($fh, sub { push @another, shift }); +is($another[0]->header('Status'), 'RO', 'seen kw set'); + +# forwarded +{ + local $ENV{DBG} = 1; + $o = "$ENV{HOME}/forwarded"; + lei_ok(qw(q -o), $o, "m:$m"); + my @p = glob("$o/cur/*"); + scalar(@p) == 1 or xbail('multiple when 1 expected', \@p); + my $passed = $p[0]; + $passed =~ s/,S\z/,PS/ or xbail "failed to replace $passed"; + rename($p[0], $passed) or xbail "rename $!"; + lei_ok(qw(q -o), $o, 'm:bogus', \'clobber maildir'); + is_deeply([glob("$o/cur/*")], [], 'old results clobbered'); + lei_ok(qw(q -o), $o, "m:$m"); + @p = glob("$o/cur/*"); + scalar(@p) == 1 or xbail('multiple when 1 expected', \@p); + like($p[0], qr/,PS/, 'passed (Forwarded) flag kept'); + lei_ok(qw(q -o), "mboxrd:$o.mboxrd", "m:$m"); + open $fh, '<', "$o.mboxrd" or xbail $!; + my @res; + PublicInbox::MboxReader->mboxrd($fh, sub { push @res, shift }); + scalar(@res) == 1 or xbail('multiple when 1 expected', \@res); + is($res[0]->header('Status'), 'RO', 'seen kw set'); + is($res[0]->header('X-Status'), undef, 'no X-Status'); + + lei_ok(qw(q -o), "mboxrd:$o.mboxrd", 'bogus-for-import-before'); + lei_ok(qw(q -o), $o, "m:$m"); + @p = glob("$o/cur/*"); + scalar(@p) == 1 or xbail('multiple when 1 expected', \@p); + like($p[0], qr/,PS/, 'passed (Forwarded) flag still kept'); +} + }); # test_lei done_testing;