X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-convert.t;h=e1849ff796cd6d840606efd5db7c6e2b11b954f8;hb=4eee5af6011cc8cdefb66c9729952c7eff5c0b0b;hp=7ff628f9faa3a978084193462480b652752e16f6;hpb=29792d70a5d8305f68521664a7fa2e0fe54ff291;p=public-inbox.git diff --git a/t/lei-convert.t b/t/lei-convert.t index 7ff628f9..e1849ff7 100644 --- a/t/lei-convert.t +++ b/t/lei-convert.t @@ -6,6 +6,7 @@ use PublicInbox::MboxReader; use PublicInbox::MdirReader; use PublicInbox::NetReader; use PublicInbox::Eml; +use IO::Uncompress::Gunzip; require_mods(qw(lei -imapd -nntpd Mail::IMAPClient Net::NNTP)); my ($tmpdir, $for_destroy) = tmpdir; my $sock = tcp_server; @@ -56,7 +57,7 @@ test_lei({ tmpdir => $tmpdir }, sub { lei_ok('convert', '-o', "$d/md", "mboxrd:$d/foo.mboxrd"); ok(-d "$d/md", 'Maildir created'); my @md; - PublicInbox::MdirReader::maildir_each_eml("$d/md", sub { + PublicInbox::MdirReader->new->maildir_each_eml("$d/md", sub { push @md, $_[2]; }); is(scalar(@md), scalar(@mboxrd), 'got expected emails in Maildir') or @@ -91,13 +92,38 @@ test_lei({ tmpdir => $tmpdir }, sub { @bar = (); PublicInbox::MboxReader->mboxcl2($fh, sub { my $eml = shift; - for my $h (qw(Status Content-Length Lines)) { + for my $h (qw(Content-Length Lines)) { ok(defined($eml->header_raw($h)), "$h defined for mboxcl2"); $eml->header_set($h); } push @bar, $eml; }); - is_deeply(\@bar, [ eml_load('t/plack-qp.eml') ], 'eml => mboxcl2'); + my $qp_eml = eml_load('t/plack-qp.eml'); + $qp_eml->header_set('Status', 'O'); + is_deeply(\@bar, [ $qp_eml ], 'eml => mboxcl2'); + + lei_ok qw(convert t/plack-qp.eml -o), "mboxrd:$d/qp.gz"; + open $fh, '<', "$d/qp.gz" or xbail $!; + ok(-s $fh, 'not empty'); + $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); + @bar = (); + PublicInbox::MboxReader->mboxrd($fh, sub { push @bar, shift }); + is_deeply(\@bar, [ $qp_eml ], 'wrote gzipped mboxrd'); + lei_ok qw(convert -o mboxrd:/dev/stdout), "mboxrd:$d/qp.gz"; + open $fh, '<', \$lei_out or xbail; + @bar = (); + PublicInbox::MboxReader->mboxrd($fh, sub { push @bar, shift }); + is_deeply(\@bar, [ $qp_eml ], 'readed gzipped mboxrd'); + + # Status => Maildir flag => Status round trip + $lei_out =~ s/^Status: O/Status: RO/sm or xbail "`seen' Status"; + $rdr = { 0 => \($in = $lei_out), %$lei_opt }; + lei_ok([qw(convert -F mboxrd -o), "$d/md2"], undef, $rdr); + @md = glob("$d/md2/*/*"); + is(scalar(@md), 1, 'one message'); + like($md[0], qr/:2,S\z/, "`seen' flag set in Maildir"); + lei_ok(qw(convert -o mboxrd:/dev/stdout), "$d/md2"); + like($lei_out, qr/^Status: RO/sm, "`seen' flag preserved"); }); done_testing;