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

SenderIsRegex

public class SenderIsRegex extends org.apache.mailet.GenericMatcher

Matches mails that are sent by a sender whose address matches a regular expression.

Is equivalent to the {@link RecipientIsRegex} matcher but matching on the sender.

Configuration string: a regular expression.


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

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


<mailet match="SenderIsRegex=(.*)@log\.(.*)" class="<any-class>">
</mailet>

Another example below will match any sender having some variations of the string mp3 inside the username part.


<mailet match="SenderIsRegex=(.*)(mp3|emmepitre)(.*)@" class="<any-class>">
</mailet>
version
CVS $Revision: 494012 $ $Date: 2007-01-08 11:23:58 +0100 (Mo, 08 Jan 2007) $
since
2.2.0

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 java.util.Collectionmatch(org.apache.mailet.Mail mail)

        MailAddress mailAddress = mail.getSender();
        if (mailAddress == null) {
            return null;
        }
        String senderString = mailAddress.toString();
        Perl5Matcher matcher  = new Perl5Matcher();
        if (matcher.matches(senderString, pattern)) {
            return mail.getRecipients();
        }
        return null;