Class MailEventSource

    • Field Detail

      • PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDER

        public static final String PLUGIN_TYPE_OAUTH2_ACCESS_TOKEN_PROVIDER
        The plug-in type ID for OAuth 2 access token providers.
        See Also:
        Constant Field Values
      • CONF_AUTH_MECHANISM

        public static final String CONF_AUTH_MECHANISM
        The configuration key for the authentication mechanism. This will be used in the Properties for connecting to the mail store.
        See Also:
        Constant Field Values
      • AUTHMECH_XOAUTH2

        public static final String AUTHMECH_XOAUTH2
        Configuration value for the "XOAUTH2" authentication mechanisms.
        See Also:
        Constant Field Values
      • pollTime

        protected Long pollTime
        The time in milliseconds this event source polls its data source.
      • startPoint

        protected Long startPoint
        The start point (in milliseconds) this event should start polling.
      • keepConnection

        protected boolean keepConnection
        Whether the mail storage should not be disconnected between polls.
      • protocol

        protected String protocol
        The protocol to use for this mail events, for instance pop3, imap, ...
      • sslProtocols

        protected String sslProtocols
        The SSL protocols used for secure protocols.
      • host

        protected String host
        The host to connect to and from which to use as mail source.
      • port

        protected int port
        The port of the host to which to connect to.
      • userName

        protected String userName
        The user name to connect to the host with.
      • authMechanism

        protected String authMechanism
        The authentication mechanism to use.
      • password

        protected String password
        The password used to connect to the host with, unless the current authentication mechanism requires something different.
      • oauth2AccessTokenProviderId

        protected String oauth2AccessTokenProviderId
        The optional (simple) instance name of the OAuth2AccessTokenProvider to use when the "XOAUTH2" authentication mechanism is configured. If no ID is specified, the default instance will be used.
      • oauth2AccessTokenProvider

        protected OAuth2AccessTokenProvider oauth2AccessTokenProvider
        The plugin instance that will be used to acquire an OAuth2 access token when the "XOAUTH2" authentication mechanisms is used.
      • folderName

        protected String folderName
        The name of the folder which causes an event when a new mail is received. If not specified the usual INBOX will be used.
      • timeout

        protected long timeout
        The timeout in milliseconds this event source uses for the mail server.
      • eventManager

        protected AbstractEventManager eventManager
        The event manager for retrieving the OAuth2 access token provider.
      • eventManagerURIs

        protected final URI[] eventManagerURIs
        The event manager URIs to provide to the created events.
      • store

        protected javax.mail.Store store
        The mail server which to check for mails. This will be null in case this source is not connected.
    • Constructor Detail

      • MailEventSource

        public MailEventSource​(org.apache.commons.configuration2.Configuration conf,
                               AbstractEventManager eventManager,
                               Registry registry)
                        throws ConfigurationException
        Default constructor for a plugin of an EventManager called by a service registry.

        Note that this constructor calls setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.

        Parameters:
        conf - The configuration as provided from the registry.
        eventManager - The event manager this event source is a plugin of.
        registry - The registry of this plugin.
        Throws:
        ConfigurationException - If the configuration is not valid for a PollingMailSource, a ConfigurationException will be thrown.
      • MailEventSource

        protected MailEventSource​(org.apache.commons.configuration2.Configuration conf,
                                  AbstractEventManager eventManager,
                                  Registry registry,
                                  Class<?> confDesc)
                           throws ConfigurationException
        Constructor for subclasses allowing to set a separate class for the configuration description.

        Note that this constructor calls setConfiguration(Configuration, boolean); subclasses may not be fully initialised at this point.

        Parameters:
        conf - The configuration as provided from the registry.
        eventManager - The event manager this event source is a plugin of.
        registry - The registry of this plugin.
        confDesc - The class (or interface) providing the configuration description to validate.
        Throws:
        ConfigurationException - If the configuration is not valid for a PollingMailSource, a ConfigurationException will be thrown.
    • Method Detail

      • setConfiguration

        protected void setConfiguration​(org.apache.commons.configuration2.Configuration conf,
                                        boolean completed)
                                 throws ConfigurationException
        Sets the internal fields according to the values of the designated configuration. Note that this method is called from the constructor and therefore this object may not be fully initialised!
        Parameters:
        conf - The configuration from which to get the configuration values.
        completed - Whether the configuration is complete after this setting and therefore the values should be verified.
        Throws:
        ConfigurationException - If there are problems with the configuration, for instance the configuration does not provide required values, a ConfigurationException may be thrown.
      • verifyConfigurationValues

        protected void verifyConfigurationValues()
                                          throws ConfigurationException
        This method verifies the configuration values that have been set yet. If a configuration value is missing or inappropriate, a ConfigurationException will be thrown.
        Throws:
        ConfigurationException - If there are problems with the configuration, for instance the configuration does not provide required values, a ConfigurationException may be thrown.
      • setConfiguration

        public void setConfiguration​(org.apache.commons.configuration2.Configuration conf,
                                     String id)
                              throws ConfigurationException
        Description copied from interface: EventSource
        Sets the (additional) configuration of this event source and its ID. The configuration is additional with respect to the configuration provided by the plugin load mechanism, if the event source is loaded as plugin.
        It is ensured that this method will be called before Runnable.run().
        Specified by:
        setConfiguration in interface EventSource<MailEvent>
        Overrides:
        setConfiguration in class AbstractEventSource<MailEvent>
        Parameters:
        conf - The configuration of this event source. This adheres (and overwrites) the configuration provided by the plugin loading, if this event source has been loaded as plugin. Whether this is allowed to be null depends on the implementation of the event source.
        id - The ID of this event source. This must not be null nor the empty string.
        Throws:
        ConfigurationException - If there are problems with the designated configuration (configuration is null although this is not allowed, a required configuration value is missing, ...), a ConfigurationException will be thrown.
      • getStartTime

        public long getStartTime()
        Description copied from interface: PollingSource
        Gets the absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling. This is used for calculating the first poll time by adding the time span defined in PollingSource.getPollTime().
        Specified by:
        getStartTime in interface PollingSource<MailEvent>
        Returns:
        The absolute time in milliseconds since midnight, January 1, 1970 UTC when this polling source should start polling.
      • init

        public void init()
        Description copied from interface: PollingSource
        Initialises this polling source. This is called once before polling is started the first time.
        Specified by:
        init in interface PollingSource<MailEvent>
      • terminate

        public void terminate()
        Description copied from interface: PollingSource
        Terminates this polling source. This is called once after polling has terminated and this source is removed.
        Note that this may be called any time, even when creating or handling an event. So take care to synchronise the implementation appropriately!
        Specified by:
        terminate in interface PollingSource<MailEvent>
      • createMailEvent

        protected MailEvent createMailEvent​(javax.mail.Message message)
                                     throws javax.mail.MessagingException,
                                            IOException
        Creates a MailEvent for the designated message.
        Parameters:
        message - The message for which to create a MailEvent.
        Returns:
        The MailEvent created for the designated message.
        Throws:
        javax.mail.MessagingException - If retrieving the required data from the message fails, a MessagingException will be thrown.
        IOException - Retrieving the (complex) content of the message may thrown an IOException.
      • nextHandler

        protected boolean nextHandler​(MailEvent event,
                                      boolean consumed,
                                      boolean concurrent)
        Description copied from class: AbstractEventSource
        This method is called right before an event is offered to the next handler. In case of concurrent handling, this method will only be called once for all concurrent handling but this will be indicated by the corresponding parameter.
        Specified by:
        nextHandler in class AbstractEventSource<MailEvent>
        Parameters:
        event - The event which is about to be handled by the next registered handler.
        consumed - Whether the event has been consumed yet.
        concurrent - Whether the next event handling is concurrent and thus the event will be offered to several event handler concurrently.
        Returns:
        Whether the event handling may continue. In case of serious problems preventing further event handling, return false here.
      • connectToStore

        protected void connectToStore()
                               throws javax.mail.MessagingException
        Connects to the configured store of this event source.
        Throws:
        javax.mail.MessagingException - If there are problems connecting to the store, a MessagingException will be thrown.
      • closeStore

        protected void closeStore()
                           throws javax.mail.MessagingException
        Closes the message store of this event source.
        Throws:
        javax.mail.MessagingException - If there are problems closing the store, a MessagingException will be thrown.
      • openFolder

        protected javax.mail.Folder openFolder()
                                        throws javax.mail.MessagingException
        Opens and returns the folder configured for the message store in read/write mode.
        Returns:
        The opened folder configured for the message store.
        Throws:
        javax.mail.MessagingException - If there are problems retrieving or opening the folder, a MessagingException will be thrown.
      • close

        protected void close​(javax.mail.Folder folder)
                      throws javax.mail.MessagingException
        Closes and expunges the designated folder if it is open.
        Parameters:
        folder - The folder to close and expunge.
        Throws:
        javax.mail.MessagingException - If there are problems closing the designated folder, a MessagingException will be thrown.
      • timedOut

        protected boolean timedOut​(Throwable t)
        Gets whether the designated throwable indicates a timeout. Depending on the protocol provider, a timeout can be signalled differently.
        Parameters:
        t - The throwable which to check for whether it indicates a timeout.
        Returns:
        Whether the designated throwable indicates a timeout.