This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch quick-fix/mail-received-now in repository https://gitbox.apache.org/repos/asf/camel.git
commit 39e233402bdedcfb902ec027021b3e864702fcfd Author: Claus Ibsen <[email protected]> AuthorDate: Sat Nov 21 07:57:22 2026 +0100 chore: camel-mail - SearchTermBuilder.receivedNow(Comparison, long) builds a received-date term The two-argument receivedNow called sentNow, so it built a term on the sent date instead of the received date. The overload with an Op was correct. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../camel/component/mail/SearchTermBuilder.java | 2 +- .../component/mail/SearchTermBuilderTest.java | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/SearchTermBuilder.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/SearchTermBuilder.java index 0bbd84c513d0..672a5bced55b 100644 --- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/SearchTermBuilder.java +++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/SearchTermBuilder.java @@ -180,7 +180,7 @@ public class SearchTermBuilder { } public SearchTermBuilder receivedNow(Comparison comparison, long offset) { - return sentNow(Op.and, comparison, offset); + return receivedNow(Op.and, comparison, offset); } public SearchTermBuilder receivedNow(Op op, Comparison comparison, long offset) { diff --git a/components/camel-mail/src/test/java/org/apache/camel/component/mail/SearchTermBuilderTest.java b/components/camel-mail/src/test/java/org/apache/camel/component/mail/SearchTermBuilderTest.java index eb4bf8f5bdb8..43906cce1743 100644 --- a/components/camel-mail/src/test/java/org/apache/camel/component/mail/SearchTermBuilderTest.java +++ b/components/camel-mail/src/test/java/org/apache/camel/component/mail/SearchTermBuilderTest.java @@ -112,6 +112,39 @@ public class SearchTermBuilderTest { assertFalse(st.match(msg2), "Should not match message as its too old"); } + @Test + public void testSearchTermReceivedLast24Hours() throws Exception { + SearchTermBuilder build = new SearchTermBuilder(); + long offset = -1 * (24 * 60 * 60 * 1000L); + SearchTerm st = build.receivedNow(Comparison.GE, offset).build(); + + assertNotNull(st); + + JavaMailSender sender = new DefaultJavaMailSender(); + long twoDays = 2 * 24 * 60 * 60 * 1000L; + Date now = new Date(); + Date twoDaysAgo = new Date(now.getTime() - twoDays); + + // sent 2 days ago, received now + MimeMessage msg = newMessageReceivedAt(sender, now); + msg.setSentDate(twoDaysAgo); + assertTrue(st.match(msg), "Should match message as it was received now"); + + // sent now, received 2 days ago + MimeMessage msg2 = newMessageReceivedAt(sender, twoDaysAgo); + msg2.setSentDate(now); + assertFalse(st.match(msg2), "Should not match message as it was received too long ago"); + } + + private static MimeMessage newMessageReceivedAt(JavaMailSender sender, Date receivedDate) { + return new MimeMessage(sender.getSession()) { + @Override + public Date getReceivedDate() { + return receivedDate; + } + }; + } + @Test public void testComparison() { assertEquals(1, Comparison.LE.asNum());
