FileDocCategorySizeDatePackage
XMLVirtualUserTable.javaAPI DocApache James 2.3.15283Fri Jan 12 12:56:30 GMT 2007org.apache.james.transport.mailets

XMLVirtualUserTable

public class XMLVirtualUserTable extends AbstractVirtualUserTable
Implements a Virtual User Table to translate virtual users to real users. This implementation has the same functionality as JDBCVirtualUserTable, but is configured in the JAMES configuration and is thus probably most suitable for smaller and less dynamic mapping requirements. The configuration is specified in the form: <mailet match="All" class="XMLVirtualUserTable"> <mapping>virtualuser@xxx=realuser[@yyy][;anotherrealuser[@zzz]]</mapping> <mapping>virtualuser2@*=realuser2[@yyy][;anotherrealuser2[@zzz]]</mapping> ... </mailet> As many <mapping> elements can be added as necessary. As indicated, wildcards are supported, and multiple recipients can be specified with a semicolon-separated list. The target domain does not need to be specified if the real user is local to the server. Matching is done in the following order: 1. user@domain - explicit mapping for user@domain 2. user@* - catchall mapping for user anywhere 3. *@domain - catchall mapping for anyone at domain 4. null - no valid mapping

Fields Summary
private Map
mappings
Holds the configured mappings
Constructors Summary
Methods Summary
public java.lang.StringgetMailetInfo()

      return "XML Virtual User Table mailet";
  
private java.lang.StringgetTargetString(java.lang.String user, java.lang.String domain)
Returns the real recipient given a virtual username and domain.

param
user the virtual user
param
domain the virtual domain
return
the real recipient address, or null if no mapping exists

      StringBuffer buf;
      String target;
      
      //Look for exact (user@domain) match
      buf = new StringBuffer().append(user).append("@").append(domain);
      target = (String)mappings.get(buf.toString());
      if (target != null) {
          return target;
      }
      
      //Look for user@* match
      buf = new StringBuffer().append(user).append("@*");
      target = (String)mappings.get(buf.toString());
      if (target != null) {
          return target;
      }
      
      //Look for *@domain match
      buf = new StringBuffer().append("*@").append(domain);
      target = (String)mappings.get(buf.toString());
      if (target != null) {
          return target;
      }
      
      return null;
  
public voidinit()
Initialize the mailet


        
       
      String mapping = getInitParameter("mapping");
      
      if(mapping != null) {
          StringTokenizer tokenizer = new StringTokenizer(mapping, ",");
          while(tokenizer.hasMoreTokens()) {
            String mappingItem = tokenizer.nextToken();
            int index = mappingItem.indexOf('=");
            String virtual = mappingItem.substring(0, index).trim().toLowerCase();
            String real = mappingItem.substring(index + 1).trim().toLowerCase();
            mappings.put(virtual, real);
          }
      }
  
protected voidmapRecipients(java.util.Map recipientsMap)
Map any virtual recipients to real recipients using the configured mapping.

param
recipientsMap the mapping of virtual to real recipients

      Collection recipients = recipientsMap.keySet();  
        
      for (Iterator i = recipients.iterator(); i.hasNext(); ) {
          MailAddress source = (MailAddress)i.next();
          String user = source.getUser().toLowerCase();
          String domain = source.getHost().toLowerCase();
    
          String targetString = getTargetString(user, domain);
          
          if (targetString != null) {
              recipientsMap.put(source, targetString);
          }
      }