Search in sources :

Example 1 with InternetAddress

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

the class MailboxTest method tombstones.

@Test
public void tombstones() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    mbox.beginTrackingSync();
    int token = mbox.getLastChangeID();
    Document doc1 = DocumentTest.createDocument(mbox, "doc1", "abcdefg", false);
    Document doc2 = DocumentTest.createDocument(mbox, "doc2", "tuvwxyz", false);
    Set<Integer> ids = Sets.newHashSet(doc1.getId(), doc2.getId());
    Set<String> uuids = Sets.newHashSet(doc1.getUuid(), doc2.getUuid());
    Assert.assertEquals("2 different UUIDs", 2, uuids.size());
    mbox.delete(null, ArrayUtil.toIntArray(ids), MailItem.Type.DOCUMENT, null);
    TypedIdList tombstones = mbox.getTombstones(token);
    Assert.assertEquals("2 tombstones", 2, tombstones.size());
    for (Map.Entry<MailItem.Type, List<TypedIdList.ItemInfo>> row : tombstones) {
        Assert.assertEquals("all tombstones are for Documents", MailItem.Type.DOCUMENT, row.getKey());
        for (TypedIdList.ItemInfo iinfo : row.getValue()) {
            Assert.assertTrue(iinfo + ": id contained in set", ids.remove(iinfo.getId()));
            Assert.assertTrue(iinfo + ": uuid contained in set", uuids.remove(iinfo.getUuid()));
        }
    }
    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"));
    List<Contact> contactList = mbox.createAutoContact(null, addrs);
    Assert.assertEquals(3, addrs.size());
    int[] contacts = new int[addrs.size()];
    int i = 0;
    for (Contact c : contactList) {
        contacts[i++] = c.mId;
    }
    mbox.delete(null, contacts, MailItem.Type.CONTACT, null);
    Set<MailItem.Type> types = new HashSet<MailItem.Type>();
    types.add(MailItem.Type.CONTACT);
    List<Integer> contactTombstones = mbox.getTombstones(token, types);
    Assert.assertEquals(addrs.size(), contactTombstones.size());
    types = new HashSet<MailItem.Type>();
    types.add(MailItem.Type.DOCUMENT);
    List<Integer> docTombstones = mbox.getTombstones(token, types);
    Assert.assertEquals(2, docTombstones.size());
    types.add(MailItem.Type.CONTACT);
    Assert.assertEquals(5, mbox.getTombstones(token, types).size());
    token = mbox.getLastChangeID();
    Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), STANDARD_DELIVERY_OPTIONS, null);
    Document doc3 = DocumentTest.createDocument(mbox, "doc3", "lmnop", false);
    Folder folder = mbox.createFolder(null, "test", new Folder.FolderOptions());
    ids = Sets.newHashSet(doc3.getId(), msg.getId(), folder.getId());
    uuids = Sets.newHashSet(doc3.getUuid(), msg.getUuid(), folder.getUuid());
    Assert.assertEquals("3 different UUIDs", 3, uuids.size());
    mbox.move(null, new int[] { doc3.getId(), msg.getId() }, MailItem.Type.UNKNOWN, folder.getId(), null);
    mbox.delete(null, folder.getId(), MailItem.Type.FOLDER, null);
    types = new HashSet<MailItem.Type>();
    types.add(MailItem.Type.MESSAGE);
    Assert.assertEquals(1, mbox.getTombstones(token, types).size());
    types = new HashSet<MailItem.Type>();
    types.add(MailItem.Type.CONTACT);
    Assert.assertEquals(0, mbox.getTombstones(token, types).size());
    tombstones = mbox.getTombstones(token);
    Assert.assertEquals("3 tombstones", 3, tombstones.size());
    for (Map.Entry<MailItem.Type, List<TypedIdList.ItemInfo>> row : tombstones) {
        Assert.assertTrue("expected tombstone types", EnumSet.of(MailItem.Type.FOLDER, MailItem.Type.MESSAGE, MailItem.Type.DOCUMENT).contains(row.getKey()));
        Assert.assertEquals("1 tombstone per type", 1, row.getValue().size());
        for (TypedIdList.ItemInfo iinfo : row.getValue()) {
            Assert.assertTrue(iinfo + ": id contained in set", ids.remove(iinfo.getId()));
            Assert.assertTrue(iinfo + ": uuid contained in set", uuids.remove(iinfo.getUuid()));
        }
    }
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) List(java.util.List) HashSet(java.util.HashSet) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with InternetAddress

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

the class MailboxTest method createAutoContactTestForDisplayNameFormat.

@Test
public void createAutoContactTestForDisplayNameFormat() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Account acct1 = Provisioning.getInstance().get(Key.AccountBy.id, MockProvisioning.DEFAULT_ACCOUNT_ID);
    Collection<InternetAddress> addrs = new ArrayList<InternetAddress>();
    addrs.add(new InternetAddress("\"First Last\" <user@email.com>"));
    List<Contact> contactList = mbox.createAutoContact(null, addrs);
    Contact contact = contactList.get(0);
    assertEquals("First", contact.get("firstName"));
    assertEquals("Last", contact.get("lastName"));
    addrs = new ArrayList<InternetAddress>();
    addrs.add(new InternetAddress("\"Last First\" <user@email.com>"));
    acct1.setPrefLocale("ja");
    ;
    contactList = mbox.createAutoContact(new OperationContext(acct1), addrs);
    contact = contactList.get(0);
    assertEquals("First", contact.get("firstName"));
    assertEquals("Last", contact.get("lastName"));
}
Also used : Account(com.zimbra.cs.account.Account) InternetAddress(com.zimbra.common.mime.InternetAddress) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with InternetAddress

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

the class MilterHandlerTest method testGetToCcAddressHeaderAscii.

@Test
public void testGetToCcAddressHeaderAscii() throws IOException {
    String to = "To" + '\0' + "admin@example.com; admin2@example.com";
    List<String> expctedEmails = new ArrayList<String>();
    expctedEmails.add("admin@example.com");
    expctedEmails.add("admin2@example.com");
    MimeAddressHeader mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
    Assert.assertEquals(2, mh.getAddresses().size());
    for (InternetAddress addrs : mh.getAddresses()) {
        expctedEmails.contains(addrs.getAddress());
    }
    to = "To" + '\0';
    mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
    Assert.assertNull(mh);
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) MimeAddressHeader(com.zimbra.common.mime.MimeAddressHeader) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with InternetAddress

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

the class MilterHandler method SMFIC_BodyEOB.

private void SMFIC_BodyEOB() throws IOException {
    ZimbraLog.milter.debug("SMFIC_BodyEOB");
    Set<String> listAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    Set<String> replyToAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    for (Group group : lists) {
        if (group == null) {
            ZimbraLog.milter.warn("null group in group list!?!");
            continue;
        }
        if (visibleAddresses.contains(group.getMail().toLowerCase())) {
            listAddrs.add(group.getMail());
            if (group.isPrefReplyToEnabled()) {
                String addr = group.getPrefReplyToAddress();
                if (Strings.isNullOrEmpty(addr)) {
                    // fallback to the default email address
                    addr = group.getMail();
                }
                String disp = group.getPrefReplyToDisplay();
                if (Strings.isNullOrEmpty(disp)) {
                    // fallback to the default display name
                    disp = group.getDisplayName();
                }
                replyToAddrs.add(new InternetAddress(disp, addr).toString());
            }
        }
    }
    if (!listAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "X-Zimbra-DL", Joiner.on(", ").join(listAddrs));
    }
    if (!replyToAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "Reply-To", Joiner.on(", ").join(replyToAddrs));
    }
    connection.send(new MilterPacket(SMFIR_ACCEPT));
}
Also used : Group(com.zimbra.cs.account.Group) InternetAddress(com.zimbra.common.mime.InternetAddress)

Example 5 with InternetAddress

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

the class MilterHandler method getAddrListsFromHeaders.

private void getAddrListsFromHeaders(MilterPacket command) {
    MimeAddressHeader mHeader = getToCcAddressHeader(command.getData());
    if (mHeader != null) {
        for (InternetAddress address : mHeader.getAddresses()) {
            if (address.getAddress() != null) {
                visibleAddresses.add(address.getAddress().toLowerCase());
                ZimbraLog.milter.debug("Visible value %s", address.getAddress());
            }
        }
    }
}
Also used : InternetAddress(com.zimbra.common.mime.InternetAddress) MimeAddressHeader(com.zimbra.common.mime.MimeAddressHeader)

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