org.apache.james.fetchmail
Class FetchMail

java.lang.Object
  extended by org.apache.james.fetchmail.FetchMail
All Implemented Interfaces:
Runnable, Configurable, LogEnabled

public class FetchMail
extends Object
implements Runnable, LogEnabled, Configurable

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.


Constructor Summary
FetchMail()
          Constructor for POP3mail.
 
Method Summary
protected  Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> computeDynamicAccounts()
          Computes the dynamicAccounts.
protected  Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> computeDynamicAccounts(Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> oldAccounts, org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters parameters)
          Compute the dynamicAccounts for the passed parameters.
protected  List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> computeParsedDynamicAccountParameters()
          Computes the ParsedDynamicAccountParameters.
protected  javax.mail.Session computeSession()
          Answers a new Session.
protected  List<org.apache.james.fetchmail.Account> computeStaticAccounts()
          Computes the staticAccounts.
 void configure(org.apache.commons.configuration.HierarchicalConfiguration 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  DNSService getDNSService()
          Returns the DNSService.
 DomainList getDomainList()
           
protected  Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> getDynamicAccounts()
          Returns the dynamicAccounts.
protected  UsersRepository getLocalUsers()
          Returns the localUsers.
 MailQueue getMailQueue()
           
protected  List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> getParsedDynamicAccountParameters()
          Returns the ParsedDynamicAccountParameters.
protected  javax.mail.Session getSession()
          Returns the session, lazily initialized if required.
protected  List<org.apache.james.fetchmail.Account> getStaticAccounts()
          Returns the accounts.
protected  boolean isFetching()
          Returns the fetching.
protected  void resetDynamicAccounts()
          Resets the dynamicAccounts.
 void run()
          Method target triggered fetches mail for each configured account.
 void setDNSService(DNSService dns)
           
 void setDomainList(DomainList domainList)
           
protected  void setDynamicAccounts(Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> dynamicAccounts)
          Sets the dynamicAccounts.
protected  void setFetching(boolean fetching)
          Sets the fetching.
 void setLog(org.slf4j.Logger logger)
           
 void setMailQueue(MailQueue queue)
           
protected  void setParsedConfiguration(org.apache.james.fetchmail.ParsedConfiguration configuration)
          Sets the configuration.
protected  void setParsedDynamicAccountParameters(List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> parsedDynamicAccountParameters)
          Sets the ParsedDynamicAccountParameters.
protected  void setSession(javax.mail.Session session)
          Sets the session.
protected  void setSessionParameters(org.apache.commons.configuration.HierarchicalConfiguration configuration)
          Propagate any Session parameters in the configuration to the Session.
protected  void setStaticAccounts(List<org.apache.james.fetchmail.Account> accounts)
          Sets the accounts.
 void setUsersRepository(UsersRepository urepos)
           
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 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.commons.configuration.HierarchicalConfiguration configuration)
               throws org.apache.commons.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 Configurable
Throws:
org.apache.commons.configuration.ConfigurationException
See Also:
Configurable.configure(HierarchicalConfiguration)

run

public void run()
Method target triggered fetches mail for each configured account.

Specified by:
run in interface Runnable

isFetching

protected boolean isFetching()
Returns the fetching.

Returns:
boolean

setFetching

protected void setFetching(boolean fetching)
Sets the fetching.

Parameters:
fetching - The fetching to set

getConfiguration

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

Returns:
ParsedConfiguration

setParsedConfiguration

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

Parameters:
configuration - The configuration to set

getLocalUsers

protected UsersRepository getLocalUsers()
Returns the localUsers.

Returns:
UsersRepository

getDNSService

protected DNSService getDNSService()
Returns the DNSService.

Returns:
DNSService

setDNSService

public void setDNSService(DNSService dns)

setUsersRepository

public void setUsersRepository(UsersRepository urepos)

setLog

public final void setLog(org.slf4j.Logger logger)
Specified by:
setLog in interface LogEnabled

getStaticAccounts

protected List<org.apache.james.fetchmail.Account> getStaticAccounts()
Returns the accounts. Initializes if required.

Returns:
List

setStaticAccounts

protected void setStaticAccounts(List<org.apache.james.fetchmail.Account> 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.commons.configuration.ConfigurationException
Updates the dynamicAccounts.

Throws:
org.apache.commons.configuration.ConfigurationException

computeStaticAccounts

protected List<org.apache.james.fetchmail.Account> computeStaticAccounts()
Computes the staticAccounts.


computeParsedDynamicAccountParameters

protected List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> computeParsedDynamicAccountParameters()
Computes the ParsedDynamicAccountParameters.


computeDynamicAccounts

protected Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> computeDynamicAccounts()
                                                                                                     throws org.apache.commons.configuration.ConfigurationException
Computes the dynamicAccounts.

Throws:
org.apache.commons.configuration.ConfigurationException

getDynamicAccounts

protected Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> getDynamicAccounts()
                                                                                                 throws org.apache.commons.configuration.ConfigurationException
Returns the dynamicAccounts. Initializes if required.

Returns:
Map
Throws:
org.apache.commons.configuration.ConfigurationException

setDynamicAccounts

protected void setDynamicAccounts(Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> dynamicAccounts)
Sets the dynamicAccounts.

Parameters:
dynamicAccounts - The dynamicAccounts to set

computeDynamicAccounts

protected Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> computeDynamicAccounts(Map<org.apache.james.fetchmail.FetchMail.DynamicAccountKey,DynamicAccount> oldAccounts,
                                                                                                            org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters parameters)
                                                                                                     throws org.apache.commons.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.commons.configuration.ConfigurationException

resetDynamicAccounts

protected void resetDynamicAccounts()
Resets the dynamicAccounts.


getParsedDynamicAccountParameters

protected List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> getParsedDynamicAccountParameters()
Returns the ParsedDynamicAccountParameters.

Returns:
List

setParsedDynamicAccountParameters

protected void setParsedDynamicAccountParameters(List<org.apache.james.fetchmail.FetchMail.ParsedDynamicAccountParameters> parsedDynamicAccountParameters)
Sets the ParsedDynamicAccountParameters.

Parameters:
parsedDynamicAccountParameters - The ParsedDynamicAccountParameters to 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.commons.configuration.HierarchicalConfiguration configuration)
                             throws org.apache.commons.configuration.ConfigurationException
Propagate any Session parameters in the configuration to the Session.

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

setMailQueue

public void setMailQueue(MailQueue queue)

getMailQueue

public MailQueue getMailQueue()

setDomainList

public void setDomainList(DomainList domainList)

getDomainList

public DomainList getDomainList()


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