#!perl
use Cassandane::Tiny;

sub test_contact_get_invalid_utf8
    :min_version_3_3
{
    my ($self) = @_;
    my $jmap = $self->{jmap};

    my $res = $jmap->CallMethods([
        ['Contact/get', {
            properties => ['emails'],
        }, 'R1']
    ]);

    my $datadir = $self->{instance}->folder_to_directory("user.cassandane.#addressbooks.Default");
    copy('data/vcard/invalid-utf8.eml', "$datadir/1.") or die;
    $self->{instance}->run_command({ cyrus => 1 },
        'reconstruct', 'user.cassandane.#addressbooks.Default');

    $res = $jmap->CallMethods([
        ['Contact/get', {
            properties => ['emails'],
        }, 'R1']
    ]);
    $self->assert_deep_equals([{
        type => 'work',
        value => "beno\N{REPLACEMENT CHARACTER}t\@local",
        isDefault => JSON::true,
    }], $res->[0][1]{list}[0]{emails});
}
