+
+ if ($ENV{TEST_KILL_IMAPD}) { # not sure how reliable this test can be
+ xsys(qw(git config), "--file=$home/.public-inbox/config",
+ qw(--unset imap.PollInterval)) == 0
+ or BAIL_OUT "git config $?";
+ truncate($err_wr, 0) or BAIL_OUT $!;
+ my @t0 = times;
+ $w = start_script(['-watch'], undef, { 2 => $err_wr });
+ seek($err, 0, 0);
+ tick until (grep(/# \S+ idling/, <$err>));
+ diag 'killing imapd, waiting for CPU spins';
+ my $delay = 0.11;
+ $td->kill(9);
+ tick $delay;
+ $w->kill;
+ $w->join;
+ is($?, 0, 'no error in exited -watch process');
+ my @t1 = times;
+ my $c = $t1[2] + $t1[3] - $t0[2] - $t0[3];
+ my $thresh = (0.9 * $delay);
+ diag "c=$c, threshold=$thresh";
+ ok($c < $thresh, 'did not burn much CPU');
+ is_deeply([grep(/ line \d+$/m, <$err>)], [],
+ 'no backtraces from errors');
+ }
+}
+
+{
+ ok(my $ic = $imap_client->new(%mic_opt), 'logged in');
+ my $mb = "$ibx[0]->{newsgroup}.$first_range";
+ ok($ic->examine($mb), "EXAMINE $mb");
+ my $uidnext = $ic->uidnext($mb); # we'll fetch BODYSTRUCTURE on this
+ my $im = $ibx[0]->importer(0);
+ $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
+Subject: test Ævar
+Message-ID: <smtputf8-delivered-mess\@age>
+From: Ævar Arnfjörð Bjarmason <avarab\@example>
+To: git\@vger.kernel.org
+
+EOF
+ $im->done;
+ my $envl = $ic->get_envelope($uidnext);
+ is($envl->{subject}, 'test Ævar', 'UTF-8 subject');
+ is($envl->{sender}->[0]->{personalname}, 'Ævar Arnfjörð Bjarmason',
+ 'UTF-8 sender[0].personalname');
+ SKIP: {
+ skip 'need compress for comparisons', 1 if !$can_compress;
+ ok($ic = $imap_client->new(%mic_opt), 'uncompressed logged in');
+ ok($ic && $ic->compress, 'compress enabled');
+ ok($ic->examine($mb), "EXAMINE $mb");
+ my $raw = $ic->get_envelope($uidnext);
+ is_deeply($envl, $raw, 'raw and compressed match');
+ }