Search in sources :

Example 1 with DeleteItemNotification

use of com.zimbra.soap.mail.type.DeleteItemNotification 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 2 with DeleteItemNotification

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

the class PendingModifications method encodeIMAPFolderModifications.

@SuppressWarnings("rawtypes")
public static Map<Integer, PendingFolderModifications> encodeIMAPFolderModifications(PendingModifications accountMods, Set<Integer> folderInterests) throws ServiceException {
    HashMap<Integer, PendingFolderModifications> folderMap = Maps.newHashMap();
    if (accountMods != null && accountMods.created != null) {
        for (Object mod : accountMods.created.values()) {
            if (mod instanceof BaseItemInfo) {
                Integer folderId = ((BaseItemInfo) mod).getFolderIdInMailbox();
                if (folderInterests != null && !folderInterests.contains(folderId)) {
                    continue;
                }
                JaxbUtil.getFolderMods(folderId, folderMap).addCreatedItem(JaxbUtil.getCreatedItemSOAP((BaseItemInfo) mod));
            }
        }
    }
    if (accountMods != null && accountMods.modified != null) {
        // aggregate tag changes so they are sent to each folder we are interested in
        List<ModifyTagNotification> tagMods = new ArrayList<ModifyTagNotification>();
        List<DeleteItemNotification> tagDeletes = new ArrayList<DeleteItemNotification>();
        for (Object maybeTagChange : accountMods.modified.values()) {
            if (maybeTagChange instanceof Change) {
                Object maybeTag = ((Change) maybeTagChange).what;
                if (maybeTag != null && maybeTag instanceof Tag) {
                    Tag tag = (Tag) maybeTag;
                    tagMods.add(new ModifyTagNotification(tag.getIdInMailbox(), tag.getName(), ((Change) maybeTagChange).why));
                }
            }
        }
        if (accountMods != null && accountMods.deleted != null) {
            @SuppressWarnings("unchecked") Map<ModificationKey, Change> deletedMap = accountMods.deleted;
            for (Map.Entry<ModificationKey, Change> entry : deletedMap.entrySet()) {
                ModificationKey key = entry.getKey();
                Change mod = entry.getValue();
                if (mod instanceof Change) {
                    Object what = mod.what;
                    if (what != null && what instanceof MailItem.Type) {
                        if (what == MailItem.Type.TAG) {
                            // aggregate tag deletions so they are sent to each folder we are interested in
                            tagDeletes.add(JaxbUtil.getDeletedItemSOAP(key.getItemId(), what.toString()));
                        } else {
                            Integer folderId;
                            if (what == MailItem.Type.FOLDER) {
                                folderId = key.getItemId();
                            } else {
                                folderId = mod.getFolderId();
                            }
                            if (folderInterests != null && !folderInterests.contains(folderId)) {
                                continue;
                            }
                            JaxbUtil.getFolderMods(folderId, folderMap).addDeletedItem(JaxbUtil.getDeletedItemSOAP(key.getItemId(), what.toString()));
                        }
                    }
                }
            }
        }
        for (Object mod : accountMods.modified.values()) {
            if (mod instanceof Change) {
                Object what = ((Change) mod).what;
                if (what != null && what instanceof BaseItemInfo) {
                    BaseItemInfo itemInfo = (BaseItemInfo) what;
                    Integer folderId = itemInfo.getFolderIdInMailbox();
                    if (itemInfo instanceof Folder) {
                        Integer itemId = itemInfo.getIdInMailbox();
                        if (folderInterests != null && !folderInterests.contains(folderId) && !folderInterests.contains(itemId)) {
                            continue;
                        }
                        if (!tagMods.isEmpty()) {
                            PendingFolderModifications folderMods = JaxbUtil.getFolderMods(itemId, folderMap);
                            for (ModifyTagNotification modTag : tagMods) {
                                folderMods.addModifiedTag(modTag);
                            }
                        } else if (!tagDeletes.isEmpty()) {
                            PendingFolderModifications folderMods = JaxbUtil.getFolderMods(itemId, folderMap);
                            for (DeleteItemNotification tagDelete : tagDeletes) {
                                folderMods.addDeletedItem(tagDelete);
                            }
                        }
                    } else if (!(itemInfo instanceof Tag)) {
                        if (folderInterests != null && !folderInterests.contains(folderId)) {
                            continue;
                        }
                        JaxbUtil.getFolderMods(folderId, folderMap).addModifiedMsg(JaxbUtil.getModifiedItemSOAP(itemInfo, ((Change) mod).why));
                    }
                }
            }
        }
    }
    return folderMap;
}
Also used : BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Type(com.zimbra.cs.mailbox.MailItem.Type) MailItem(com.zimbra.cs.mailbox.MailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) DeleteItemNotification(com.zimbra.soap.mail.type.DeleteItemNotification) Tag(com.zimbra.cs.mailbox.Tag) ModifyTagNotification(com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) PendingFolderModifications(com.zimbra.soap.mail.type.PendingFolderModifications)

Aggregations

BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)2 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)2 MailItem (com.zimbra.cs.mailbox.MailItem)2 Type (com.zimbra.cs.mailbox.MailItem.Type)2 DeleteItemNotification (com.zimbra.soap.mail.type.DeleteItemNotification)2 ModifyTagNotification (com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification)2 ZimbraTag (com.zimbra.common.mailbox.ZimbraTag)1 Folder (com.zimbra.cs.mailbox.Folder)1 Tag (com.zimbra.cs.mailbox.Tag)1 CreateItemNotification (com.zimbra.soap.mail.type.CreateItemNotification)1 ModifyItemNotification (com.zimbra.soap.mail.type.ModifyNotification.ModifyItemNotification)1 RenameFolderNotification (com.zimbra.soap.mail.type.ModifyNotification.RenameFolderNotification)1 PendingFolderModifications (com.zimbra.soap.mail.type.PendingFolderModifications)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1