01: package org.concern.library.mail;
02:
03: import org.concern.controller.AbstractCondition;
04:
05: import javax.mail.MessagingException;
06: import javax.mail.internet.MimeMessage;
07: import java.util.regex.Pattern;
08:
09: public class MatchHeader extends AbstractCondition {
10: Pattern pattern;
11:
12: public boolean eval(Object subject) {
13: return eval((MimeMessage) subject);
14: }
15:
16: public boolean eval(MimeMessage subject) {
17: try {
18: String[] values = subject.getHeader(getHeader());
19: if (values != null) {
20: for (int i = 0; i < values.length; i++) {
21: String value = values[i];
22: if (getPattern().matcher(value).matches()) {
23: return true;
24: }
25:
26: }
27: }
28: return false;
29: } catch (MessagingException e) {
30: e.printStackTrace();
31: return false;
32: }
33: }
34:
35: public String getHeader() {
36: return (String) environment.get("header");
37: }
38:
39: public Pattern getPattern() {
40: if (pattern == null)
41: pattern = Pattern
42: .compile((String) environment.get("match"));
43: return pattern;
44: }
45: }
|