From ca68e519d588b1fd97d9d4a9c43bbb07534624c2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2020 07:04:09 +0000 Subject: imap: support fetch for BODYSTRUCTURE and BODY I'm not sure which clients use these, but it could be useful down the line. --- t/imapd.t | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/imapd.t b/t/imapd.t index c31ac12f..31154bdf 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -7,7 +7,7 @@ use Time::HiRes (); use PublicInbox::TestCommon; use PublicInbox::Config; use PublicInbox::Spawn qw(which); -require_mods(qw(DBD::SQLite Mail::IMAPClient)); +require_mods(qw(DBD::SQLite Mail::IMAPClient Mail::IMAPClient::BodyStructure)); my $level = '-Lbasic'; SKIP: { @@ -190,6 +190,11 @@ for my $r ('1:*', '1') { $ret = $mic->fetch_hash($r, 'FLAGS') or BAIL_OUT "FETCH $@"; is_deeply($ret->{1}->{FLAGS}, '', 'no flags'); + + my $bs = $mic->get_bodystructure($r) or BAIL_OUT("bodystructure: $@"); + ok($bs, 'got a bodystructure'); + is(lc($bs->bodytype), 'text', '->bodytype'); + is(lc($bs->bodyenc), '8bit', '->bodyenc'); } # Mail::IMAPClient ->compress creates cyclic reference: @@ -217,10 +222,12 @@ $pi_config->each_inbox(sub { my $ng = $ibx->{newsgroup}; my $mic = Mail::IMAPClient->new(%mic_opt); ok($mic && $mic->login && $mic->IsAuthenticated, "authed $name"); + my $uidnext = $mic->uidnext($ng); # we'll fetch BODYSTRUCTURE on this + ok($uidnext, 'got uidnext for later fetch'); is_deeply([$mic->has_capability('IDLE')], ['IDLE'], "IDLE capa $name"); ok(!$mic->idle, "IDLE fails w/o SELECT/EXAMINE $name"); ok($mic->examine($ng), "EXAMINE $ng succeeds"); - ok($mic->idle, "IDLE succeeds on $ng"); + ok(my $idle_tag = $mic->idle, "IDLE succeeds on $ng"); open(my $fh, '<', 't/data/message_embed.eml') or BAIL_OUT("open: $!"); run_script(['-mda', '--no-precheck'], $env, { 0 => $fh }) or @@ -280,6 +287,11 @@ $pi_config->each_inbox(sub { ok(@res = $mic->idle_data(11), "IDLE succeeds on $ng after HUP"); is(grep(/\A\* [0-9] EXISTS\b/, @res), 1, 'got EXISTS message'); ok((Time::HiRes::time() - $t0) < 10, 'IDLE client notified'); + ok($mic->done($idle_tag), 'IDLE DONE'); + my $bs = $mic->get_bodystructure($uidnext); + ok($bs, 'BODYSTRUCTURE ok for deeply nested'); + $ret = $mic->fetch_hash($uidnext, 'BODY') or BAIL_OUT "FETCH $@"; + ok($ret->{$uidnext}->{BODY}, 'got something in BODY'); }); $td->kill; -- cgit v1.2.3-24-ge0c7