1 17 18 package org.apache.james.transport.matchers; 19 20 import java.util.Collection ; 21 22 import javax.mail.MessagingException ; 23 24 import org.apache.mailet.GenericMatcher; 25 import org.apache.mailet.Mail; 26 import org.apache.mailet.MatcherConfig; 27 28 64 public class HasMailAttributeWithValue extends GenericMatcher 65 { 66 67 70 private String fieldAttributeName; 71 72 75 private String fieldAttributeValue; 76 77 78 84 public Collection match(Mail mail) throws MessagingException 85 { 86 Object attributeValue = mail.getAttribute(getAttributeName()); 87 88 if (attributeValue != null 89 && attributeValue.toString().trim().equals(getAttributeValue())) 90 return mail.getRecipients(); 91 return null; 92 } 93 94 98 protected String getAttributeName() 99 { 100 return fieldAttributeName; 101 } 102 103 107 protected String getAttributeValue() 108 { 109 return fieldAttributeValue; 110 } 111 112 116 protected void setAttributeName(String attributeName) 117 { 118 fieldAttributeName = attributeName; 119 } 120 121 125 protected void setAttributeValue(String attributeValue) 126 { 127 fieldAttributeValue = attributeValue; 128 } 129 130 133 public void init(MatcherConfig config) throws MessagingException 134 { 135 super.init(config); 136 String condition = config.getCondition().trim(); 137 int commaPosition = condition.indexOf(','); 138 139 if (-1 == commaPosition) 140 throw new MessagingException ("Syntax Error. Missing ','."); 141 142 if (0 == commaPosition) 143 throw new MessagingException ("Syntax Error. Missing attribute name."); 144 145 setAttributeName(condition.substring(0, commaPosition).trim()); 146 setAttributeValue(condition.substring(commaPosition + 1).trim()); 147 } 148 149 154 public String getMatcherInfo() { 155 return "Has Mail Attribute With Value Matcher"; 156 } 157 } 158 | Popular Tags |