#!perl
use Cassandane::Tiny;

sub test_email_get_bodyvalues_nulbyte
    :min_version_3_9 :needs_component_jmap
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $imap = $self->{store}->get_client();

    my $mimeMsg = <<'EOF';
From: <from@local>
To: to@local
Bcc: bcc@local
Subject: test
Date: Mon, 13 Apr 2020 15:34:03 +0200
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;charset=utf-8

<html><body>hello=00 world</body></html>
EOF
    $mimeMsg =~ s/\r?\n/\r\n/gs;
    $mimeMsg =~ s/\r\n$//;
    $imap->append('INBOX', $mimeMsg) || die $@;

    $res = $jmap->CallMethods([
        ['Email/query', { }, 'R1'],
        ['Email/get', {
            '#ids' => {
                resultOf => 'R1',
                name => 'Email/query',
                path => '/ids'
            },
            properties => ['bodyValues'],
            fetchAllBodyValues => JSON::true,
        }, 'R2'],
    ]);

    my $bodyValue = $res->[1][1]{list}[0]{bodyValues}{1};
    $self->assert_str_equals("<html><body>hello world</body></html>",
        $bodyValue->{value});
    $self->assert_equals(JSON::true, $bodyValue->{isEncodingProblem});
    $self->assert_equals(JSON::false, $bodyValue->{isTruncated});
}
