Search in sources :

Example 1 with ImapMessageInfo

use of com.zimbra.soap.mail.type.ImapMessageInfo in project zm-mailbox by Zimbra.

the class PendingRemoteNotificationsTest method testPendingRemoteNotifications.

@Test
public void testPendingRemoteNotifications() throws Exception {
    String acctId = "12aa345b-2b47-44e6-8cb8-7fdfa18c1a9f";
    ImapMessageInfo imapMsg1 = new ImapMessageInfo(123, 123, Type.MESSAGE.toString(), 0, null);
    BaseItemInfo msg1 = ModificationItem.itemUpdate(imapMsg1, Mailbox.ID_FOLDER_INBOX, acctId);
    ImapMessageInfo imapMsg2 = new ImapMessageInfo(456, 456, Type.MESSAGE.toString(), 0, null);
    BaseItemInfo msg2 = ModificationItem.itemUpdate(imapMsg2, Mailbox.ID_FOLDER_INBOX, acctId);
    PendingRemoteModifications prm = new PendingRemoteModifications();
    prm.recordCreated(msg1);
    assertTrue(!prm.created.isEmpty());
    BaseItemInfo newItem = prm.created.get(new ModificationKey(msg1));
    assertEquals(imapMsg1.getId(), newItem.getIdInMailbox());
    assertEquals(imapMsg1.getImapUid(), newItem.getImapUid());
    assertEquals(acctId, newItem.getAccountId());
    // rename a tag
    ZimbraTag tag = ModificationItem.tagRename(2, "tagname");
    prm.recordModified(tag, acctId, Change.NAME);
    Change tagChange = prm.modified.get(new ModificationKey(acctId, tag.getTagId()));
    assertNotNull(tagChange);
    assertEquals(Change.NAME, tagChange.why);
    assertEquals(tag, tagChange.what);
    // rename a folder
    ModificationItem folder = ModificationItem.folderRename(3, "/newpath", acctId);
    prm.recordModified(folder, Change.NAME);
    Change folderChange = prm.modified.get(new ModificationKey(folder));
    assertNotNull(folderChange);
    assertEquals(Change.NAME, folderChange.why);
    assertEquals(folder, folderChange.what);
    // modify an item
    BaseItemInfo updateItem = ModificationItem.itemUpdate(imapMsg2, Mailbox.ID_FOLDER_INBOX, acctId);
    prm.recordModified(updateItem, Change.FLAGS);
    Change itemChange = prm.modified.get(new ModificationKey(updateItem));
    assertNotNull(itemChange);
    assertEquals(Change.FLAGS, itemChange.why);
    assertEquals(updateItem, itemChange.what);
    // adding a delete notification for the previously added message
    // should remove it from the created map, and NOT add it to the deleted map
    prm.recordDeleted(Type.MESSAGE, acctId, imapMsg1.getId());
    assertTrue(prm.created.isEmpty());
    assertTrue(prm.deleted == null);
    // adding a delete notification for a previously modified message
    // should remove it from the modified map AND add it to the deleted map
    prm.recordDeleted(Type.MESSAGE, acctId, imapMsg2.getId());
    assertNull(prm.modified.get(new ModificationKey(msg2)));
    assertEquals(1, prm.deleted.size());
    Change deletionChange = prm.deleted.get(new ModificationKey(msg2));
    assertEquals(Change.NONE, deletionChange.why);
    assertEquals(MailItem.Type.MESSAGE, deletionChange.what);
}
Also used : ModificationItem(com.zimbra.cs.session.ModificationItem) BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) PendingRemoteModifications(com.zimbra.cs.session.PendingRemoteModifications) ZimbraTag(com.zimbra.common.mailbox.ZimbraTag) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo) Change(com.zimbra.cs.session.PendingModifications.Change) Test(org.junit.Test)

Example 2 with ImapMessageInfo

use of com.zimbra.soap.mail.type.ImapMessageInfo in project zm-mailbox by Zimbra.

the class JaxbUtil method getCreatedItemSOAP.

public static CreateItemNotification getCreatedItemSOAP(BaseItemInfo mod) throws ServiceException {
    String tags = mod.getTags() == null ? null : Joiner.on(",").join(mod.getTags());
    ImapMessageInfo messageInfo = new ImapMessageInfo(mod.getIdInMailbox(), mod.getImapUid(), mod.getMailItemType().toString(), mod.getFlagBitmask(), tags);
    return new CreateItemNotification(messageInfo);
}
Also used : CreateItemNotification(com.zimbra.soap.mail.type.CreateItemNotification) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo)

Example 3 with ImapMessageInfo

use of com.zimbra.soap.mail.type.ImapMessageInfo in project zm-mailbox by Zimbra.

the class JaxbUtil method getModifiedItemSOAP.

public static ModifyItemNotification getModifiedItemSOAP(BaseItemInfo mod, int reason) throws ServiceException {
    String tags = mod.getTags() == null ? null : Joiner.on(",").join(mod.getTags());
    ImapMessageInfo messageInfo = new ImapMessageInfo(mod.getIdInMailbox(), mod.getImapUid(), mod.getMailItemType().toString(), mod.getFlagBitmask(), tags);
    return new ModifyNotification.ModifyItemNotification(messageInfo, reason);
}
Also used : ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo) ModifyItemNotification(com.zimbra.soap.mail.type.ModifyNotification.ModifyItemNotification)

Example 4 with ImapMessageInfo

use of com.zimbra.soap.mail.type.ImapMessageInfo in project zm-mailbox by Zimbra.

the class RemoteImapMailboxStore method openImapFolder.

@Override
public List<ImapMessage> openImapFolder(OperationContext octxt, ItemIdentifier folderId) throws ServiceException {
    List<ImapMessage> msgs = new ArrayList<ImapMessage>();
    Integer chunkSize = Provisioning.getInstance().getLocalServer().getOpenImapFolderRequestChunkSize();
    for (ImapMessageInfo msg : zMailbox.openImapFolder(folderId, chunkSize)) {
        msgs.add(new ImapMessage(msg));
    }
    return msgs;
}
Also used : ArrayList(java.util.ArrayList) ImapMessageInfo(com.zimbra.soap.mail.type.ImapMessageInfo)

Example 5 with ImapMessageInfo

use of com.zimbra.soap.mail.type.ImapMessageInfo 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)

Aggregations

ImapMessageInfo (com.zimbra.soap.mail.type.ImapMessageInfo)7 OpenIMAPFolderResponse (com.zimbra.soap.mail.message.OpenIMAPFolderResponse)3 ImapMessage (com.zimbra.cs.imap.ImapMessage)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 ImapCursorInfo (com.zimbra.soap.mail.type.ImapCursorInfo)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 OpenIMAPFolderParams (com.zimbra.client.ZMailbox.OpenIMAPFolderParams)1 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)1 ZMessage (com.zimbra.client.ZMessage)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 ZSearchFolder (com.zimbra.client.ZSearchFolder)1 BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)1 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)1 ZimbraTag (com.zimbra.common.mailbox.ZimbraTag)1 Folder (com.zimbra.cs.mailbox.Folder)1 Message (com.zimbra.cs.mailbox.Message)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1