You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by "Benoit Tellier (Jira)" <se...@james.apache.org> on 2026/07/06 12:50:00 UTC

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

     [ https://issues.apache.org/jira/browse/JAMES-4214?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Benoit Tellier closed JAMES-4214.
---------------------------------
    Resolution: Fixed

Hello

I merged the fix as this is straightforward.

Thanks again for the report

> 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
>            Priority: Critical
>         Attachments: bodyTextMatchBitcoin.script, titi-1.eml
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> When processing a simple text mail with the following SIEVE filter, it does not match the content because the inputstream is already closed when searching 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 mail tit.eml in attachment to reproduce the issue.
> {quote}require "fileinto";
> require "body";
> if body :content "text/plain" :contains "bitcoin" {
>     fileinto "INBOX.select";
> } else {
>     fileinto "INBOX.not.selected";
> }
> {quote}
>  
> The issue is not located in mime4j, the following unit test works well in org.apache.james.mime4j.utils.search.MessageMatcherTest
> {quote}{{@Test}}
> {{public void isFoundInShouldBeAbleToLocateTextFragments2() throws Exception {}}
> {{        MessageMatcher messageMatcher = MessageMatcher.builder()}}
> {{                .searchContents(Lists.<CharSequence>newArrayList("bitcoin"))}}
> {{                .caseInsensitive(false)}}
> {{                .includeHeaders(false)}}
> {{                .contentTypes(ImmutableList.of("text/plain"))}}
> {{                .build();}}
> {{        assertThat(messageMatcher.messageMatches(getResourceStream("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 bytes, so the isFound() does not read anything at all.
>  
> You can add the following test in the SieveIntegrationTest class, it does not work.
> {{@Test}}
> {{void bodyTextShouldMatchContentWithBitcoin() throws Exception {}}
> {{    prepareTestUsingScript("org/apache/james/transport/mailets/delivery/bodyTextMatchBitcoin.script");}}{{    }}
> {{FakeMail mail = FakeMail.builder()}}
> {{            .name("name")}}
> {{            .mimeMessage(MimeMessageUtil.mimeMessageFromStream(}}
> {{                    ClassLoader.getSystemResourceAsStream("eml/titi.eml")))}}
> {{            .state(Mail.DEFAULT)}}
> {{            .recipient(RECEIVER_DOMAIN_COM)}}
> {{            .sender("sender@any.com")}}
> {{            .build();}}
> {{    testee.service(mail);}}{{    assertThatAttribute(mail.getAttribute(ATTRIBUTE_NAME)).isEqualTo(ATTRIBUTE_SELECTED_MAILBOX);}}
> {{}}}
>  



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

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org