use of org.apache.jsieve.tests.Address in project zm-mailbox by Zimbra.
the class AddressTest method match.
/**
* Compares the address with operator
*/
private boolean match(MailAdapter mail, String addressPart, String comparator, String matchType, String operator, List<String> headerNames, List<String> keys, SieveContext context) throws SieveException {
// Iterate over the address fields looking for a match
boolean isMatched = false;
Iterator headerNamesIter = headerNames.iterator();
List<String> headerValues = new ArrayList<String>();
while (headerNamesIter.hasNext()) {
final MailAdapter.Address[] addresses = mail.parseAddresses((String) headerNamesIter.next());
final int length = addresses.length;
int i = 0;
while (i < length) {
MailAdapter.Address address = addresses[i++];
final String localPart = address.getLocalPart();
final String domain = address.getDomain();
headerValues.add(getMatchAddress(addressPart, localPart, domain));
}
}
if (COUNT_TAG.equals(matchType)) {
for (final String key : keys) {
isMatched = ZimbraComparatorUtils.counts(comparator, operator, headerValues, ZimbraComparatorUtils.getMatchKey(addressPart, key), context);
if (isMatched) {
break;
}
}
} else {
Iterator headerValuesIter = headerValues.iterator();
while (!isMatched && headerValuesIter.hasNext()) {
isMatched = match(comparator, matchType, operator, (String) headerValuesIter.next(), keys, context);
}
}
return isMatched;
}
Aggregations