1 17 18 package org.apache.james.transport.mailets; 19 20 import org.apache.mailet.GenericMailet; 21 import org.apache.mailet.Mail; 22 import org.apache.mailet.MailAddress; 23 import org.apache.mailet.MailetContext; 24 25 import javax.mail.MessagingException ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.Vector ; 29 31 38 public class PostmasterAlias extends GenericMailet { 39 40 48 public void service(Mail mail) throws MessagingException { 49 Collection recipients = mail.getRecipients(); 50 Collection recipientsToRemove = null; 51 MailetContext mailetContext = getMailetContext(); 52 boolean postmasterAddressed = false; 53 54 for (Iterator i = recipients.iterator(); i.hasNext(); ) { 55 MailAddress addr = (MailAddress)i.next(); 56 if (addr.getUser().equalsIgnoreCase("postmaster") && 57 mailetContext.isLocalServer(addr.getHost())) { 58 if (recipientsToRemove == null) { 61 recipientsToRemove = new Vector (); 62 } 63 recipientsToRemove.add(addr); 64 postmasterAddressed = true; 66 } 67 } 68 if (postmasterAddressed) { 69 recipients.removeAll(recipientsToRemove); 70 recipients.add(getMailetContext().getPostmaster()); 71 } 72 } 73 74 79 public String getMailetInfo() { 80 return "Postmaster aliasing mailet"; 81 } 82 } 83 | Popular Tags |