#!perl
use Cassandane::Tiny;

sub test_html_only
    :min_version_3_3
{
    my ($self) = @_;
    my $talk = $self->{store}->get_client();

    xlog "Index message with both html and plain text part";
    $self->make_message("test",
        mime_type => "text/html",
        body => ""
          . "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\">\r\n"
          . "<div>This is an html <o:p>LL123</o:p> <h11>xyzzy</h11> body.</div>\r\n"
          . "</html"

    ) || die;
    $self->{instance}->run_command({cyrus => 1}, 'squatter');

    xlog "Assert that HTML in plain text is stripped";
    my $uids = $talk->search('fuzzy', 'body', 'html') || die;
    $self->assert_deep_equals([1], $uids);

    $uids = $talk->search('fuzzy', 'body', 'div') || die;
    $self->assert_deep_equals([], $uids);

    # make sure the "p" doesn't leak into a token
    $uids = $talk->search('fuzzy', 'body', 'LL123p') || die;
    $self->assert_deep_equals([], $uids);

    # make sure the real token gets indexed
    $uids = $talk->search('fuzzy', 'body', 'LL123') || die;
    $self->assert_deep_equals([1], $uids);

    # make sure the h11 doesn't leak
    $uids = $talk->search('fuzzy', 'body', 'xyzzy1') || die;
    $self->assert_deep_equals([], $uids);
    $uids = $talk->search('fuzzy', 'body', 'xyzzy') || die;
    $self->assert_deep_equals([1], $uids);
}
