Methods Summary |
---|
protected java.util.Map | computeDynamicAccounts()Computes the dynamicAccounts.
Map newAccounts =
new HashMap(
getLocalUsers().countUsers()
* getParsedDynamicAccountParameters().size());
Map oldAccounts = getDynamicAccountsBasic();
if (null == oldAccounts)
oldAccounts = new HashMap(0);
Iterator parameterIterator =
getParsedDynamicAccountParameters().iterator();
// Process each ParsedDynamicParameters
while (parameterIterator.hasNext())
{
Map accounts =
computeDynamicAccounts(
oldAccounts,
(ParsedDynamicAccountParameters) parameterIterator.next());
// Remove accounts from oldAccounts.
// This avoids an average 2*N increase in heapspace used as the
// newAccounts are created.
Iterator oldAccountsIterator = oldAccounts.keySet().iterator();
while (oldAccountsIterator.hasNext())
{
if (accounts.containsKey(oldAccountsIterator.next()))
oldAccountsIterator.remove();
}
// Add this parameter's accounts to newAccounts
newAccounts.putAll(accounts);
}
return newAccounts;
|
protected java.util.Map | computeDynamicAccounts(java.util.Map oldAccounts, org.apache.james.fetchmail.FetchMail$ParsedDynamicAccountParameters parameters)Compute the dynamicAccounts for the passed parameters.
Accounts for existing users are copied and accounts for new users are
created.
Map accounts = new HashMap(getLocalUsers().countUsers());
Iterator usersIterator = getLocalUsers().list();
while (usersIterator.hasNext())
{
String userName = (String) usersIterator.next();
DynamicAccountKey key =
new DynamicAccountKey(userName, parameters.getSequenceNumber());
Account account = (Account) oldAccounts.get(key);
if (null == account)
{
// Create a new DynamicAccount
account =
new DynamicAccount(
parameters.getSequenceNumber(),
getConfiguration(),
userName,
parameters.getUserPrefix(),
parameters.getUserSuffix(),
parameters.getPassword(),
parameters.getRecipientPrefix(),
parameters.getRecipientSuffix(),
parameters.isIgnoreRecipientHeader(),
parameters.getCustomRecipientHeader(),
getSession());
}
accounts.put(key, account);
}
return accounts;
|
protected java.util.List | computeParsedDynamicAccountParameters()Computes the ParsedDynamicAccountParameters.
return new ArrayList();
|
protected javax.mail.Session | computeSession()Answers a new Session.
return Session.getInstance(System.getProperties());
|
protected java.util.List | computeStaticAccounts()Computes the staticAccounts.
return new ArrayList();
|
public 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.
// Set any Session parameters passed in the Configuration
setSessionParameters(configuration);
// Create the ParsedConfiguration used in the delegation chain
ParsedConfiguration parsedConfiguration =
new ParsedConfiguration(
configuration,
getLogger(),
getServer(),
getLocalUsers());
setConfiguration(parsedConfiguration);
// Setup the Accounts
Configuration[] allAccounts = configuration.getChildren("accounts");
if (allAccounts.length < 1)
throw new ConfigurationException("Missing <accounts> section.");
if (allAccounts.length > 1)
throw new ConfigurationException("Too many <accounts> sections, there must be exactly one");
Configuration accounts = allAccounts[0];
// Create an Account for every configured account
Configuration[] accountsChildren = accounts.getChildren();
if (accountsChildren.length < 1)
throw new ConfigurationException("Missing <account> section.");
for (int i = 0; i < accountsChildren.length; i++)
{
Configuration accountsChild = accountsChildren[i];
if ("alllocal".equals(accountsChild.getName()))
{
// <allLocal> is dynamic, save the parameters for accounts to
// be created when the task is triggered
getParsedDynamicAccountParameters().add(
new ParsedDynamicAccountParameters(i, accountsChild));
continue;
}
if ("account".equals(accountsChild.getName()))
{
// Create an Account for the named user and
// add it to the list of static accounts
getStaticAccounts().add(
new Account(
i,
parsedConfiguration,
accountsChild.getAttribute("user"),
accountsChild.getAttribute("password"),
accountsChild.getAttribute("recipient"),
accountsChild.getAttributeAsBoolean(
"ignorercpt-header"),
accountsChild.getAttribute("customrcpt-header",""),
getSession()));
continue;
}
throw new ConfigurationException(
"Illegal token: <"
+ accountsChild.getName()
+ "> in <accounts>");
}
|
protected ParsedConfiguration | getConfiguration()Returns the configuration.
return fieldConfiguration;
|
protected java.util.Map | getDynamicAccounts()Returns the dynamicAccounts. Initializes if required.
if (null == getDynamicAccountsBasic())
{
updateDynamicAccounts();
return getDynamicAccounts();
}
return fieldDynamicAccounts;
|
private java.util.Map | getDynamicAccountsBasic()Returns the dynamicAccounts.
return fieldDynamicAccounts;
|
protected org.apache.james.services.UsersRepository | getLocalUsers()Returns the localUsers.
return fieldLocalUsers;
|
protected java.util.List | getParsedDynamicAccountParameters()Returns the ParsedDynamicAccountParameters.
if (null == getParsedDynamicAccountParametersBasic())
{
updateParsedDynamicAccountParameters();
return getParsedDynamicAccountParameters();
}
return fieldParsedDynamicAccountParameters;
|
private java.util.List | getParsedDynamicAccountParametersBasic()Returns the ParsedDynamicAccountParameters.
return fieldParsedDynamicAccountParameters;
|
protected org.apache.james.services.MailServer | getServer()Returns the server.
return fieldServer;
|
protected javax.mail.Session | getSession()Returns the session, lazily initialized if required.
Session session = null;
if (null == (session = getSessionBasic()))
{
updateSession();
return getSession();
}
return session;
|
private javax.mail.Session | getSessionBasic()Returns the session.
return fieldSession;
|
protected java.util.List | getStaticAccounts()Returns the accounts. Initializes if required.
if (null == getStaticAccountsBasic())
{
updateStaticAccounts();
return getStaticAccounts();
}
return fieldStaticAccounts;
|
private java.util.List | getStaticAccountsBasic()Returns the staticAccounts.
return fieldStaticAccounts;
|
protected boolean | isFetching()Returns the fetching.
return fieldFetching;
|
protected void | resetDynamicAccounts()Resets the dynamicAccounts.
setDynamicAccounts(null);
|
public void | service(org.apache.avalon.framework.service.ServiceManager manager)
try
{
setServer((MailServer) manager.lookup(MailServer.ROLE));
}
catch (ClassCastException cce)
{
StringBuffer errorBuffer =
new StringBuffer(128).append("Component ").append(
MailServer.ROLE).append(
"does not implement the required interface.");
throw new ServiceException("", errorBuffer.toString());
}
UsersRepository usersRepository =
(UsersRepository) manager.lookup(UsersRepository.ROLE);
setLocalUsers(usersRepository);
|
protected void | setConfiguration(ParsedConfiguration configuration)Sets the configuration.
fieldConfiguration = configuration;
|
protected void | setDynamicAccounts(java.util.Map dynamicAccounts)Sets the dynamicAccounts.
fieldDynamicAccounts = dynamicAccounts;
|
protected void | setFetching(boolean fetching)Sets the fetching.
fieldFetching = fetching;
|
protected void | setLocalUsers(org.apache.james.services.UsersRepository localUsers)Sets the localUsers.
fieldLocalUsers = localUsers;
|
protected void | setParsedDynamicAccountParameters(java.util.List parsedDynamicAccountParameters)Sets the ParsedDynamicAccountParameters.
fieldParsedDynamicAccountParameters = parsedDynamicAccountParameters;
|
protected void | setServer(org.apache.james.services.MailServer server)Sets the server.
fieldServer = server;
|
protected void | setSession(javax.mail.Session session)Sets the session.
fieldSession = session;
|
protected void | setSessionParameters(org.apache.avalon.framework.configuration.Configuration configuration)Propogate any Session parameters in the configuration to the Session.
Configuration javaMailProperties =
configuration.getChild("javaMailProperties", false);
if (null != javaMailProperties)
{
Properties properties = getSession().getProperties();
Configuration[] allProperties =
javaMailProperties.getChildren("property");
for (int i = 0; i < allProperties.length; i++)
{
properties.setProperty(
allProperties[i].getAttribute("name"),
allProperties[i].getAttribute("value"));
if (getLogger().isDebugEnabled())
{
StringBuffer messageBuffer =
new StringBuffer("Set property name: ");
messageBuffer.append(allProperties[i].getAttribute("name"));
messageBuffer.append(" to: ");
messageBuffer.append(
allProperties[i].getAttribute("value"));
getLogger().debug(messageBuffer.toString());
}
}
}
|
protected void | setStaticAccounts(java.util.List accounts)Sets the accounts.
fieldStaticAccounts = accounts;
|
public void | targetTriggered(java.lang.String arg0)Method target triggered fetches mail for each configured account.
// if we are already fetching then just return
if (isFetching())
{
getLogger().info(
"Triggered fetch cancelled. A fetch is already in progress.");
return;
}
// Enter Fetching State
try
{
setFetching(true);
getLogger().info("Fetcher starting fetches");
// if debugging, list the JavaMail property key/value pairs
// for this Session
if (getLogger().isDebugEnabled())
{
getLogger().debug("Session properties:");
Properties properties = getSession().getProperties();
Enumeration e = properties.keys();
while (e.hasMoreElements())
{
String key = (String) e.nextElement();
String val = (String) properties.get(key);
if (val.length() > 40)
{
val = val.substring(0, 37) + "...";
}
getLogger().debug(key + "=" + val);
}
}
// Update the dynamic accounts,
// merge with the static accounts and
// sort the accounts so they are in the order
// they were entered in config.xml
updateDynamicAccounts();
ArrayList mergedAccounts =
new ArrayList(
getDynamicAccounts().size() + getStaticAccounts().size());
mergedAccounts.addAll(getDynamicAccounts().values());
mergedAccounts.addAll(getStaticAccounts());
Collections.sort(mergedAccounts);
StringBuffer logMessage = new StringBuffer(64);
logMessage.append("Processing ");
logMessage.append(getStaticAccounts().size());
logMessage.append(" static accounts and ");
logMessage.append(getDynamicAccounts().size());
logMessage.append(" dynamic accounts.");
getLogger().info(logMessage.toString());
// Fetch each account
Iterator accounts = mergedAccounts.iterator();
while (accounts.hasNext())
{
try
{
new StoreProcessor((Account) accounts.next()).process();
}
catch (MessagingException ex)
{
getLogger().error(
"A MessagingException has terminated processing of this Account",
ex);
}
}
}
catch (Exception ex)
{
getLogger().error("An Exception has terminated this fetch.", ex);
}
finally
{
getLogger().info("Fetcher completed fetches");
// Exit Fetching State
setFetching(false);
}
|
protected void | updateDynamicAccounts()Updates the dynamicAccounts.
setDynamicAccounts(computeDynamicAccounts());
|
protected void | updateParsedDynamicAccountParameters()Updates the ParsedDynamicAccountParameters.
setParsedDynamicAccountParameters(computeParsedDynamicAccountParameters());
|
protected void | updateSession()Updates the current Session.
setSession(computeSession());
|
protected void | updateStaticAccounts()Updates the staticAccounts.
setStaticAccounts(computeStaticAccounts());
|