}
while(true) {
try {
String key = spool.accept();
MailImpl mail = spool.retrieve(key);
// Retrieve can return null if the mail is no longer on the spool
// (i.e. another thread has gotten to it first).
// In this case we simply continue to the next key
if (mail == null) {
continue;
}
if (getLogger().isDebugEnabled()) {
StringBuffer debugBuffer =
new StringBuffer(64)
.append("==== Begin processing mail ")
.append(mail.getName())
.append("====");
getLogger().debug(debugBuffer.toString());
}
process(mail);
// Only remove an email from the spool is processing is
// complete, or if it has no recipients
if ((Mail.GHOST.equals(mail.getState())) ||
(mail.getRecipients() == null) ||
(mail.getRecipients().size() == 0)) {
spool.remove(key);
if (getLogger().isDebugEnabled()) {
StringBuffer debugBuffer =
new StringBuffer(64)
.append("==== Removed from spool mail ")
.append(mail.getName())
.append("====");
getLogger().debug(debugBuffer.toString());
}
}
else {