This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 60e8f8346502 CAMEL-27199: camel-mail - parse the fixed-date search
terms with seconds (HH:mm:ss) (#30537)
60e8f8346502 is described below
commit 60e8f83465023dd55c5f92c1186ea66259180c14
Author: Urmila Unni <[email protected]>
AuthorDate: Sat Nov 21 13:19:40 2026 +0530
CAMEL-27199: camel-mail - parse the fixed-date search terms with seconds
(HH:mm:ss) (#30537)
The fixed-date form of the fromSentDate, toSentDate, fromReceivedDate and
toReceivedDate search terms was parsed with HH:mm:SS, where SS is milliseconds,
so the seconds of the date were lost. Use HH:mm:ss, fix the SimpleSearchTerm
javadoc, and document the two date forms.
* CAMEL-27199: test the received-date search terms too
Co-authored-by: Claude <[email protected]>
---
.../apache/camel/catalog/docs/mail-component.adoc | 5 +-
.../camel-mail/src/main/docs/mail-component.adoc | 5 +-
.../camel/component/mail/MailConverters.java | 2 +-
.../camel/component/mail/SimpleSearchTerm.java | 2 +-
.../mail/MailConvertersSearchTermDateTest.java | 97 ++++++++++++++++++++++
5 files changed, 107 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mail-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mail-component.adoc
index 6c683cb2515e..a7c423fbab02 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mail-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mail-component.adoc
@@ -762,7 +762,10 @@ word "Camel". +
number of options you can configure:
Or to get the new unseen emails going 24 hours back in time, you can do.
-Notice the "now-24h" syntax. See the table below for more details.
+Notice the "now-24h" syntax. The `fromSentDate`, `toSentDate`,
+`fromReceivedDate` and `toReceivedDate` options take either `now`,
+with an optional offset such as `-24h`, or a fixed date in the
+`yyyy-MM-dd HH:mm:ss` format, such as `2026-11-18 14:30:45`.
[tabs]
====
diff --git a/components/camel-mail/src/main/docs/mail-component.adoc
b/components/camel-mail/src/main/docs/mail-component.adoc
index 6c683cb2515e..a7c423fbab02 100644
--- a/components/camel-mail/src/main/docs/mail-component.adoc
+++ b/components/camel-mail/src/main/docs/mail-component.adoc
@@ -762,7 +762,10 @@ word "Camel". +
number of options you can configure:
Or to get the new unseen emails going 24 hours back in time, you can do.
-Notice the "now-24h" syntax. See the table below for more details.
+Notice the "now-24h" syntax. The `fromSentDate`, `toSentDate`,
+`fromReceivedDate` and `toReceivedDate` options take either `now`,
+with an optional offset such as `-24h`, or a fixed date in the
+`yyyy-MM-dd HH:mm:ss` format, such as `2026-11-18 14:30:45`.
[tabs]
====
diff --git
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
index 69763740b865..b7c12761a6b9 100644
---
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
+++
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
@@ -50,7 +50,7 @@ import org.eclipse.angus.mail.imap.SortTerm;
@Converter(generateLoader = true)
public final class MailConverters {
- private static final String NOW_DATE_FORMAT = "yyyy-MM-dd HH:mm:SS";
+ private static final String NOW_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
// the now syntax: "now-24h" or "now - 24h" = the last 24 hours etc.
private static final Pattern NOW_PATTERN =
Pattern.compile("now\\s?(\\+|\\-)\\s?(.*)");
diff --git
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/SimpleSearchTerm.java
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/SimpleSearchTerm.java
index e7fdb1b2decf..1ca2275c8b3b 100644
---
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/SimpleSearchTerm.java
+++
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/SimpleSearchTerm.java
@@ -23,7 +23,7 @@ package org.apache.camel.component.mail;
* This POJO has default <tt>true</tt> for the {@link #isUnseen()} option.
* <p/>
* The date options (such as {@link #setFromReceivedDate(String)}) is using
the following date pattern
- * <tt>yyyy-MM-dd HH:mm:SS</tt>.
+ * <tt>yyyy-MM-dd HH:mm:ss</tt>.
*/
public class SimpleSearchTerm {
diff --git
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConvertersSearchTermDateTest.java
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConvertersSearchTermDateTest.java
new file mode 100644
index 000000000000..cedbcb1e1376
--- /dev/null
+++
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConvertersSearchTermDateTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mail;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+
+import jakarta.mail.Session;
+import jakarta.mail.internet.MimeMessage;
+import jakarta.mail.search.SearchTerm;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The fixed-date form of the date search options keeps the seconds of the
date (yyyy-MM-dd HH:mm:ss).
+ */
+class MailConvertersSearchTermDateTest {
+
+ @Test
+ void fromSentDateKeepsTheSeconds() throws Exception {
+ SimpleSearchTerm simple = new SimpleSearchTerm();
+ simple.setUnseen(false);
+ simple.setFromSentDate("2026-11-18 14:30:45");
+ SearchTerm term = MailConverters.toSearchTerm(simple);
+
+ assertFalse(term.match(sentAt("2026-11-18 14:30:10")), "a mail sent
before the given time");
+ assertTrue(term.match(sentAt("2026-11-18 14:30:50")), "a mail sent
after the given time");
+ }
+
+ @Test
+ void toSentDateKeepsTheSeconds() throws Exception {
+ SimpleSearchTerm simple = new SimpleSearchTerm();
+ simple.setUnseen(false);
+ simple.setToSentDate("2026-11-18 14:30:45");
+ SearchTerm term = MailConverters.toSearchTerm(simple);
+
+ assertTrue(term.match(sentAt("2026-11-18 14:30:10")), "a mail sent
before the given time");
+ assertFalse(term.match(sentAt("2026-11-18 14:30:50")), "a mail sent
after the given time");
+ }
+
+ @Test
+ void fromReceivedDateKeepsTheSeconds() throws Exception {
+ SimpleSearchTerm simple = new SimpleSearchTerm();
+ simple.setUnseen(false);
+ simple.setFromReceivedDate("2026-11-18 14:30:45");
+ SearchTerm term = MailConverters.toSearchTerm(simple);
+
+ assertFalse(term.match(receivedAt("2026-11-18 14:30:10")), "a mail
received before the given time");
+ assertTrue(term.match(receivedAt("2026-11-18 14:30:50")), "a mail
received after the given time");
+ }
+
+ @Test
+ void toReceivedDateKeepsTheSeconds() throws Exception {
+ SimpleSearchTerm simple = new SimpleSearchTerm();
+ simple.setUnseen(false);
+ simple.setToReceivedDate("2026-11-18 14:30:45");
+ SearchTerm term = MailConverters.toSearchTerm(simple);
+
+ assertTrue(term.match(receivedAt("2026-11-18 14:30:10")), "a mail
received before the given time");
+ assertFalse(term.match(receivedAt("2026-11-18 14:30:50")), "a mail
received after the given time");
+ }
+
+ private static MimeMessage sentAt(String date) throws Exception {
+ MimeMessage message = new MimeMessage(Session.getInstance(new
Properties()));
+ message.setSentDate(new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss").parse(date));
+ return message;
+ }
+
+ private static MimeMessage receivedAt(String date) throws Exception {
+ Date received = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss").parse(date);
+ // only a mail server sets the received date, so a MimeMessage made
here has none
+ return new MimeMessage(Session.getInstance(new Properties())) {
+ @Override
+ public Date getReceivedDate() {
+ return received;
+ }
+ };
+ }
+}