Search in sources :

Example 1 with PendingRemoteModifications

use of com.zimbra.cs.session.PendingRemoteModifications 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 PendingRemoteModifications

use of com.zimbra.cs.session.PendingRemoteModifications in project zm-mailbox by Zimbra.

the class ImapServerListener method notifyAccountChange.

public void notifyAccountChange(AccountWithModifications accInfo) {
    ConcurrentHashMap<Integer, Set<ImapRemoteSession>> foldersToSessions = sessionMap.get(accInfo.getId());
    if (foldersToSessions != null && !foldersToSessions.isEmpty()) {
        Collection<PendingFolderModifications> mods = accInfo.getPendingFolderModifications();
        if (mods != null && !mods.isEmpty()) {
            for (PendingFolderModifications folderMods : mods) {
                Integer folderId = folderMods.getFolderId();
                PendingRemoteModifications remoteMods = PendingRemoteModifications.fromSOAP(folderMods, folderId, accInfo.getId());
                Set<ImapRemoteSession> listeners = foldersToSessions.get(folderId);
                if (listeners != null) {
                    for (ImapRemoteSession l : listeners) {
                        l.notifyPendingChanges(remoteMods, accInfo.getLastChangeId(), null);
                    }
                }
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet) Set(java.util.Set) PendingRemoteModifications(com.zimbra.cs.session.PendingRemoteModifications) PendingFolderModifications(com.zimbra.soap.mail.type.PendingFolderModifications)

Aggregations

PendingRemoteModifications (com.zimbra.cs.session.PendingRemoteModifications)2 BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)1 ZimbraTag (com.zimbra.common.mailbox.ZimbraTag)1 ModificationItem (com.zimbra.cs.session.ModificationItem)1 Change (com.zimbra.cs.session.PendingModifications.Change)1 ModificationKey (com.zimbra.cs.session.PendingModifications.ModificationKey)1 ImapMessageInfo (com.zimbra.soap.mail.type.ImapMessageInfo)1 PendingFolderModifications (com.zimbra.soap.mail.type.PendingFolderModifications)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1