Class ImapMailReceiver
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.mail.AbstractMailReceiver
org.springframework.integration.mail.ImapMailReceiver
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,ComponentSourceAware
,ExpressionCapable
,MailReceiver
,NamedComponent
A
MailReceiver
implementation for receiving mail messages from a
mail server that supports the IMAP protocol. In addition to the pollable
AbstractMailReceiver.receive()
method, the waitForNewMessages()
method provides
the option of blocking until new messages are available prior to calling
AbstractMailReceiver.receive()
. That option is only available if the server supports
the idle
command.- Author:
- Arjen Poutsma, Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Alexander Pinske
-
Field Summary
Fields inherited from class org.springframework.integration.mail.AbstractMailReceiver
DEFAULT_SI_USER_FLAG
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
The hook to be called when we need to cancel the current ping task and close the mail folder.void
destroy()
Check if messages should be marked as read.protected void
onInit()
Subclasses may implement this for initialization logic.protected Message[]
Retrieves new messages from this receiver's folder.protected void
setAdditionalFlags
(Message message) Optional method allowing you to set additional flags.void
setCancelIdleInterval
(long cancelIdleInterval) IDLE commands will be terminated after this interval; useful in cases where a connection might be silently dropped.void
setSearchTermStrategy
(SearchTermStrategy searchTermStrategy) Provides a way to set customSearchTermStrategy
to compile aSearchTerm
to be applied when retrieving mail.void
setShouldMarkMessagesAsRead
(Boolean shouldMarkMessagesAsRead) Specify if messages should be marked as read.void
This method is unique to the IMAP receiver and only works if IMAP IDLE is supported (see RFC 2177 for more detail).Methods inherited from class org.springframework.integration.mail.AbstractMailReceiver
closeFolder, deleteMessages, fetchMessages, getFolder, getFolderOpenMode, getJavaMailProperties, getUserFlag, openFolder, receive, setAutoCloseFolder, setEmbeddedPartsAsBytes, setFlaggedAsFallback, setHeaderMapper, setJavaMailAuthenticator, setJavaMailProperties, setMaxFetchSize, setProtocol, setSelectorExpression, setSession, setShouldDeleteMessages, setSimpleContent, setUserFlag, shouldDeleteMessages, toString
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
ImapMailReceiver
public ImapMailReceiver() -
ImapMailReceiver
-
-
Method Details
-
isShouldMarkMessagesAsRead
Check if messages should be marked as read.- Returns:
- true if messages should be marked as read.
-
setSearchTermStrategy
Provides a way to set customSearchTermStrategy
to compile aSearchTerm
to be applied when retrieving mail.- Parameters:
searchTermStrategy
- The search term strategy implementation.
-
setShouldMarkMessagesAsRead
Specify if messages should be marked as read.- Parameters:
shouldMarkMessagesAsRead
- true if messages should be marked as read.
-
setCancelIdleInterval
public void setCancelIdleInterval(long cancelIdleInterval) IDLE commands will be terminated after this interval; useful in cases where a connection might be silently dropped. A new IDLE will usually immediately be processed. Specified in seconds; default 120 (2 minutes). RFC 2177 recommends an interval no larger than 29 minutes.- Parameters:
cancelIdleInterval
- the cancelIdleInterval to set- Since:
- 3.0.5
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractMailReceiver
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Overrides:
destroy
in classAbstractMailReceiver
-
cancelPing
public void cancelPing()The hook to be called when we need to cancel the current ping task and close the mail folder. In other words: when IMAP idle should be stopped for some reason. The nextwaitForNewMessages()
call will re-open the folder and start a new ping task.- Since:
- 5.2
-
waitForNewMessages
This method is unique to the IMAP receiver and only works if IMAP IDLE is supported (see RFC 2177 for more detail).- Throws:
MessagingException
- Any MessagingException.
-
searchForNewMessages
Retrieves new messages from this receiver's folder. This implementation creates aSearchTerm
that searches for all messages in the folder that areRECENT
, notANSWERED
, and notDELETED
. The search term is used tosearch
for new messages.- Specified by:
searchForNewMessages
in classAbstractMailReceiver
- Returns:
- the new messages
- Throws:
MessagingException
- in case of JavaMail errors
-
setAdditionalFlags
Description copied from class:AbstractMailReceiver
Optional method allowing you to set additional flags. Currently only implemented in IMapMailReceiver.- Overrides:
setAdditionalFlags
in classAbstractMailReceiver
- Parameters:
message
- The message.- Throws:
MessagingException
- A MessagingException.
-