Search in sources :

Example 1 with Address

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;
}
Also used : Address(org.apache.jsieve.tests.Address) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) MailAdapter(org.apache.jsieve.mail.MailAdapter)

Aggregations

DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)1 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 MailAdapter (org.apache.jsieve.mail.MailAdapter)1 Address (org.apache.jsieve.tests.Address)1