Search in sources :

Example 1 with ContactRankings

use of com.zimbra.cs.mailbox.ContactRankings in project zm-mailbox by Zimbra.

the class ContactRankingTest method executeBasic.

@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
    assert (headers != null);
    if (mail instanceof DummyMailAdapter) {
        return true;
    }
    if (!(mail instanceof ZimbraMailAdapter)) {
        return false;
    }
    Mailbox mbox = ((ZimbraMailAdapter) mail).getMailbox();
    List<InternetAddress> addrs = new ArrayList<InternetAddress>();
    for (String header : headers) {
        for (String value : mail.getHeader(header)) {
            addrs.add(new InternetAddress(value));
        }
    }
    try {
        ContactRankings ranking = new ContactRankings(mbox.getAccountId());
        for (InternetAddress addr : addrs) {
            if (ranking.query(addr.getAddress()) > 0) {
                return true;
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.filter.error("Failed to lookup ranking", e);
    }
    return false;
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) ContactRankings(com.zimbra.cs.mailbox.ContactRankings) ArrayList(java.util.ArrayList) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Aggregations

InternetAddress (com.zimbra.common.mime.InternetAddress)1 ServiceException (com.zimbra.common.service.ServiceException)1 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)1 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)1 ContactRankings (com.zimbra.cs.mailbox.ContactRankings)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 ArrayList (java.util.ArrayList)1