com.openexchange.mail
Class MailProviderRegistry

java.lang.Object
  extended by com.openexchange.mail.MailProviderRegistry

public final class MailProviderRegistry
extends java.lang.Object

MailProviderRegistry

Author:
Thorben Betten

Method Summary
static MailProvider getMailProvider(java.lang.String protocolName)
          Gets the mail provider appropriate for specified protocol.
static MailProvider getMailProviderBySession(com.openexchange.session.Session session, int accountId)
          Gets the mail provider appropriate for specified session.
static MailProvider getMailProviderByURL(java.lang.String serverUrl)
          Gets the mail provider appropriate for specified mail server URL.
static boolean registerMailProvider(java.lang.String protocol, MailProvider provider)
          Registers a mail provider and performs its start-up actions
static void unregisterAll()
          Unregisters all mail providers
static MailProvider unregisterMailProvider(MailProvider provider)
          Unregisters the mail provider
static MailProvider unregisterMailProviderByProtocol(java.lang.String protocol)
          Unregisters the mail provider supporting specified protocol
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getMailProviderBySession

public static MailProvider getMailProviderBySession(com.openexchange.session.Session session,
                                                    int accountId)
                                             throws MailException
Gets the mail provider appropriate for specified session.

Parameters:
session - The session
accountId - The account ID
Returns:
The appropriate mail provider
Throws:
MailException - If no supporting mail provider can be found

getMailProviderByURL

public static MailProvider getMailProviderByURL(java.lang.String serverUrl)
Gets the mail provider appropriate for specified mail server URL.

The given URL should match pattern

 <protocol>://<host>(:<port>)?
 
The protocol should be present. Otherwise the configured fallback is used as protocol.

Parameters:
serverUrl - The mail server URL
Returns:
The appropriate mail provider

getMailProvider

public static MailProvider getMailProvider(java.lang.String protocolName)
Gets the mail provider appropriate for specified protocol.

Parameters:
protocolName - The mail protocol; e.g. "imap"
Returns:
The appropriate mail provider

registerMailProvider

public static boolean registerMailProvider(java.lang.String protocol,
                                           MailProvider provider)
                                    throws MailException
Registers a mail provider and performs its start-up actions

Parameters:
protocol - The mail protocol's string representation; e.g. "imap_imaps"
provider - The mail provider to register
Returns:
true if mail provider has been successfully registered and no other mail provider supports the same protocol; otherwise false
Throws:
MailException - If provider's start-up fails

unregisterAll

public static void unregisterAll()
Unregisters all mail providers


unregisterMailProvider

public static MailProvider unregisterMailProvider(MailProvider provider)
                                           throws MailException
Unregisters the mail provider

Parameters:
provider - The mail provider to unregister
Returns:
The unregistered mail provider, or null
Throws:
MailException - If provider's shut-down fails

unregisterMailProviderByProtocol

public static MailProvider unregisterMailProviderByProtocol(java.lang.String protocol)
                                                     throws MailException
Unregisters the mail provider supporting specified protocol

Parameters:
protocol - The protocol
Returns:
The unregistered instance of MailProvider, or null if there was no provider supporting specified protocol
Throws:
MailException - If provider's shut-down fails