Method process connects to a Folder in a Message Store, creates a
FolderProcessor
and runs it to process the messages in
the Folder.
Store store = null;
Folder folder = null;
StringBuffer logMessageBuffer =
new StringBuffer("Starting fetching mail from server '");
logMessageBuffer.append(getHost());
logMessageBuffer.append("' for user '");
logMessageBuffer.append(getUser());
logMessageBuffer.append("' in folder '");
logMessageBuffer.append(getJavaMailFolderName());
logMessageBuffer.append("'");
getLogger().info(logMessageBuffer.toString());
try
{
// Get a Store object
store = getSession().getStore(getJavaMailProviderName());
// Connect
if (getHost() != null
|| getUser() != null
|| getPassword() != null)
store.connect(getHost(), getUser(), getPassword());
else
store.connect();
// Get the Folder
folder = store.getFolder(getJavaMailFolderName());
if (folder == null)
getLogger().error(getFetchTaskName() + " No default folder");
// Process the Folder
new FolderProcessor(folder, getAccount()).process();
}
catch (MessagingException ex)
{
getLogger().error(
"A MessagingException has terminated processing of this Folder",
ex);
}
finally
{
try
{
if (null != store && store.isConnected())
store.close();
}
catch (MessagingException ex)
{
getLogger().error(
"A MessagingException occured while closing the Store",
ex);
}
logMessageBuffer =
new StringBuffer("Finished fetching mail from server '");
logMessageBuffer.append(getHost());
logMessageBuffer.append("' for user '");
logMessageBuffer.append(getUser());
logMessageBuffer.append("' in folder '");
logMessageBuffer.append(getJavaMailFolderName());
logMessageBuffer.append("'");
getLogger().info(logMessageBuffer.toString());
}