#!perl
use Cassandane::Tiny;

sub test_email_query_dash_sieve
    :min_version_3_3 :JMAPExtensions
    :needs_component_sieve
{
    my ($self) = @_;
    my $jmap = $self->{jmap};
    my $imap = $self->{store}->get_client();

    xlog "Running query in sieve";
    $imap->create("INBOX.matches") or die;
    $self->{instance}->install_sieve_script(<<'EOF'
require ["x-cyrus-jmapquery", "x-cyrus-log", "variables", "fileinto"];
if
  allof( not string :is "${stop}" "Y",
    jmapquery text:
  {
     "operator" : "AND",
     "conditions" : [
        {
           "subject" : "something"
        },
        {
           "subject" : "-"
        },
        {
           "subject" : "otherthing"
        }
     ]
  }
.
  )
{
  fileinto "INBOX.matches";
}
EOF
    );

    my $msg1 = $self->{gen}->generate(
		subject => 'something - otherthing', body => ''
    );
    $self->{instance}->deliver($msg1);
    my $msg2 = $self->{gen}->generate(
		subject => 'something', body => ''
    );
    my $msg3 = $self->{gen}->generate(
		subject => 'otherthing', body => ''
    );
    $self->{instance}->deliver($msg1);
    $self->{store}->set_fetch_attributes('uid');
    $self->{store}->set_folder('INBOX.matches');
    $self->check_messages({ 1 => $msg1 }, check_guid => 0);
}
