Make sure that a message that is addressed to a postmaster alias is always
sent to the postmaster address, regardless of delivery to other recipients.
Collection recipients = mail.getRecipients();
Collection recipientsToRemove = null;
MailetContext mailetContext = getMailetContext();
boolean postmasterAddressed = false;
for (Iterator i = recipients.iterator(); i.hasNext(); ) {
MailAddress addr = (MailAddress)i.next();
if (addr.getUser().equalsIgnoreCase("postmaster") &&
mailetContext.isLocalServer(addr.getHost())) {
//Should remove this address... we want to replace it with
// the server's postmaster address
if (recipientsToRemove == null) {
recipientsToRemove = new Vector();
}
recipientsToRemove.add(addr);
//Flag this as having found the postmaster
postmasterAddressed = true;
}
}
if (postmasterAddressed) {
recipients.removeAll(recipientsToRemove);
recipients.add(getMailetContext().getPostmaster());
}