My Account   Contact Us    
  
» HomeProductsSupportDeveloper CommunityCompany

Example Recipient Reject Filter

This example takes an email address from the configuration file, and rejects any messages sent to that address.

/*
 * SimpleRecipientRejectFilter.java
 *
 * Created on December 1, 2004, 4:45 PM
 */

package xms.filter.recipient;

import xms.filter.*;
import xms.configuration.bean.*;
import xms.configuration.bean.attribute.*;
import xms.message.StatusCode;

/**
 *
 * @author  stephen
 */
public class SimpleRecipientRejectFilter implements RecipientFilter, Configurable, Filter {
    
    private String rejectAddress;
    
    public void configure(ConfigurationBean configuration) throws Exception {
        RejectBean cfg = (RejectBean)configuration;
        rejectAddress = cfg.getAddress().getValue().toLowerCase();
    }

    public ConfigurationBean newConfigurationBean() {
        return new RejectBean();        
    }

    public void register(FilterHost filterHost) throws Exception {
        filterHost.registerFilter(this, RecipientFilter.class);
    }

    public void init() throws Exception {  }

    public void destroy() {  }

    public void filterRecipient(FilterContext filterContext, String recipient, java.util.List<String> list) {
        if (recipient.equalsIgnoreCase(rejectAddress)) {
            filterContext.complete(StatusCode.CodeClass.REJECT);
        } else {
            filterContext.complete(StatusCode.CodeClass.CONTINUE);
        }
    }
    
    public static class RejectBean extends FilterConfig {
        StringAttribute address = new StringAttribute("Reject Address", 
			"If the recipient matches this address mail is blocked", 
			null, true, true);
        
        public String getFriendlyName() {
            return "Recipient Reject Filter";
        }
        
        public StringAttribute getAddress() {
            return address;
        }
        
        public String getBeanDescription() {
            return "Rejects mail to a given recipient";
        }
    }
    
    
}
Sign up for our newsletter: | Subscribe with RSS: RSS
© ActivSoftware 1999 to 2005 | Privacy Statement