1 17 18 package org.apache.james.transport.matchers; 19 20 import org.apache.james.util.RFC2822Headers; 21 import org.apache.mailet.GenericMatcher; 22 import org.apache.mailet.Mail; 23 import org.apache.oro.text.regex.MalformedPatternException; 24 import org.apache.oro.text.regex.Pattern; 25 import org.apache.oro.text.regex.Perl5Compiler; 26 import org.apache.oro.text.regex.Perl5Matcher; 27 28 import javax.mail.MessagingException ; 29 import javax.mail.internet.MimeMessage ; 30 import java.util.Collection ; 31 32 43 44 abstract public class GenericRegexMatcher extends GenericMatcher { 45 protected Object [][] patterns; 46 47 public void compile(Object [][] patterns) throws MalformedPatternException { 48 this.patterns = patterns; 50 for (int i = 0; i < patterns.length; i++) { 51 String pattern = (String )patterns[i][1]; 52 patterns[i][1] = new Perl5Compiler().compile(pattern, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK); 53 } 54 } 55 56 abstract public void init() throws MessagingException ; 57 58 public Collection match(Mail mail) throws MessagingException { 59 MimeMessage message = mail.getMessage(); 60 Perl5Matcher matcher = new Perl5Matcher(); 61 62 if (patterns != null) for (int i = 0; i < patterns.length; i++) { 64 String headerName = (String )patterns[i][0]; 66 Pattern pattern = (Pattern)patterns[i][1]; 68 String headers[] = message.getHeader(headerName); 70 if (headers != null) for (int j = 0; j < headers.length; j++) { 72 if (matcher.matches(headers[j], pattern)) { 73 return mail.getRecipients(); 75 } 76 } 78 } 79 return null; 80 } 81 } 82 | Popular Tags |