use PublicInbox::MdirReader;
use PublicInbox::NetReader;
use PublicInbox::Eml;
-require_git 2.6;
-require_mods(qw(DBD::SQLite Search::Xapian Mail::IMAPClient Net::NNTP));
+use IO::Uncompress::Gunzip;
+require_mods(qw(lei -imapd -nntpd Mail::IMAPClient Net::NNTP));
my ($tmpdir, $for_destroy) = tmpdir;
my $sock = tcp_server;
my $cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2" ];
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');
+ is(scalar(@md), scalar(@mboxrd), 'got expected emails in Maildir') or
+ diag $lei_err;
@md = sort { ${$a->{bdy}} cmp ${$b->{bdy}} } @md;
@mboxrd = sort { ${$a->{bdy}} cmp ${$b->{bdy}} } @mboxrd;
my @rd_nostatus = map {
my $exp = do { local $/; <$fh> };
is($out, $exp, 'stdin => stdout');
- lei_ok qw(convert -F eml -o mboxcl2:/dev/stdout t/plack-qp.eml);
+ lei_ok qw(convert -F eml -o mboxcl2:/dev/fd/1 t/plack-qp.eml);
open $fh, '<', \$lei_out or BAIL_OUT;
@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;