#!perl
use Cassandane::Tiny;

sub test_email_set_mimeversion
    :min_version_3_1 :needs_component_sieve
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $store = $self->{store};
    my $talk = $store->get_client();
    my $inboxid = $self->getinbox()->{id};

    my $email1 = {
        mailboxIds => { $inboxid => JSON::true },
        from => [{ name => "Test", email => q{foo@bar} }],
        subject => "test",
        bodyStructure => {
            partId => '1',
        },
        bodyValues => {
            "1" => {
                value => "A text body",
            },
        },
    };
    my $email2 = {
        mailboxIds => { $inboxid => JSON::true },
        from => [{ name => "Test", email => q{foo@bar} }],
        subject => "test",
	'header:Mime-Version' => '1.1',
        bodyStructure => {
            partId => '1',
        },
        bodyValues => {
            "1" => {
                value => "A text body",
            },
        },
    };
    my $res = $jmap->CallMethods([
        ['Email/set', { create => { '1' => $email1 , 2 => $email2 } }, 'R1'],
	['Email/get', { ids => ['#1', '#2'], properties => ['header:mime-version'] }, 'R2'],
    ]);
    $self->assert_str_equals(' 1.0', $res->[1][1]{list}[0]{'header:mime-version'});
    $self->assert_str_equals(' 1.1', $res->[1][1]{list}[1]{'header:mime-version'});
}
