Search in sources :

Example 6 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class AddressBookTest method executeBasic.

@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) 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 {
        return mbox.index.existsInContacts(addrs);
    } catch (IOException e) {
        ZimbraLog.filter.error("Failed to lookup contacts", e);
    }
    return false;
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) IOException(java.io.IOException) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 7 with InternetAddress

use of com.zimbra.common.mime.InternetAddress 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)

Example 8 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class MeTest 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)) {
            List<InternetAddress> inetAddrs = InternetAddress.parseHeader(value);
            if (inetAddrs != null) {
                addrs.addAll(inetAddrs);
            }
        }
    }
    try {
        Account account = mbox.getAccount();
        Set<String> me = AccountUtil.getEmailAddresses(account);
        me.addAll(AccountUtil.getImapPop3EmailAddresses(account));
        for (InternetAddress addr : addrs) {
            String email = addr.getAddress();
            if (email != null && me.contains(email.toLowerCase())) {
                return true;
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.filter.error("Failed to lookup my addresses", e);
    }
    return false;
}
Also used : Account(com.zimbra.cs.account.Account) InternetAddress(com.zimbra.common.mime.InternetAddress) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 9 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class ContactTest method existsInContacts.

@Test
public void existsInContacts() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.createContact(null, new ParsedContact(Collections.singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
    MailboxTestUtil.index(mbox);
    Assert.assertTrue(mbox.index.existsInContacts(ImmutableList.of(new InternetAddress("Test <test1@zimbra.com>"), new InternetAddress("Test <test2@zimbra.com>"))));
    Assert.assertFalse(mbox.index.existsInContacts(ImmutableList.of(new InternetAddress("Test <test2@zimbra.com>"), new InternetAddress("Test <test3@zimbra.com>"))));
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ParsedContact(com.zimbra.cs.mime.ParsedContact) Test(org.junit.Test)

Example 10 with InternetAddress

use of com.zimbra.common.mime.InternetAddress in project zm-mailbox by Zimbra.

the class MailboxTest method createAutoContactTestWhenMaxEntriesLimitIsReached.

@Test
public void createAutoContactTestWhenMaxEntriesLimitIsReached() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Collection<InternetAddress> addrs = new ArrayList<InternetAddress>();
    addrs.add(new InternetAddress("user2@email.com"));
    addrs.add(new InternetAddress("user3@email.com"));
    addrs.add(new InternetAddress("user4@email.com"));
    Provisioning prov = Provisioning.getInstance();
    Account acct1 = Provisioning.getInstance().get(Key.AccountBy.id, MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraContactMaxNumEntries, Integer.toString(2));
    prov.modifyAttrs(acct1, attrs);
    List<Contact> contactList = mbox.createAutoContact(null, addrs);
    assertEquals(2, contactList.size());
    attrs.put(Provisioning.A_zimbraContactMaxNumEntries, Integer.toString(10));
    prov.modifyAttrs(acct1, attrs);
    addrs = new ArrayList<InternetAddress>();
    addrs.add(new InternetAddress("user2@email.com"));
    addrs.add(new InternetAddress("user3@email.com"));
    addrs.add(new InternetAddress("user4@email.com"));
    contactList = mbox.createAutoContact(null, addrs);
    assertEquals(3, contactList.size());
}
Also used : Account(com.zimbra.cs.account.Account) InternetAddress(com.zimbra.common.mime.InternetAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) Test(org.junit.Test)

Aggregations

InternetAddress (com.zimbra.common.mime.InternetAddress)16 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)6 ServiceException (com.zimbra.common.service.ServiceException)5 MimeAddressHeader (com.zimbra.common.mime.MimeAddressHeader)3 Account (com.zimbra.cs.account.Account)3 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)3 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Provisioning (com.zimbra.cs.account.Provisioning)2 ParsedAddress (com.zimbra.cs.mime.ParsedAddress)2 ParsedContact (com.zimbra.cs.mime.ParsedContact)2 HashMap (java.util.HashMap)2 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Group (com.zimbra.cs.account.Group)1 MockProvisioning (com.zimbra.cs.account.MockProvisioning)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 BrowseTerm (com.zimbra.cs.index.BrowseTerm)1 TermFieldEnumeration (com.zimbra.cs.index.ZimbraIndexReader.TermFieldEnumeration)1