From 2d4ac1c886908bb1d79592913a2a2037a1a024e7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 23 May 2021 08:01:16 +0000 Subject: lei : set \Recent on non-empty mbox and Maildir Despite JMAP not supporting the equivalent of the IMAP \Recent flag, it is useful for "lei q --augment", and "lei up" users to be able to distinguish new results from old-but-unread messages in an mbox or Maildir. For mbox family messages, we'll drop the "O" status flag when appending to mboxes, and we'll write to the "new" subdirectory of Maildirs. Behavior when writing to initially empty Maildirs and mboxes remains unchanged since there's no need to distinguish between new and old results in the initial case. Having users wait for a rename(2) storm or complete mbox rewrite hurts UX. With IMAP mailboxes, \Recent is already enforced by the IMAP server and IMAP clients have no way of changing it(*) (*) mutt uses the "Old" IMAP flag which isn't part of RFC 3501, other MUAs may do similar things. --- t/lei-q-kw.t | 13 +++++++++++-- t/lei-q-save.t | 4 ++-- t/lei_to_mail.t | 16 +++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 't') diff --git a/t/lei-q-kw.t b/t/lei-q-kw.t index c00a0a43..074c573d 100644 --- a/t/lei-q-kw.t +++ b/t/lei-q-kw.t @@ -14,7 +14,6 @@ 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)); @@ -105,7 +104,17 @@ 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'); diff --git a/t/lei-q-save.t b/t/lei-q-save.t index 753d5b20..aed38a51 100644 --- a/t/lei-q-save.t +++ b/t/lei-q-save.t @@ -42,7 +42,7 @@ test_lei(sub { lei_ok qw(up -q md -C), $home; lei_ok qw(up -q . -C), "$home/md"; lei_ok qw(up -q), "/$home/md"; - my %after = map { $_ => 1 } glob("$home/md/cur/*"); + my %after = map { $_ => 1 } glob("$home/md/{new,cur}/*"); is(delete $after{(keys(%before))[0]}, 1, 'original message kept'); is(scalar(keys %after), 1, 'one new message added'); is_deeply(eml_load((keys %after)[0]), $doc2, 'doc2 matches'); @@ -155,7 +155,7 @@ test_lei(sub { $im->add(PublicInbox::Eml->new($diff)); $im->done; lei_ok('up', $o); - @m = glob("$o/cur/*"); + @m = glob("$o/{new,cur}/*"); is(scalar(@m), 2, 'got 2nd result due to different OID'); SKIP: { diff --git a/t/lei_to_mail.t b/t/lei_to_mail.t index 32532a98..35904706 100644 --- a/t/lei_to_mail.t +++ b/t/lei_to_mail.t @@ -90,7 +90,7 @@ my $fn = "$tmpdir/x.mbox"; my ($mbox) = shuffle(@MBOX); # pick one, shouldn't matter my $wcb_get = sub { my ($fmt, $dst) = @_; - delete $lei->{dedupe}; + delete $lei->{dedupe}; # to be recreated $lei->{ovv} = bless { fmt => $fmt, dst => $dst @@ -119,13 +119,12 @@ my $orig = do { like($raw, qr/^blah\n/sm, 'wrote content'); unlink $fn or BAIL_OUT $!; - local $lei->{opt} = { jobs => 2 }; $wcb = $wcb_get->($mbox, $fn); ok(-f $fn && !-s _, 'truncated mbox destination'); $wcb->(\($dup = $buf), $deadbeef); $commit->($wcb); open $fh, '<', $fn or BAIL_OUT $!; - is(do { local $/; <$fh> }, $raw, 'jobs > 1'); + is(do { local $/; <$fh> }, $raw, 'wrote identical content'); $raw; }; @@ -158,21 +157,20 @@ for my $zsfx (qw(gz bz2 xz)) { ok($dc_cmd, "decompressor for .$zsfx"); my $f = "$fn.$zsfx"; my $wcb = $wcb_get->($mbox, $f); - $wcb->(\(my $dup = $buf), $deadbeef); + $wcb->(\(my $dup = $buf), { %$deadbeef }); $commit->($wcb); my $uncompressed = xqx([@$dc_cmd, $f]); is($uncompressed, $orig, "$zsfx works unlocked"); - local $lei->{opt} = { jobs => 2 }; # for atomic writes unlink $f or BAIL_OUT "unlink $!"; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf), $deadbeef); + $wcb->(\($dup = $buf), { %$deadbeef }); $commit->($wcb); is(xqx([@$dc_cmd, $f]), $orig, "$zsfx matches with lock"); local $lei->{opt} = { augment => 1 }; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf . "\nx\n"), $deadbeef); + $wcb->(\($dup = $buf . "\nx\n"), { %$deadbeef }); $commit->($wcb); my $cat = popen_rd([@$dc_cmd, $f]); @@ -182,9 +180,9 @@ for my $zsfx (qw(gz bz2 xz)) { like($raw[1], qr/\nblah\n\nx\n\z/s, "augmented $zsfx"); like($raw[0], qr/\nblah\n\z/s, "original preserved $zsfx"); - local $lei->{opt} = { augment => 1, jobs => 2 }; + local $lei->{opt} = { augment => 1 }; $wcb = $wcb_get->($mbox, $f); - $wcb->(\($dup = $buf . "\ny\n"), $deadbeef); + $wcb->(\($dup = $buf . "\ny\n"), { %$deadbeef }); $commit->($wcb); my @raw3; -- cgit v1.2.3-24-ge0c7