diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java
index 74a72f1ffb..43e06c6f56 100755
--- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java
+++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java
@@ -143,6 +143,10 @@ public abstract class AbstractMailReceiver extends IntegrationObjectSupport impl
this.javaMailProperties = javaMailProperties;
}
+ protected Properties getJavaMailProperties() {
+ return javaMailProperties;
+ }
+
/**
* Optional, sets the Authenticator to be used to obtain a session. This will not be used if
* {@link AbstractMailReceiver#setSession} has been used to configure the {@link Session} directly.
diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java
index a7c3904c6c..9b764b0ade 100755
--- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java
+++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/ImapMailReceiver.java
@@ -17,6 +17,7 @@
package org.springframework.integration.mail;
import java.util.Date;
+import java.util.Properties;
import java.util.concurrent.ScheduledFuture;
import javax.mail.Flags;
@@ -37,7 +38,6 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.Assert;
import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPMessage;
/**
* A {@link MailReceiver} implementation for receiving mail messages from a
@@ -51,6 +51,7 @@ import com.sun.mail.imap.IMAPMessage;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
+ * @author Artem Bilan
*/
public class ImapMailReceiver extends AbstractMailReceiver {
@@ -136,6 +137,13 @@ public class ImapMailReceiver extends AbstractMailReceiver {
scheduler.initialize();
this.scheduler = scheduler;
}
+ Properties javaMailProperties = getJavaMailProperties();
+ for (String name : new String[]{"imap", "imaps"}) {
+ String peek = "mail." + name + ".peek";
+ if (javaMailProperties.getProperty(peek) == null) {
+ javaMailProperties.setProperty(peek, "true");
+ }
+ }
}
/**
@@ -189,11 +197,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
SearchTerm searchTerm = this.compileSearchTerms(supportedFlags);
Folder folder = this.getFolder();
if (folder.isOpen()) {
- Message[] messages = searchTerm != null ? folder.search(searchTerm) : folder.getMessages();
- for (Message message : messages) {
- ((IMAPMessage) message).setPeek(true);
- }
- return messages;
+ return searchTerm != null ? folder.search(searchTerm) : folder.getMessages();
}
throw new MessagingException("Folder is closed");
}
@@ -214,7 +218,7 @@ public class ImapMailReceiver extends AbstractMailReceiver {
@Override
public void run() {
try {
- IMAPFolder folder = (IMAPFolder) getFolder();
+ Folder folder = getFolder();
logger.debug("Canceling IDLE");
if (folder != null) {
folder.isOpen(); // resets idle state
diff --git a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java
index a5efaf7bd0..3d04a1b083 100644
--- a/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java
+++ b/spring-integration-mail/src/test/java/org/springframework/integration/mail/config/ImapIdleChannelAdapterParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
+ * @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -74,7 +75,8 @@ public class ImapIdleChannelAdapterParserTests {
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
- assertEquals(0, properties.size());
+ // mail.imap(s).peek properties
+ assertEquals(2, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
assertNull(adapterAccessor.getPropertyValue("errorChannel"));
@@ -94,7 +96,8 @@ public class ImapIdleChannelAdapterParserTests {
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
- assertEquals(0, properties.size());
+ // mail.imap(s).peek properties
+ assertEquals(2, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
assertSame(context.getBean("errorChannel"), adapterAccessor.getPropertyValue("errorChannel"));
@@ -113,7 +116,8 @@ public class ImapIdleChannelAdapterParserTests {
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
- assertEquals(0, properties.size());
+ // mail.imap(s).peek properties
+ assertEquals(2, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
}
@@ -132,7 +136,8 @@ public class ImapIdleChannelAdapterParserTests {
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
- assertEquals(0, properties.size());
+ // mail.imap(s).peek properties
+ assertEquals(2, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
assertEquals(Boolean.FALSE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
}
@@ -176,7 +181,8 @@ public class ImapIdleChannelAdapterParserTests {
Object url = receiverAccessor.getPropertyValue("url");
assertEquals(new URLName("imap:foo"), url);
Properties properties = (Properties) receiverAccessor.getPropertyValue("javaMailProperties");
- assertEquals(0, properties.size());
+ // mail.imap(s).peek properties
+ assertEquals(2, properties.size());
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldDeleteMessages"));
assertEquals(Boolean.TRUE, receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead"));
assertNull(adapterAccessor.getPropertyValue("errorChannel"));
diff --git a/src/reference/docbook/mail.xml b/src/reference/docbook/mail.xml
index d467d11976..2f58cefdf6 100644
--- a/src/reference/docbook/mail.xml
+++ b/src/reference/docbook/mail.xml
@@ -171,8 +171,17 @@ For example:
In the above example instead of relying on the default SearchTermStrategy the
TestSearchTermStrategy will be used instead
+
+ Important: IMAP PEEK
+ Starting with version 4.1.1, the IMAP mail receiver will use the mail.imap.peek
+ or mail.imaps.peek
+ javamail property, if specified. Previously, the receiver ignored the property and always set the PEEK flag. Now,
+ if you explicitly set this property to false, the message will be marked as \Seen
+ regardless of the setting of shouldMarkMessagesRead. If not specified, the previous behavior
+ is retained (peek is true).
+
- IMAP IDLE and lost connection
+ IMAP IDLE and lost connection
When using IMAP IDLE channel adapter there might be situations where connection to the server may be lost
diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml
index d1183ddf88..ba5d1802ff 100644
--- a/src/reference/docbook/whats-new.xml
+++ b/src/reference/docbook/whats-new.xml
@@ -299,6 +299,15 @@
See .
+
+ IMAP PEEK
+
+ Since version 4.1.1 there is a change of behavior if you explicitly
+ set the javamail property mail.[protocol].peek to false
+ (where [protocol] is imap or imaps).
+ See .
+
+