#!perl
use Cassandane::Tiny;

#
# Test uniqueid and rename
#
sub test_emailid_threadid
    :AltNamespace :Conversations :min_version_3_1
    ($self)
{
    my $admintalk = $self->{adminstore}->get_client();
    my $talk = $self->{store}->get_client();

    $talk->create('foo');

    my %exp;

    $self->{store}->set_fetch_attributes('uid', 'cid');

    xlog $self, "generating message A";
    $exp{A} = $self->make_message("Message A");
    $exp{A}->set_attributes(uid => 1, cid => $exp{A}->make_cid());
    $self->check_messages(\%exp);

    xlog $self, "generating message B";
    $exp{B} = $self->make_message("Re: Message A", references => [ $exp{A} ]);
    $exp{B}->set_attributes(uid => 2, cid => $exp{A}->make_cid());
    $self->check_messages(\%exp);

    xlog $self, "generating message C";
    $exp{C} = $self->make_message("Message C");
    $exp{C}->set_attributes(uid => 3, cid => $exp{C}->make_cid());
    $self->check_messages(\%exp);

    $talk->select('INBOX');
    my $data = $talk->fetch('1:*', "(emailid threadid)");

    $talk->search('emailid', $data->{1}{emailid});
    $talk->search('threadid', $data->{1}{threadid});

    $talk->move("2", "foo");

    $talk->fetch('1:*', "(emailid threadid)");

    $talk->select('foo');
    $talk->fetch('1:*', "(emailid threadid)");

    $talk->select('INBOX');

    my $email = <<EOF;
Subject: foo
Date: bar
From: <foobar\@example.com>

Body
EOF

    my $email2 = <<EOF;
Subject: foo
Date: bar
From: <foobar\@example.com>

Body2
EOF

    $email =~ s/\r?\n/\r\n/gs;
    $email2 =~ s/\r?\n/\r\n/gs;

    $talk->append("INBOX", "()", " 7-Feb-1994 22:43:04 -0800", { Literal => "$email" },
                           "()", " 7-Feb-1994 22:43:04 -0800", { Literal => "$email2" });

    # XXX and then what???  is this test incomplete?
}
