FromRepositorypublic class FromRepository extends org.apache.mailet.GenericMailet Re-spools Mail found in the specified Repository.
<mailet match="RecipientIs=respool@localhost" class="FromRepository">
<repositoryPath> repository path </repositoryPath>
<processor> target processor </repositoryPath>
<delete&t; [true|false] </delete>
</mailet> |
Fields Summary |
---|
private org.apache.james.services.MailRepository | repositoryThe repository from where this mailet spools mail. | private boolean | deleteWhether this mailet should delete messages after being spooled | private String | repositoryPathThe path to the repository | private String | processorThe processor that will handle the re-spooled message(s) |
Methods Summary |
---|
public java.lang.String | getMailetInfo()Return a string describing this mailet.
return "FromRepository Mailet";
| public void | init()Initialize the mailet, loading configuration information.
repositoryPath = getInitParameter("repositoryPath");
processor = (getInitParameter("processor") == null) ? Mail.DEFAULT : getInitParameter("processor");
try {
delete = (getInitParameter("delete") == null) ? false : new Boolean(getInitParameter("delete")).booleanValue();
} catch (Exception e) {
// Ignore exception, default to false
}
ServiceManager compMgr = (ServiceManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
try {
Store mailstore = (Store) compMgr.lookup(Store.ROLE);
DefaultConfiguration mailConf
= new DefaultConfiguration("repository", "generated:ToRepository");
mailConf.setAttribute("destinationURL", repositoryPath);
mailConf.setAttribute("type", "MAIL");
repository = (MailRepository) mailstore.select(mailConf);
} catch (ServiceException cnfe) {
log("Failed to retrieve Store component:" + cnfe.getMessage());
} catch (Exception e) {
log("Failed to retrieve Store component:" + e.getMessage());
}
| public void | service(org.apache.mailet.Mail trigger)Spool mail from a particular repository.
trigger.setState(Mail.GHOST);
java.util.Collection processed = new java.util.ArrayList();
Iterator list = repository.list();
while (list.hasNext()) {
String key = (String) list.next();
try {
Mail mail = repository.retrieve(key);
if (mail != null && mail.getRecipients() != null) {
log((new StringBuffer(160).append("Spooling mail ").append(mail.getName()).append(" from ").append(repositoryPath)).toString());
/*
log("Return-Path: " + mail.getMessage().getHeader(RFC2822Headers.RETURN_PATH, ", "));
log("Sender: " + mail.getSender());
log("To: " + mail.getMessage().getHeader(RFC2822Headers.TO, ", "));
log("Recipients: ");
for (Iterator i = mail.getRecipients().iterator(); i.hasNext(); ) {
log(" " + ((MailAddress)i.next()).toString());
};
*/
mail.setAttribute("FromRepository", Boolean.TRUE);
mail.setState(processor);
getMailetContext().sendMail(mail);
if (delete) processed.add(key);
}
} catch (MessagingException e) {
log((new StringBuffer(160).append("Unable to re-spool mail ").append(key).append(" from ").append(repositoryPath)).toString(), e);
}
}
if (delete) {
Iterator delList = processed.iterator();
while (delList.hasNext()) {
repository.remove((String)delList.next());
}
}
|
|