org.springframework.integration.mail
Class AbstractMailReceiver

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.mail.AbstractMailReceiver
All Implemented Interfaces:
BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, NamedComponent, MailReceiver
Direct Known Subclasses:
ImapMailReceiver, Pop3MailReceiver

public abstract class AbstractMailReceiver
extends IntegrationObjectSupport
implements MailReceiver, DisposableBean

Base class for MailReceiver implementations.


Field Summary
protected  int folderOpenMode
           
protected  boolean initialized
           
protected  org.apache.commons.logging.Log logger
           
static java.lang.String SI_USER_FLAG
           
 
Constructor Summary
AbstractMailReceiver()
           
AbstractMailReceiver(java.lang.String url)
           
AbstractMailReceiver(javax.mail.URLName urlName)
           
 
Method Summary
protected  void deleteMessages(javax.mail.Message[] messages)
          Deletes the given messages from this receiver's folder.
 void destroy()
           
protected  void fetchMessages(javax.mail.Message[] messages)
          Fetches the specified messages from this receiver's folder.
protected  javax.mail.Folder getFolder()
           
protected  void onInit()
          Subclasses may implement this for initialization logic.
protected  void openFolder()
           
 javax.mail.Message[] receive()
           
protected abstract  javax.mail.Message[] searchForNewMessages()
          Subclasses must implement this method to return new mail messages.
protected  void setAdditionalFlags(javax.mail.Message message)
          Optional method allowing you to set additional flags.
 void setJavaMailAuthenticator(javax.mail.Authenticator javaMailAuthenticator)
          Optional, sets the Authenticator to be used to obtain a session.
 void setJavaMailProperties(java.util.Properties javaMailProperties)
          A new Session will be created with these properties (and the JavaMailAuthenticator if provided).
 void setMaxFetchSize(int maxFetchSize)
          Specify the maximum number of Messages to fetch per call to receive().
 void setProtocol(java.lang.String protocol)
           
 void setSelectorExpression(Expression selectorExpression)
           
 void setSession(javax.mail.Session session)
          Set the Session.
 void setShouldDeleteMessages(boolean shouldDeleteMessages)
          Specify whether mail messages should be deleted after retrieval.
protected  boolean shouldDeleteMessages()
          Indicates whether the mail messages should be deleted after being received.
 java.lang.String toString()
           
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getComponentType, getConversionService, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SI_USER_FLAG

public static final java.lang.String SI_USER_FLAG
See Also:
Constant Field Values

logger

protected final org.apache.commons.logging.Log logger

folderOpenMode

protected volatile int folderOpenMode

initialized

protected volatile boolean initialized
Constructor Detail

AbstractMailReceiver

public AbstractMailReceiver()

AbstractMailReceiver

public AbstractMailReceiver(javax.mail.URLName urlName)

AbstractMailReceiver

public AbstractMailReceiver(java.lang.String url)
Method Detail

setSelectorExpression

public void setSelectorExpression(Expression selectorExpression)

setProtocol

public void setProtocol(java.lang.String protocol)

setSession

public void setSession(javax.mail.Session session)
Set the Session. Otherwise, the Session will be created by invocation of Session.getInstance(Properties) or Session.getInstance(Properties, Authenticator).

See Also:
setJavaMailProperties(Properties), setJavaMailAuthenticator(Authenticator)

setJavaMailProperties

public void setJavaMailProperties(java.util.Properties javaMailProperties)
A new Session will be created with these properties (and the JavaMailAuthenticator if provided). Use either this method or setSession(javax.mail.Session), but not both.

See Also:
setJavaMailAuthenticator(Authenticator), setSession(Session)

setJavaMailAuthenticator

public void setJavaMailAuthenticator(javax.mail.Authenticator javaMailAuthenticator)
Optional, sets the Authenticator to be used to obtain a session. This will not be used if setSession(javax.mail.Session) has been used to configure the Session directly.

See Also:
setSession(Session)

setMaxFetchSize

public void setMaxFetchSize(int maxFetchSize)
Specify the maximum number of Messages to fetch per call to receive().


setShouldDeleteMessages

public void setShouldDeleteMessages(boolean shouldDeleteMessages)
Specify whether mail messages should be deleted after retrieval.


shouldDeleteMessages

protected boolean shouldDeleteMessages()
Indicates whether the mail messages should be deleted after being received.


getFolder

protected javax.mail.Folder getFolder()

searchForNewMessages

protected abstract javax.mail.Message[] searchForNewMessages()
                                                      throws javax.mail.MessagingException
Subclasses must implement this method to return new mail messages.

Throws:
javax.mail.MessagingException

openFolder

protected void openFolder()
                   throws javax.mail.MessagingException
Throws:
javax.mail.MessagingException

receive

public javax.mail.Message[] receive()
                             throws javax.mail.MessagingException
Specified by:
receive in interface MailReceiver
Throws:
javax.mail.MessagingException

fetchMessages

protected void fetchMessages(javax.mail.Message[] messages)
                      throws javax.mail.MessagingException
Fetches the specified messages from this receiver's folder. Default implementation fetches every FetchProfile.Item.

Parameters:
messages - the messages to fetch
Throws:
javax.mail.MessagingException - in case of JavaMail errors

deleteMessages

protected void deleteMessages(javax.mail.Message[] messages)
                       throws javax.mail.MessagingException
Deletes the given messages from this receiver's folder.

Parameters:
messages - the messages to delete
Throws:
javax.mail.MessagingException - in case of JavaMail errors

setAdditionalFlags

protected void setAdditionalFlags(javax.mail.Message message)
                           throws javax.mail.MessagingException
Optional method allowing you to set additional flags. Currently only implemented in IMapMailReceiver.

Parameters:
message -
Throws:
javax.mail.MessagingException

destroy

public void destroy()
             throws java.lang.Exception
Specified by:
destroy in interface DisposableBean
Throws:
java.lang.Exception

onInit

protected void onInit()
               throws java.lang.Exception
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport
Throws:
java.lang.Exception

toString

public java.lang.String toString()
Overrides:
toString in class IntegrationObjectSupport