HasMailAttributeWithValueRegexpublic 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. |
Fields Summary |
---|
private String | attributeName | private org.apache.oro.text.regex.Perl5Matcher | matcher | private org.apache.oro.text.regex.Pattern | pattern |
Methods Summary |
---|
public java.lang.String | getMatcherInfo()Return a string describing this matcher.
return "Has Mail Attribute Value Matcher";
| public void | init(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.Collection | match(org.apache.mailet.Mail mail)
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;
|
|