Search in sources :

Example 1 with Folder

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

the class EffectiveACLCache method notifyCommittedChanges.

public void notifyCommittedChanges(PendingModifications mods, int changeId) {
    Set<EffectiveACLCacheKey> keysToInvalidate = new HashSet<EffectiveACLCacheKey>();
    if (mods.modified != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.modified.entrySet()) {
            Change change = entry.getValue();
            Object whatChanged = change.what;
            // permission change or move to a new parent folder.
            if (whatChanged instanceof Folder && (change.why & (Change.ACL | Change.FOLDER)) != 0) {
                Folder folder = (Folder) whatChanged;
                // Invalidate all child folders because their inherited ACL will need to be recomputed.
                String acctId = folder.getMailbox().getAccountId();
                // includes "folder" folder
                List<Folder> subfolders = folder.getSubfolderHierarchy();
                for (Folder subf : subfolders) {
                    EffectiveACLCacheKey key = new EffectiveACLCacheKey(acctId, subf.getId());
                    keysToInvalidate.add(key);
                }
            }
        }
    }
    if (mods.deleted != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
            MailItem.Type type = (MailItem.Type) entry.getValue().what;
            if (type == MailItem.Type.FOLDER) {
                String acctId = entry.getKey().getAccountId();
                if (acctId == null)
                    // just to be safe
                    continue;
                EffectiveACLCacheKey key = new EffectiveACLCacheKey(acctId, entry.getKey().getItemId());
                keysToInvalidate.add(key);
            }
        }
    }
    try {
        mMemcachedLookup.removeMulti(keysToInvalidate);
    } catch (ServiceException e) {
        ZimbraLog.calendar.warn("Unable to notify folder acl cache.  Some cached data may become stale.", e);
    }
}
Also used : ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) Folder(com.zimbra.cs.mailbox.Folder) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) Map(java.util.Map) MemcachedMap(com.zimbra.common.util.memcached.MemcachedMap) HashSet(java.util.HashSet)

Example 2 with Folder

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

the class PendingModifications method deserialize.

@SuppressWarnings("unchecked")
public static PendingModifications deserialize(Mailbox mbox, byte[] data) throws IOException, ClassNotFoundException, ServiceException {
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    ObjectInputStream ois = new ObjectInputStream(bis);
    PendingModifications pms = new PendingModifications();
    pms.changedTypes = (Set<Type>) ois.readObject();
    LinkedHashMap<ModificationKeyMeta, String> metaCreated = (LinkedHashMap<ModificationKeyMeta, String>) ois.readObject();
    if (metaCreated != null) {
        pms.created = new LinkedHashMap<ModificationKey, MailItem>();
        Iterator<Entry<ModificationKeyMeta, String>> iter = metaCreated.entrySet().iterator();
        while (iter.hasNext()) {
            Entry<ModificationKeyMeta, String> entry = iter.next();
            Metadata meta = new Metadata(entry.getValue());
            MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
            ud.deserialize(meta);
            MailItem item = MailItem.constructItem(mbox, ud, true);
            if (item instanceof Folder) {
                Folder folder = ((Folder) item);
                folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
            }
            ModificationKey key = new ModificationKey(entry.getKey().accountId, entry.getKey().itemId);
            pms.created.put(key, item);
        }
    }
    Map<ModificationKeyMeta, ChangeMeta> metaModified = (Map<ModificationKeyMeta, ChangeMeta>) ois.readObject();
    pms.modified = getOriginal(mbox, metaModified);
    Map<ModificationKeyMeta, ChangeMeta> metaDeleted = (Map<ModificationKeyMeta, ChangeMeta>) ois.readObject();
    pms.deleted = getOriginal(mbox, metaDeleted);
    return pms;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) Folder(com.zimbra.cs.mailbox.Folder) LinkedHashMap(java.util.LinkedHashMap) Type(com.zimbra.cs.mailbox.MailItem.Type) MailItem(com.zimbra.cs.mailbox.MailItem) Entry(java.util.Map.Entry) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with Folder

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

the class PendingModifications method getOriginal.

private static Map<ModificationKey, Change> getOriginal(Mailbox mbox, Map<ModificationKeyMeta, ChangeMeta> map) throws ServiceException {
    if (map == null) {
        return null;
    }
    Map<ModificationKey, Change> ret = new LinkedHashMap<ModificationKey, Change>();
    Iterator<Entry<ModificationKeyMeta, ChangeMeta>> iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<ModificationKeyMeta, ChangeMeta> entry = iter.next();
        ModificationKey key = new ModificationKey(entry.getKey().accountId, entry.getKey().itemId);
        ChangeMeta changeMeta = entry.getValue();
        Object what = null;
        Object preModifyObj = null;
        if (changeMeta.whatType == ChangeMeta.ObjectType.MAILITEM) {
            Metadata meta = new Metadata(changeMeta.metaWhat);
            MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
            ud.deserialize(meta);
            what = MailItem.constructItem(mbox, ud, true);
            if (what instanceof Folder) {
                Folder folder = ((Folder) what);
                folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
            }
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILITEMTYPE) {
            what = MailItem.Type.of(changeMeta.metaWhat);
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILBOX) {
            mbox.refreshMailbox(null);
            what = mbox;
        } else {
            ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
            continue;
        }
        if (changeMeta.preModifyObjType == ChangeMeta.ObjectType.MAILITEM) {
            Metadata meta = new Metadata(changeMeta.metaPreModifyObj);
            MailItem.UnderlyingData ud = new MailItem.UnderlyingData();
            ud.deserialize(meta);
            preModifyObj = MailItem.constructItem(mbox, ud, true);
            if (preModifyObj instanceof Folder) {
                Folder folder = ((Folder) preModifyObj);
                folder.setParent(mbox.getFolderById(null, folder.getFolderId()));
            }
        } else if (changeMeta.preModifyObjType == ChangeMeta.ObjectType.MAILITEMTYPE) {
            preModifyObj = MailItem.Type.of(changeMeta.metaPreModifyObj);
        } else if (changeMeta.whatType == ChangeMeta.ObjectType.MAILBOX) {
            what = mbox;
        } else {
            ZimbraLog.session.warn("Unexpected mailbox change type received : " + changeMeta.whatType);
            continue;
        }
        Change change = new Change(what, changeMeta.metaWhy, preModifyObj);
        ret.put(key, change);
    }
    return ret;
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) Folder(com.zimbra.cs.mailbox.Folder) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) MailItem(com.zimbra.cs.mailbox.MailItem)

Example 4 with Folder

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

the class ImapSession method handleModify.

private void handleModify(int changeId, Change chg, AddedItems added) {
    if (chg.what instanceof Tag && (chg.why & Change.NAME) != 0) {
        mFolder.handleTagRename(changeId, (Tag) chg.what, chg);
    } else if (chg.what instanceof Folder && ((Folder) chg.what).getId() == mFolderId) {
        Folder folder = (Folder) chg.what;
        if ((chg.why & Change.FLAGS) != 0 && (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 (chg.what instanceof Message || chg.what instanceof Contact) {
        MailItem item = (MailItem) chg.what;
        boolean inFolder = mIsVirtual || item.getFolderId() == mFolderId;
        if (!inFolder && (chg.why & Change.FOLDER) == 0) {
            return;
        }
        mFolder.handleItemUpdate(changeId, chg, added);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Message(com.zimbra.cs.mailbox.Message) DirtyMessage(com.zimbra.cs.imap.ImapFolder.DirtyMessage) Tag(com.zimbra.cs.mailbox.Tag) Folder(com.zimbra.cs.mailbox.Folder) Contact(com.zimbra.cs.mailbox.Contact)

Example 5 with Folder

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

the class ImapPath method isVisible.

boolean isVisible() throws ServiceException {
    boolean isMailFolders = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
    // check the folder type before hitting a remote server if it's a mountpoint
    if (mFolder instanceof Folder && !isVisible(((Folder) mFolder).getDefaultView(), isMailFolders)) {
        return false;
    }
    if (mCredentials != null) {
        if (mCredentials.isFolderHidden(this)) {
            return false;
        }
    }
    try {
        getFolder();
    } catch (ServiceException e) {
        if (ServiceException.PERM_DENIED.equals(e.getCode())) {
            return false;
        }
        throw e;
    }
    if (mFolder instanceof Folder) {
        Folder folder = (Folder) mFolder;
        if (folder.isHidden()) {
            return false;
        }
    }
    boolean okPath = isValidImapPath();
    if (!okPath) {
        return false;
    }
    return mReferent == this ? true : mReferent.isVisible();
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Folder(com.zimbra.cs.mailbox.Folder)

Aggregations

Folder (com.zimbra.cs.mailbox.Folder)174 Mailbox (com.zimbra.cs.mailbox.Mailbox)86 ServiceException (com.zimbra.common.service.ServiceException)52 Account (com.zimbra.cs.account.Account)47 MailItem (com.zimbra.cs.mailbox.MailItem)43 Test (org.junit.Test)43 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)41 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)38 OperationContext (com.zimbra.cs.mailbox.OperationContext)35 ItemId (com.zimbra.cs.service.util.ItemId)33 Message (com.zimbra.cs.mailbox.Message)31 ZFolder (com.zimbra.client.ZFolder)27 ArrayList (java.util.ArrayList)27 ZMailbox (com.zimbra.client.ZMailbox)26 Element (com.zimbra.common.soap.Element)26 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HashMap (java.util.HashMap)19 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)16 IOException (java.io.IOException)16 HashSet (java.util.HashSet)16