INT-3466: IMAP: Move peek Option to Properties
JIRA: https://jira.spring.io/browse/INT-3466 INT-3466 Add Docs
This commit is contained in:
committed by
Gary Russell
parent
f89963dc9b
commit
1a4f98ac4c
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -171,8 +171,17 @@ For example:
|
||||
In the above example instead of relying on the default <classname>SearchTermStrategy</classname> the
|
||||
<classname>TestSearchTermStrategy</classname> will be used instead
|
||||
</para>
|
||||
<important id="imap-peek">
|
||||
<title>Important: IMAP PEEK</title>
|
||||
Starting with <emphasis>version 4.1.1</emphasis>, the IMAP mail receiver will use the <code>mail.imap.peek</code>
|
||||
or <code>mail.imaps.peek</code>
|
||||
javamail property, if specified. Previously, the receiver ignored the property and always set the PEEK flag. Now,
|
||||
if you explicitly set this property to <code>false</code>, the message will be marked as <code>\Seen</code>
|
||||
regardless of the setting of <code>shouldMarkMessagesRead</code>. If not specified, the previous behavior
|
||||
is retained (peek is <code>true</code>).
|
||||
</important>
|
||||
|
||||
<para><emphasis>IMAP IDLE and lost connection</emphasis></para>
|
||||
<para><emphasis role="bold">IMAP IDLE and lost connection</emphasis></para>
|
||||
|
||||
<para>
|
||||
When using IMAP IDLE channel adapter there might be situations where connection to the server may be lost
|
||||
|
||||
@@ -299,6 +299,15 @@
|
||||
See <xref linkend="channel-interceptors"/>.
|
||||
</para>
|
||||
</section>
|
||||
<section id="4.1-mail-peek">
|
||||
<title>IMAP PEEK</title>
|
||||
<para>
|
||||
Since <emphasis>version 4.1.1</emphasis> there is a change of behavior if you explicitly
|
||||
set the javamail property <code>mail.[protocol].peek</code> to <code>false</code>
|
||||
(where <code>[protocol]</code> is <code>imap</code> or <code>imaps</code>).
|
||||
See <xref linkend="imap-peek"/>.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
</chapter>
|
||||
|
||||
Reference in New Issue
Block a user