org.apache.james.mailet.standard.matchers
Class HasMailAttributeWithValue

java.lang.Object
  extended by org.apache.mailet.base.GenericMatcher
      extended by org.apache.james.mailet.standard.matchers.HasMailAttributeWithValue
All Implemented Interfaces:
Matcher, MatcherConfig

public class HasMailAttributeWithValue
extends 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.

Sample configuration:


 <mailet match="HasMailAttributeWithValue=name, value" class="<any-class>">
 

Since:
2.2.0
Version:
CVS $Revision$ $Date$

Constructor Summary
HasMailAttributeWithValue()
           
 
Method Summary
protected  String getAttributeName()
          Returns the attributeName.
protected  String getAttributeValue()
          Returns the attributeValue.
 String getMatcherInfo()
          Return a string describing this matcher.
 void init()
          A convenience method which can be overridden so that there's no need to call super.init(config).
 Collection<MailAddress> match(Mail mail)
          Answers the recipients of the mail if the attribute is present, and has a toString() value equal to the configured value.
protected  void setAttributeName(String attributeName)
          Sets the attributeName.
protected  void setAttributeValue(String attributeValue)
          Sets the attributeValue.
 
Methods inherited from class org.apache.mailet.base.GenericMatcher
destroy, getCondition, getMailetContext, getMatcherConfig, getMatcherName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HasMailAttributeWithValue

public HasMailAttributeWithValue()
Method Detail

match

public Collection<MailAddress> match(Mail mail)
                              throws javax.mail.MessagingException

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

Specified by:
match in interface Matcher
Specified by:
match in class GenericMatcher
Parameters:
mail -
Returns:
java.util.Collection - the recipients that the mailet container should have the mailet affect.
Throws:
javax.mail.MessagingException - if any error occurs which prevents the Mail matching from completing successfully

getAttributeName

protected String getAttributeName()
Returns the attributeName.

Returns:
String

getAttributeValue

protected String getAttributeValue()
Returns the attributeValue.

Returns:
String

setAttributeName

protected void setAttributeName(String attributeName)
Sets the attributeName.

Parameters:
attributeName - The attributeName to set

setAttributeValue

protected void setAttributeValue(String attributeValue)
Sets the attributeValue.

Parameters:
attributeValue - The attributeValue to set

init

public void init()
          throws javax.mail.MessagingException
Description copied from class: GenericMatcher

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(MatcherConfig), simply override this method and it will be called by GenericMatcher.init(MatcherConfig config). The MatcherConfig object can still be retrieved via getMatcherConfig().

Overrides:
init in class GenericMatcher
Throws:
javax.mail.MessagingException - if an exception occurs that interrupts the matcher's normal operation

getMatcherInfo

public String getMatcherInfo()
Return a string describing this matcher.

Specified by:
getMatcherInfo in interface Matcher
Overrides:
getMatcherInfo in class GenericMatcher
Returns:
a string describing this matcher


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.