1 17 18 package org.apache.james.transport.mailets; 19 20 import java.util.Collection ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.StringTokenizer ; 25 26 import javax.mail.MessagingException ; 27 28 import org.apache.mailet.MailAddress; 29 30 56 public class XMLVirtualUserTable extends AbstractVirtualUserTable 57 { 58 61 private Map mappings = new HashMap (); 62 63 66 public void init() throws MessagingException { 67 String mapping = getInitParameter("mapping"); 68 69 if(mapping != null) { 70 StringTokenizer tokenizer = new StringTokenizer (mapping, ","); 71 while(tokenizer.hasMoreTokens()) { 72 String mappingItem = tokenizer.nextToken(); 73 int index = mappingItem.indexOf('='); 74 String virtual = mappingItem.substring(0, index).trim().toLowerCase(); 75 String real = mappingItem.substring(index + 1).trim().toLowerCase(); 76 mappings.put(virtual, real); 77 } 78 } 79 } 80 81 86 protected void mapRecipients(Map recipientsMap) throws MessagingException { 87 Collection recipients = recipientsMap.keySet(); 88 89 for (Iterator i = recipients.iterator(); i.hasNext(); ) { 90 MailAddress source = (MailAddress)i.next(); 91 String user = source.getUser().toLowerCase(); 92 String domain = source.getHost().toLowerCase(); 93 94 String targetString = getTargetString(user, domain); 95 96 if (targetString != null) { 97 recipientsMap.put(source, targetString); 98 } 99 } 100 } 101 102 109 private String getTargetString(String user, String domain) { 110 StringBuffer buf; 111 String target; 112 113 buf = new StringBuffer ().append(user).append("@").append(domain); 115 target = (String )mappings.get(buf.toString()); 116 if (target != null) { 117 return target; 118 } 119 120 buf = new StringBuffer ().append(user).append("@*"); 122 target = (String )mappings.get(buf.toString()); 123 if (target != null) { 124 return target; 125 } 126 127 buf = new StringBuffer ().append("*@").append(domain); 129 target = (String )mappings.get(buf.toString()); 130 if (target != null) { 131 return target; 132 } 133 134 return null; 135 } 136 137 public String getMailetInfo() { 138 return "XML Virtual User Table mailet"; 139 } 140 } 141 | Popular Tags |