Search in sources :

Example 1 with ZimbraTag

use of com.zimbra.common.mailbox.ZimbraTag 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 ZimbraTag

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

the class PendingRemoteModifications method fromSOAP.

public static PendingRemoteModifications fromSOAP(PendingFolderModifications mods, Integer folderId, String acctId) {
    PendingRemoteModifications prms = new PendingRemoteModifications();
    for (CreateItemNotification createSpec : mods.getCreated()) {
        prms.recordCreated(ModificationItem.itemUpdate(createSpec.getMessageInfo(), folderId, acctId));
    }
    for (ModifyItemNotification modifyItem : mods.getModifiedMsgs()) {
        int change = modifyItem.getChangeBitmask();
        BaseItemInfo itemUpdate = ModificationItem.itemUpdate(modifyItem.getMessageInfo(), folderId, acctId);
        prms.recordModified(itemUpdate, change);
    }
    for (ModifyTagNotification modifyTag : mods.getModifiedTags()) {
        int change = modifyTag.getChangeBitmask();
        int tagId = modifyTag.getId();
        String tagName = modifyTag.getName();
        ZimbraTag tagRename = ModificationItem.tagRename(tagId, tagName);
        prms.recordModified(tagRename, acctId, change);
    }
    for (RenameFolderNotification renamedFolder : mods.getRenamedFolders()) {
        int change = renamedFolder.getChangeBitmask();
        int renamedFolderId = renamedFolder.getFolderId();
        String newPath = renamedFolder.getPath();
        ModificationItem folderRename = ModificationItem.folderRename(renamedFolderId, newPath, acctId);
        prms.recordModified(folderRename, change);
    }
    for (DeleteItemNotification delSpec : mods.getDeleted()) {
        int id = delSpec.getId();
        MailItem.Type type = MailItem.Type.of(delSpec.getType());
        prms.recordDeleted(type, acctId, id);
    }
    return prms;
}
Also used : CreateItemNotification(com.zimbra.soap.mail.type.CreateItemNotification) BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) ZimbraTag(com.zimbra.common.mailbox.ZimbraTag) Type(com.zimbra.cs.mailbox.MailItem.Type) RenameFolderNotification(com.zimbra.soap.mail.type.ModifyNotification.RenameFolderNotification) MailItem(com.zimbra.cs.mailbox.MailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) DeleteItemNotification(com.zimbra.soap.mail.type.DeleteItemNotification) ModifyItemNotification(com.zimbra.soap.mail.type.ModifyNotification.ModifyItemNotification) ModifyTagNotification(com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification)

Example 3 with ZimbraTag

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

the class ImapListener method handleModify.

protected void handleModify(int changeId, Change chg, AddedItems added) {
    if (chg.what instanceof ZimbraTag && (chg.why & Change.NAME) != 0) {
        mFolder.handleTagRename(changeId, (ZimbraTag) chg.what, chg);
    } else {
        boolean isFolder = (chg.what instanceof BaseItemInfo && ((BaseItemInfo) chg.what).getMailItemType() == MailItemType.FOLDER);
        boolean isMsgOrContact = false;
        BaseItemInfo item = null;
        if (chg.what instanceof BaseItemInfo) {
            item = (BaseItemInfo) chg.what;
            isMsgOrContact = (item.getMailItemType() == MailItemType.MESSAGE || item.getMailItemType() == MailItemType.CONTACT);
        }
        try {
            if (isFolder && ((BaseFolderInfo) chg.what).getFolderIdInOwnerMailbox() == folderId.id) {
                FolderStore folder = (FolderStore) chg.what;
                // here we assume that the FolderStore object also implements BaseItemInfo
                if ((chg.why & Change.FLAGS) != 0 && (((BaseItemInfo) folder).getFlagBitmask() & Flag.BITMASK_DELETED) != 0) {
                    // mailbox accessed by sending a untagged BYE response."
                    if (handler != null) {
                        handler.close();
                    }
                } else if ((chg.why & (Change.FOLDER | Change.NAME)) != 0) {
                    mFolder.handleFolderRename(changeId, folder, chg);
                }
            } else if (isMsgOrContact) {
                boolean inFolder = mIsVirtual || item.getFolderIdInMailbox() == folderId.id;
                if (!inFolder && (chg.why & Change.FOLDER) == 0) {
                    return;
                }
                mFolder.handleItemUpdate(changeId, chg, added);
            }
        } catch (ServiceException e) {
            ZimbraLog.imap.warn("error handling modified items for changeId %s", changeId, e);
            return;
        }
    }
}
Also used : BaseFolderInfo(com.zimbra.common.mailbox.BaseFolderInfo) BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) ServiceException(com.zimbra.common.service.ServiceException) ZimbraTag(com.zimbra.common.mailbox.ZimbraTag) FolderStore(com.zimbra.common.mailbox.FolderStore)

Aggregations

BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)3 ZimbraTag (com.zimbra.common.mailbox.ZimbraTag)3 BaseFolderInfo (com.zimbra.common.mailbox.BaseFolderInfo)1 FolderStore (com.zimbra.common.mailbox.FolderStore)1 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)1 ServiceException (com.zimbra.common.service.ServiceException)1 MailItem (com.zimbra.cs.mailbox.MailItem)1 Type (com.zimbra.cs.mailbox.MailItem.Type)1 ModificationItem (com.zimbra.cs.session.ModificationItem)1 Change (com.zimbra.cs.session.PendingModifications.Change)1 ModificationKey (com.zimbra.cs.session.PendingModifications.ModificationKey)1 PendingRemoteModifications (com.zimbra.cs.session.PendingRemoteModifications)1 CreateItemNotification (com.zimbra.soap.mail.type.CreateItemNotification)1 DeleteItemNotification (com.zimbra.soap.mail.type.DeleteItemNotification)1 ImapMessageInfo (com.zimbra.soap.mail.type.ImapMessageInfo)1 ModifyItemNotification (com.zimbra.soap.mail.type.ModifyNotification.ModifyItemNotification)1 ModifyTagNotification (com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification)1 RenameFolderNotification (com.zimbra.soap.mail.type.ModifyNotification.RenameFolderNotification)1 Test (org.junit.Test)1