org.apache.james.fetchmail
Class FetchMail

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.fetchmail.FetchMail
All Implemented Interfaces:
org.apache.avalon.cornerstone.services.scheduler.Target, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.service.Serviceable

public class FetchMail
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.cornerstone.services.scheduler.Target, org.apache.avalon.framework.service.Serviceable

Class FetchMail is an Avalon task that is periodically triggered to fetch mail from a JavaMail Message Store.

The lifecycle of an instance of FetchMail is managed by Avalon. The configure(Configuration) method is invoked to parse and validate Configuration properties. The targetTriggered(String) method is invoked to execute the task.

When triggered, a sorted list of Message Store Accounts to be processed is built. Each Message Store Account is processed by delegating to StoreProcessor.

There are two kinds of Message Store Accounts, static and dynamic. Static accounts are expliciltly declared in the Configuration. Dynamic accounts are built each time the task is executed, one per each user defined to James, using the James user name with a configurable prefix and suffix to define the host user identity and recipient identity for each Account. Dynamic accounts allow FetchMail to fetch mail for all James users without modifying the Configuration parameters or restarting the Avalon server.

To fully understand the operations supported by this task, read the Class documention for each Class in the delegation chain starting with this class' delegate, StoreProcessor.

Creation Date: 24-May-03


Constructor Summary
FetchMail()
          Constructor for POP3mail.
 
Method Summary
protected  java.util.Map computeDynamicAccounts()
          Computes the dynamicAccounts.
protected  java.util.Map computeDynamicAccounts(java.util.Map oldAccounts, org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters parameters)
          Compute the dynamicAccounts for the passed parameters.
protected  java.util.List computeParsedDynamicAccountParameters()
          Computes the ParsedDynamicAccountParameters.
protected  javax.mail.Session computeSession()
          Answers a new Session.
protected  java.util.List computeStaticAccounts()
          Computes the staticAccounts.
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
          Method configure parses and validates the Configuration data and creates a new ParsedConfiguration, an Account for each configured static account and a ParsedDynamicAccountParameters for each dynamic account.
protected  org.apache.james.fetchmail.ParsedConfiguration getConfiguration()
          Returns the configuration.
protected  java.util.Map getDynamicAccounts()
          Returns the dynamicAccounts.
protected  UsersRepository getLocalUsers()
          Returns the localUsers.
protected  java.util.List getParsedDynamicAccountParameters()
          Returns the ParsedDynamicAccountParameters.
protected  MailServer getServer()
          Returns the server.
protected  javax.mail.Session getSession()
          Returns the session, lazily initialized if required.
protected  java.util.List getStaticAccounts()
          Returns the accounts.
protected  boolean isFetching()
          Returns the fetching.
protected  void resetDynamicAccounts()
          Resets the dynamicAccounts.
 void service(org.apache.avalon.framework.service.ServiceManager manager)
           
protected  void setConfiguration(org.apache.james.fetchmail.ParsedConfiguration configuration)
          Sets the configuration.
protected  void setDynamicAccounts(java.util.Map dynamicAccounts)
          Sets the dynamicAccounts.
protected  void setFetching(boolean fetching)
          Sets the fetching.
protected  void setLocalUsers(UsersRepository localUsers)
          Sets the localUsers.
protected  void setParsedDynamicAccountParameters(java.util.List parsedDynamicAccountParameters)
          Sets the ParsedDynamicAccountParameters.
protected  void setServer(MailServer server)
          Sets the server.
protected  void setSession(javax.mail.Session session)
          Sets the session.
protected  void setSessionParameters(org.apache.avalon.framework.configuration.Configuration configuration)
          Propogate any Session parameters in the configuration to the Session.
protected  void setStaticAccounts(java.util.List accounts)
          Sets the accounts.
 void targetTriggered(java.lang.String arg0)
          Method target triggered fetches mail for each configured account.
protected  void updateDynamicAccounts()
          Updates the dynamicAccounts.
protected  void updateParsedDynamicAccountParameters()
          Updates the ParsedDynamicAccountParameters.
protected  void updateSession()
          Updates the current Session.
protected  void updateStaticAccounts()
          Updates the staticAccounts.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FetchMail

public FetchMail()
Constructor for POP3mail.

Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Method configure parses and validates the Configuration data and creates a new ParsedConfiguration, an Account for each configured static account and a ParsedDynamicAccountParameters for each dynamic account.

Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

targetTriggered

public void targetTriggered(java.lang.String arg0)
Method target triggered fetches mail for each configured account.

Specified by:
targetTriggered in interface org.apache.avalon.cornerstone.services.scheduler.Target
See Also:
Target.targetTriggered(String)

isFetching

protected boolean isFetching()
Returns the fetching.

Returns:
boolean

service

public void service(org.apache.avalon.framework.service.ServiceManager manager)
             throws org.apache.avalon.framework.service.ServiceException
Specified by:
service in interface org.apache.avalon.framework.service.Serviceable
Throws:
org.apache.avalon.framework.service.ServiceException
See Also:
Serviceable.service(ServiceManager)

setFetching

protected void setFetching(boolean fetching)
Sets the fetching.

Parameters:
fetching - The fetching to set

getServer

protected MailServer getServer()
Returns the server.

Returns:
MailServer

getConfiguration

protected org.apache.james.fetchmail.ParsedConfiguration getConfiguration()
Returns the configuration.

Returns:
ParsedConfiguration

setConfiguration

protected void setConfiguration(org.apache.james.fetchmail.ParsedConfiguration configuration)
Sets the configuration.

Parameters:
configuration - The configuration to set

setServer

protected void setServer(MailServer server)
Sets the server.

Parameters:
server - The server to set

getLocalUsers

protected UsersRepository getLocalUsers()
Returns the localUsers.

Returns:
UsersRepository

setLocalUsers

protected void setLocalUsers(UsersRepository localUsers)
Sets the localUsers.

Parameters:
localUsers - The localUsers to set

getStaticAccounts

protected java.util.List getStaticAccounts()
Returns the accounts. Initializes if required.

Returns:
List

setStaticAccounts

protected void setStaticAccounts(java.util.List accounts)
Sets the accounts.

Parameters:
accounts - The accounts to set

updateStaticAccounts

protected void updateStaticAccounts()
Updates the staticAccounts.


updateParsedDynamicAccountParameters

protected void updateParsedDynamicAccountParameters()
Updates the ParsedDynamicAccountParameters.


updateDynamicAccounts

protected void updateDynamicAccounts()
                              throws org.apache.avalon.framework.configuration.ConfigurationException
Updates the dynamicAccounts.

Throws:
org.apache.avalon.framework.configuration.ConfigurationException

computeStaticAccounts

protected java.util.List computeStaticAccounts()
Computes the staticAccounts.


computeParsedDynamicAccountParameters

protected java.util.List computeParsedDynamicAccountParameters()
Computes the ParsedDynamicAccountParameters.


computeDynamicAccounts

protected java.util.Map computeDynamicAccounts()
                                        throws org.apache.avalon.framework.configuration.ConfigurationException
Computes the dynamicAccounts.

Throws:
org.apache.avalon.framework.configuration.ConfigurationException

getDynamicAccounts

protected java.util.Map getDynamicAccounts()
                                    throws org.apache.avalon.framework.configuration.ConfigurationException
Returns the dynamicAccounts. Initializes if required.

Returns:
Map
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

setDynamicAccounts

protected void setDynamicAccounts(java.util.Map dynamicAccounts)
Sets the dynamicAccounts.

Parameters:
dynamicAccounts - The dynamicAccounts to set

computeDynamicAccounts

protected java.util.Map computeDynamicAccounts(java.util.Map oldAccounts,
                                               org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters parameters)
                                        throws org.apache.avalon.framework.configuration.ConfigurationException
Compute the dynamicAccounts for the passed parameters. Accounts for existing users are copied and accounts for new users are created.

Parameters:
oldAccounts -
parameters -
Returns:
Map - The current Accounts
Throws:
org.apache.avalon.framework.configuration.ConfigurationException

resetDynamicAccounts

protected void resetDynamicAccounts()
Resets the dynamicAccounts.


getParsedDynamicAccountParameters

protected java.util.List getParsedDynamicAccountParameters()
Returns the ParsedDynamicAccountParameters.

Returns:
List

setParsedDynamicAccountParameters

protected void setParsedDynamicAccountParameters(java.util.List parsedDynamicAccountParameters)
Sets the ParsedDynamicAccountParameters.

Parameters:
ParsedDynamicAccountParameters - The ParsedDynamicAccountParametersto set

getSession

protected javax.mail.Session getSession()
Returns the session, lazily initialized if required.

Returns:
Session

computeSession

protected javax.mail.Session computeSession()
Answers a new Session.

Returns:
Session

updateSession

protected void updateSession()
Updates the current Session.


setSession

protected void setSession(javax.mail.Session session)
Sets the session.

Parameters:
session - The session to set

setSessionParameters

protected void setSessionParameters(org.apache.avalon.framework.configuration.Configuration configuration)
                             throws org.apache.avalon.framework.configuration.ConfigurationException
Propogate any Session parameters in the configuration to the Session.

Parameters:
configuration - The configuration containing the parameters
Throws:
org.apache.avalon.framework.configuration.ConfigurationException


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.