1 17 18 package org.apache.james.transport.matchers; 19 20 import org.apache.mailet.GenericRecipientMatcher; 21 import org.apache.mailet.MailAddress; 22 23 import org.apache.oro.text.regex.*; 24 25 import javax.mail.MessagingException ; 26 27 42 43 public class RecipientIsRegex extends GenericRecipientMatcher { 44 Pattern pattern = null; 45 46 public void init() throws javax.mail.MessagingException { 47 String patternString = getCondition(); 48 if (patternString == null) { 49 throw new MessagingException ("Pattern is missing"); 50 } 51 52 patternString = patternString.trim(); 53 Perl5Compiler compiler = new Perl5Compiler(); 54 try { 55 pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK); 56 } catch(MalformedPatternException mpe) { 57 throw new MessagingException ("Malformed pattern: " + patternString, mpe); 58 } 59 } 60 61 public boolean matchRecipient(MailAddress recipient) { 62 String myRecipient = recipient.toString(); 63 Perl5Matcher matcher = new Perl5Matcher(); 64 if (matcher.matches(myRecipient, pattern)){ 65 return true; 66 } else { 67 return false; 68 } 69 } 70 } 71 | Popular Tags |