#!perl
use Cassandane::Tiny;

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

    open(my $F, "data/mime/utf8-domain.bin") || die $!;
    $imap->append('INBOX', $F) || die $@;
    close($F);

    my $res = $jmap->CallMethods([
        ['Email/query', { }, 'R1'],
        ['Email/get', {
            '#ids' => {
                resultOf => 'R1',
                name => 'Email/query',
                path => '/ids'
            },
            properties => ['from', 'subject'],
        }, 'R2'],
    ]);

use utf8;
    $self->assert_deep_equals([{
        name =>  'J. Besteiro',
        email => 'jb@xn--julin-0qa.example.com',
    }], $res->[1][1]{list}[0]{from});
no utf8;

    $imap->select('INBOX');
    $res = $imap->fetch('1:*', 'ENVELOPE');
    $self->assert_str_equals('"J. Besteiro" <jb@julián.example.com>',
        $res->{1}{envelope}{From});
}
