1 17 18 package org.apache.james.transport.matchers; 19 20 import org.apache.mailet.GenericMatcher; 21 import org.apache.mailet.Mail; 22 import org.apache.mailet.MailAddress; 23 24 import org.apache.oro.text.regex.*; 25 26 import java.util.Collection ; 27 28 import javax.mail.MessagingException ; 29 30 52 public class SenderIsRegex extends GenericMatcher { 53 Pattern pattern = null; 54 55 public void init() throws MessagingException { 56 String patternString = getCondition(); 57 if (patternString == null) { 58 throw new MessagingException ("Pattern is missing"); 59 } 60 61 patternString = patternString.trim(); 62 Perl5Compiler compiler = new Perl5Compiler(); 63 try { 64 pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK); 65 } catch(MalformedPatternException mpe) { 66 throw new MessagingException ("Malformed pattern: " + patternString, mpe); 67 } 68 } 69 70 public Collection match(Mail mail) { 71 MailAddress mailAddress = mail.getSender(); 72 if (mailAddress == null) { 73 return null; 74 } 75 String senderString = mailAddress.toString(); 76 Perl5Matcher matcher = new Perl5Matcher(); 77 if (matcher.matches(senderString, pattern)) { 78 return mail.getRecipients(); 79 } 80 return null; 81 } 82 } 83 | Popular Tags |