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

HasMailAttributeWithValue

public class HasMailAttributeWithValue extends org.apache.mailet.GenericMatcher

This Matcher determines if the mail contains the attribute specified in the condition and if the value answered when the method toString() is invoked on the attribute is equal to the String value specified in the condition. If both tests are true, all recipients are returned, else null.

Notes:

The current matcher implementation expects a single String value to match on. This matcher requires two values, the attribute name and attribute value. This requires some implicit rules to govern how the single value supplied to the matcher is parsed into two values.

  • In the match condition, the split between the attribute name and the attribute value is made at the first comma. Attribute names that include a comma will parse incorrectly and therefore are not supported by this matcher.
  • Leading and trailing spaces are removed from both the attribute name and attribute value specified in the condition and the tested attribute value in the mail prior to matching. Therefore, "abc" , " abc", "abc " and " abc " are considered equivalent.
  • To test for an empty string, do not specify an attribute value after the comma.

Sample configuration:


<mailet match="HasMailAttributeWithValue=name, value" class="<any-class>">
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0

Fields Summary
private String
fieldAttributeName
The name of the attribute to match
private String
fieldAttributeValue
The value of the attribute to match
Constructors Summary
Methods Summary
protected java.lang.StringgetAttributeName()
Returns the attributeName.

return
String

        return fieldAttributeName;
    
protected java.lang.StringgetAttributeValue()
Returns the attributeValue.

return
String

        return fieldAttributeValue;
    
public java.lang.StringgetMatcherInfo()
Return a string describing this matcher.

return
a string describing this matcher

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

see
org.apache.mailet.Matcher#init(MatcherConfig)

        super.init(config);
        String condition = config.getCondition().trim();
        int commaPosition = condition.indexOf(',");

        if (-1 == commaPosition)
            throw new MessagingException("Syntax Error. Missing ','.");

        if (0 == commaPosition)
            throw new MessagingException("Syntax Error. Missing attribute name.");

        setAttributeName(condition.substring(0, commaPosition).trim());
        setAttributeValue(condition.substring(commaPosition + 1).trim());
    
public java.util.Collectionmatch(org.apache.mailet.Mail mail)

Answers the recipients of the mail if the attribute is present, and has a toString() value equal to the configured value.

see
org.apache.mailet.Matcher#match(Mail)

        Object attributeValue = mail.getAttribute(getAttributeName());

        if (attributeValue != null
            && attributeValue.toString().trim().equals(getAttributeValue()))
            return mail.getRecipients();
        return null;
    
protected voidsetAttributeName(java.lang.String attributeName)
Sets the attributeName.

param
attributeName The attributeName to set

        fieldAttributeName = attributeName;
    
protected voidsetAttributeValue(java.lang.String attributeValue)
Sets the attributeValue.

param
attributeValue The attributeValue to set

        fieldAttributeValue = attributeValue;