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

RecipientIsRegex

public class RecipientIsRegex extends org.apache.mailet.GenericRecipientMatcher

Matches recipients whose address matches a regular expression.

Is equivalent to the {@link SenderIsRegex} matcher but matching on the recipient.

Configuration string: a regular expression.


<mailet match="RecipientIsRegex=<regular-expression>" class="<any-class>">

The example below will match any recipient in the format user@log.anything


<mailet match="RecipientIsRegex=(.*)@log\.(.*)" class="<any-class>">
</mailet>
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $

Fields Summary
org.apache.oro.text.regex.Pattern
pattern
Constructors Summary
Methods Summary
public voidinit()


         
        String patternString = getCondition();
        if (patternString == null) {
            throw new MessagingException("Pattern is missing");
        }
        
        patternString = patternString.trim();
        Perl5Compiler compiler = new Perl5Compiler();
        try {
            pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
        } catch(MalformedPatternException mpe) {
            throw new MessagingException("Malformed pattern: " + patternString, mpe);
        }
    
public booleanmatchRecipient(org.apache.mailet.MailAddress recipient)

        String myRecipient = recipient.toString();
        Perl5Matcher matcher  = new Perl5Matcher();
        if (matcher.matches(myRecipient, pattern)){
            return true;
        } else {
            return false;
        }