FileDocCategorySizeDatePackage
HasMailAttributeWithValueRegex.javaAPI DocApache James 2.3.14266Fri Jan 12 12:56:32 GMT 2007org.apache.james.transport.matchers

HasMailAttributeWithValueRegex

public class HasMailAttributeWithValueRegex extends org.apache.mailet.GenericMatcher

This Matcher determines if the mail contains the attribute specified in the condition and that attribute matches the supplied regular expression, it returns all recipients if that is the case.

Sample configuration:


<mailet match="HasMailAttributeWithValueRegex=whatever," class="<any-class>">
Note: as it is not possible to put arbitrary objects in the configuration, toString() is called on the attribute value, and that is the value matched against.
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0

Fields Summary
private String
attributeName
private org.apache.oro.text.regex.Perl5Matcher
matcher
private org.apache.oro.text.regex.Pattern
pattern
Constructors Summary
Methods Summary
public java.lang.StringgetMatcherInfo()
Return a string describing this matcher.

return
a string describing this matcher


                     
       
        return "Has Mail Attribute Value Matcher";
    
public voidinit(org.apache.mailet.MatcherConfig conf)

        String condition = conf.getCondition();
        int idx = condition.indexOf(',");
        if (idx != -1) {
            attributeName = condition.substring(0,idx).trim();
            String pattern_string = condition.substring (idx+1, condition.length()).trim();
            try {
                Perl5Compiler compiler = new Perl5Compiler();
                pattern = compiler.compile(pattern_string);
            } catch(MalformedPatternException mpe) {
                throw new MessagingException("Malformed pattern: " + pattern_string, mpe);
            }
        } else {
            throw new MessagingException ("malformed condition for HasMailAttributeWithValueRegex. must be of the form: attr,regex");
        }
    
public java.util.Collectionmatch(org.apache.mailet.Mail mail)

param
mail the mail to check.
return
all recipients if the part of the condition prior to the first equalsign is the name of an attribute set on the mail and the part of the condition after interpreted as a regular expression matches the toString value of the corresponding attributes value.

        Serializable obj = mail.getAttribute (attributeName);
        //to be a little more generic the toString of the value is what is matched against
        if ( obj != null && matcher.matches(obj.toString(), pattern)) {
            return mail.getRecipients();
        } 
        return null;