Search in sources :

Example 6 with ItemIdentifier

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

the class TestZClient method testZMailboxGetContact.

@Test
public void testZMailboxGetContact() throws ServiceException {
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    Contact contact = TestUtil.createContactInDefaultFolder(mbox, "testzclient2@example.com");
    ItemIdentifier contactId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), contact.getId());
    ZContact zcontact = zmbox.getContact(contactId);
    assertNotNull("ZContact object", zcontact);
    assertEquals("Expected=ZContact ID Actual=ZContact IMAP UID", zcontact.getIdInMailbox(), zcontact.getImapUid());
    assertEquals("IMAP UID Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
    assertEquals("ModifiedSequence Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZContact(com.zimbra.client.ZContact) Contact(com.zimbra.cs.mailbox.Contact) ZContact(com.zimbra.client.ZContact) Test(org.junit.Test)

Example 7 with ItemIdentifier

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

the class TestZClient method testOpenImapFolder.

@Test
public void testOpenImapFolder() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    Folder folder = mbox.createFolder(null, "TestOpenImapFolder", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    ItemIdentifier folderId = folder.getFolderItemIdentifier();
    List<ImapMessage> expected = new LinkedList<ImapMessage>();
    for (int i = 1; i <= 10; i++) {
        Message msg = TestUtil.addMessage(mbox, folderId.id, String.format("imap message %s", i), System.currentTimeMillis());
        expected.add(new ImapMessage(msg));
    }
    // test pagination
    OpenIMAPFolderParams params = new OpenIMAPFolderParams(folderId);
    // test fetching all results
    params.setLimit(100);
    OpenIMAPFolderResponse result = zmbox.fetchImapFolderChunk(params);
    assertEquals(10, result.getImapMessageInfo().size());
    assertFalse(result.getHasMore());
    // test fetching first 5
    params.setLimit(5);
    result = zmbox.fetchImapFolderChunk(params);
    List<ImapMessageInfo> messages = result.getImapMessageInfo();
    assertEquals(5, messages.size());
    for (int i = 0; i < messages.size(); i++) {
        assertEquals(messages.get(i).getId(), expected.get(i).getMsgId());
    }
    assertTrue(result.getHasMore());
    // test fetching 5 items starting at 3rd item, (more results left)
    Integer cursorId = expected.get(2).getMsgId();
    params.setCursorId(String.valueOf(cursorId));
    result = zmbox.fetchImapFolderChunk(params);
    messages = result.getImapMessageInfo();
    assertEquals(5, messages.size());
    for (int i = 0; i < messages.size(); i++) {
        assertEquals(messages.get(i).getId(), expected.get(i + 3).getMsgId());
    }
    assertTrue(result.getHasMore());
    // test fetching 5 items starting at 7th item, exhausting all results
    cursorId = expected.get(6).getMsgId();
    params.setCursorId(String.valueOf(cursorId));
    result = zmbox.fetchImapFolderChunk(params);
    messages = result.getImapMessageInfo();
    assertEquals(3, messages.size());
    for (int i = 0; i < messages.size(); i++) {
        assertEquals(messages.get(i).getId(), expected.get(i + 7).getMsgId());
    }
    assertFalse(result.getHasMore());
    // test getting all messages in batches of 3, so pagination is used
    List<ImapMessageInfo> actual = zmbox.openImapFolder(folderId, 3);
    Collections.sort(expected);
    Collections.sort(actual);
    assertEquals("expected and actual lists have different lengths", expected.size(), actual.size());
    for (int i = 0; i < expected.size(); i++) {
        assertEquals(expected.get(i).getImapUid(), actual.get(i).getImapUid());
    }
}
Also used : OpenIMAPFolderResponse(com.zimbra.soap.mail.message.OpenIMAPFolderResponse) ImapMessage(com.zimbra.cs.imap.ImapMessage) ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Message(com.zimbra.cs.mailbox.Message) ImapMessage(com.zimbra.cs.imap.ImapMessage) Folder(com.zimbra.cs.mailbox.Folder) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) LinkedList(java.util.LinkedList) ZMountpoint(com.zimbra.client.ZMountpoint) OpenIMAPFolderParams(com.zimbra.client.ZMailbox.OpenIMAPFolderParams) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo) Test(org.junit.Test)

Example 8 with ItemIdentifier

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

the class TestZClient method testAlterTag.

@Test
public void testAlterTag() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    Message msg = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "testAlterTag message", System.currentTimeMillis());
    int msgId = msg.getId();
    String tagName = "testAlterTag tag";
    zmbox.createTag(tagName, ZTag.Color.blue);
    Collection<ItemIdentifier> ids = new ArrayList<ItemIdentifier>(1);
    ids.add(new ItemIdentifier(mbox.getAccountId(), msgId));
    // add tag via zmailbox
    zmbox.alterTag(null, ids, tagName, true);
    assertTrue("Message should be tagged", waitForTag(msgId, mbox, tagName, true, 3000));
    assertTrue(msg.isTagged(tagName));
    // remove tag via zmailbox
    zmbox.alterTag(null, ids, tagName, false);
    assertTrue("Message should NOT be tagged", waitForTag(msgId, mbox, tagName, false, 3000));
    msg = mbox.getMessageById(null, msgId);
    assertFalse(tagName + " should be removed", msg.isTagged(tagName));
    // test setting/unsetting unread flag
    zmbox.alterTag(null, ids, "\\Unread", true);
    assertTrue("Message.isUnread should return TRUE", waitForFlag(msgId, mbox, "isUnread", true, 3000));
    msg = mbox.getMessageById(null, msgId);
    assertTrue("Message should be unread", msg.isUnread());
    zmbox.alterTag(null, ids, "\\Unread", false);
    assertTrue("Message.isUnread should return FALSE", waitForFlag(msgId, mbox, "isUnread", false, 3000));
    msg = mbox.getMessageById(null, msgId);
    assertFalse("Message should be read", msg.isUnread());
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ImapMessage(com.zimbra.cs.imap.ImapMessage) ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList) ZMountpoint(com.zimbra.client.ZMountpoint) Test(org.junit.Test)

Example 9 with ItemIdentifier

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

the class Mailbox method copyItemAction.

/**
 * Copies the items identified in {@link idlist} to folder {@link targetFolder}
 * @param idlist - list of item ids for items to copy
 * @param targetFolder - Destination folder
 * @return The item IDs of the created items - these may be full item IDs in the case of remote folders
 */
@Override
public List<String> copyItemAction(OpContext ctxt, ItemIdentifier targetFolder, List<ItemIdentifier> idlist) throws ServiceException {
    if ((idlist == null) || idlist.isEmpty()) {
        return Collections.emptyList();
    }
    List<Integer> ids = Lists.newArrayListWithExpectedSize(idlist.size());
    for (ItemIdentifier ident : idlist) {
        if (this.referencesOtherMailbox(ident)) {
            // requests are proxied to the selected folder's owner.
            throw ServiceException.FAILURE("Unexpected attempt to copy item from mountpoint", null);
        }
        ids.add(ident.id);
    }
    ItemActionHelper op = ItemActionHelper.COPY((OperationContext) ctxt, this, null, ids, MailItem.Type.UNKNOWN, null, new ItemId(targetFolder));
    CopyActionResult caResult = (CopyActionResult) op.getResult();
    return caResult.getCreatedIds();
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ItemActionHelper(com.zimbra.cs.service.mail.ItemActionHelper) CopyActionResult(com.zimbra.cs.service.mail.CopyActionResult) ItemId(com.zimbra.cs.service.util.ItemId)

Example 10 with ItemIdentifier

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

the class RecordIMAPSession method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    com.zimbra.soap.mail.message.RecordIMAPSessionRequest req = zsc.elementToJaxb(request);
    String folderId = req.getFolderId();
    Mailbox mbox = getRequestedMailbox(zsc);
    ItemIdentifier folderIdent = ItemIdentifier.fromEncodedAndDefaultAcctId(folderId, mbox.getAccountId());
    mbox.recordImapSession(folderIdent.id);
    int lastItemId = mbox.getLastItemId();
    Folder folder = mbox.getFolderById(null, folderIdent.id);
    RecordIMAPSessionResponse resp = new RecordIMAPSessionResponse(lastItemId, folder.getUuid());
    return zsc.jaxbToElement(resp);
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Folder(com.zimbra.cs.mailbox.Folder) RecordIMAPSessionResponse(com.zimbra.soap.mail.message.RecordIMAPSessionResponse)

Aggregations

ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)26 ZMailbox (com.zimbra.client.ZMailbox)12 Mailbox (com.zimbra.cs.mailbox.Mailbox)12 Test (org.junit.Test)11 ZMessage (com.zimbra.client.ZMessage)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)6 ArrayList (java.util.ArrayList)6 ZMountpoint (com.zimbra.client.ZMountpoint)5 MailboxStore (com.zimbra.common.mailbox.MailboxStore)5 ImapMessage (com.zimbra.cs.imap.ImapMessage)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Message (com.zimbra.cs.mailbox.Message)5 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)4 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)4 Folder (com.zimbra.cs.mailbox.Folder)4 ZContact (com.zimbra.client.ZContact)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Contact (com.zimbra.cs.mailbox.Contact)3 OperationContext (com.zimbra.cs.mailbox.OperationContext)3