Class ImapMailReceiver

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ExpressionCapable, MailReceiver, NamedComponent

public class ImapMailReceiver extends AbstractMailReceiver
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
  • Constructor Details

    • ImapMailReceiver

      public ImapMailReceiver()
    • ImapMailReceiver

      public ImapMailReceiver(String url)
  • Method Details

    • isShouldMarkMessagesAsRead

      public Boolean isShouldMarkMessagesAsRead()
      Check if messages should be marked as read.
      Returns:
      true if messages should be marked as read.
    • setSearchTermStrategy

      public void setSearchTermStrategy(SearchTermStrategy searchTermStrategy)
      Provides a way to set custom SearchTermStrategy to compile a SearchTerm to be applied when retrieving mail.
      Parameters:
      searchTermStrategy - The search term strategy implementation.
    • setShouldMarkMessagesAsRead

      public void setShouldMarkMessagesAsRead(Boolean shouldMarkMessagesAsRead)
      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 class AbstractMailReceiver
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
      Overrides:
      destroy in class AbstractMailReceiver
    • 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 next waitForNewMessages() call will re-open the folder and start a new ping task.
      Since:
      5.2
    • waitForNewMessages

      public void waitForNewMessages() throws MessagingException
      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

      protected Message[] searchForNewMessages() throws MessagingException
      Retrieves new messages from this receiver's folder. This implementation creates a SearchTerm that searches for all messages in the folder that are RECENT, not ANSWERED, and not DELETED. The search term is used to search for new messages.
      Specified by:
      searchForNewMessages in class AbstractMailReceiver
      Returns:
      the new messages
      Throws:
      MessagingException - in case of JavaMail errors
    • setAdditionalFlags

      protected void setAdditionalFlags(Message message) throws MessagingException
      Description copied from class: AbstractMailReceiver
      Optional method allowing you to set additional flags. Currently only implemented in IMapMailReceiver.
      Overrides:
      setAdditionalFlags in class AbstractMailReceiver
      Parameters:
      message - The message.
      Throws:
      MessagingException - A MessagingException.