[jira] [Created] (JAMES-4214) Sieve MessageMatcher failed for simple Mime message

"vincent royer (Jira)" <[email protected]> Tue, 30 Jun 2026 20:09:00 +0000 (UTC)
Newsgroups gmane.comp.jakarta.james.devel
Message-ID <[email protected]>
vincent royer created JAMES-4214:
------------------------------------

             Summary: Sieve MessageMatcher failed for simple Mime message
                 Key: JAMES-4214
                 URL: https://issues.apache.org/jira/browse/JAMES-4214
             Project: James Server
          Issue Type: Bug
          Components: Matchers/Mailets (bundled), sieve
    Affects Versions: 3.9.0
         Environment: apache james 3.9.0
            Reporter: vincent royer
         Attachments: bodyTextMatchBitcoin.script, titi-1.eml

When processing a simple text mail with the following SIEVE filter, it does=
 not match the content because the inputstream is already closed when searc=
hing for the keyword in the message body. With a multi-part message, there =
is no issue and the SIEVE filter match the keyword. Please find the raw mai=
l tit.eml in attachment to reproduce the issue.
{quote}require "fileinto";
require "body";

if body :content "text/plain" :contains "bitcoin" {
=C2=A0 =C2=A0 fileinto "INBOX.select";
} else {
=C2=A0 =C2=A0 fileinto "INBOX.not.selected";
}
{quote}
=C2=A0

The issue is not located in mime4j, the following unit test works well in o=
rg.apache.james.mime4j.utils.search.MessageMatcherTest
{quote}{{@Test}}
{{public void isFoundInShouldBeAbleToLocateTextFragments2() throws Exceptio=
n {}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 MessageMatcher messageMatcher =3D MessageMatc=
her.builder()}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .searchContents(L=
ists.<CharSequence>newArrayList("bitcoin"))}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .caseInsensitive(=
false)}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .includeHeaders(f=
alse)}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .contentTypes(Imm=
utableList.of("text/plain"))}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .build();}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 assertThat(messageMatcher.messageMatches(getR=
esourceStream("titi.eml"))).isTrue();}}{quote}
{quote}{{}}}{quote}
The issue really happens when reading a single-part text/plain message from=
 a mailet, it seems the underlying input stream does not reset the read byt=
es, so the isFound() does not read anything at all.

=C2=A0

You can add the following test in the SieveIntegrationTest class, it does n=
ot work.

{{@Test}}
{{void bodyTextShouldMatchContentWithBitcoin() throws Exception {}}
{{=C2=A0 =C2=A0 prepareTestUsingScript("org/apache/james/transport/mailets/=
delivery/bodyTextMatchBitcoin.script");}}{{=C2=A0 =C2=A0 }}

{{FakeMail mail =3D FakeMail.builder()}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .name("name")}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .mimeMessage(MimeMessageUtil.mi=
meMessageFromStream(}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Cla=
ssLoader.getSystemResourceAsStream("eml/titi.eml")))}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .state(Mail.DEFAULT)}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .recipient(RECEIVER_DOMAIN_COM)=
}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .sender("[email protected]")}}
{{=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .build();}}
{{=C2=A0 =C2=A0 testee.service(mail);}}{{=C2=A0 =C2=A0 assertThatAttribute(=
mail.getAttribute(ATTRIBUTE_NAME)).isEqualTo(ATTRIBUTE_SELECTED_MAILBOX);}}
{{}}}

=C2=A0



--
This message was sent by Atlassian Jira
(v8.20.10#820010)