Search in sources :

Example 1 with ExistingParentFolderStoreAndUnmatchedPart

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

the class Mailbox method getParentFolderStoreAndUnmatchedPart.

/**
 * Given a path, resolves as much of the path as possible and returns the folder and the unmatched part.
 *
 * For path e.g. "/foo/bar/baz/gub" where a mailbox has a Folder at "/foo/bar" but NOT one at "/foo/bar/baz"
 * this class can encapsulate this information where:
 *     parentFolderStore is the folder at path "/foo/bar"
 *     unmatchedPart = "baz/gub".
 *
 * If the returned folder is a mountpoint, then perhaps the remaining part is a subfolder in the remote mailbox.
 */
@Override
public ExistingParentFolderStoreAndUnmatchedPart getParentFolderStoreAndUnmatchedPart(OpContext octxt, String path) throws ServiceException {
    int baseFolderId = Mailbox.ID_FOLDER_USER_ROOT;
    Pair<Folder, String> pair = getFolderByPathLongestMatch((OperationContext) octxt, baseFolderId, path);
    return new ExistingParentFolderStoreAndUnmatchedPart(pair.getFirst(), pair.getSecond());
}
Also used : ExistingParentFolderStoreAndUnmatchedPart(com.zimbra.common.mailbox.ExistingParentFolderStoreAndUnmatchedPart) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Example 2 with ExistingParentFolderStoreAndUnmatchedPart

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

the class ImapPath method getReferent.

/**
 * @return If the folder is a mountpoint (i.e. an accepted share), may return an ImapPath representing
 *         that, otherwise, the value is this.
 */
@VisibleForTesting
public ImapPath getReferent() throws ServiceException {
    if (mReferent != null) {
        return mReferent;
    }
    // while calculating, use the base
    mReferent = this;
    // only follow the authenticated user's own mountpoints
    if (mScope == Scope.REFERENCE || mScope == Scope.UNPARSED || !belongsTo(mCredentials)) {
        return mReferent;
    }
    ImapMailboxStore ownerImapMailboxStore = getOwnerImapMailboxStore();
    if (null == ownerImapMailboxStore) {
        return mReferent;
    }
    ItemId iidRemote;
    String subpathRemote = null;
    if (folder == null) {
        try {
            ExistingParentFolderStoreAndUnmatchedPart info = ownerImapMailboxStore.getMailboxStore().getParentFolderStoreAndUnmatchedPart(getContext(), asZimbraPath());
            subpathRemote = info.unmatchedPart;
            if (info.parentFolderStore instanceof MountpointStore || Strings.isNullOrEmpty(subpathRemote)) {
                folder = info.parentFolderStore;
                mItemId = new ItemId(ItemIdentifier.fromOwnerAndFolder(accountIdFromCredentials(), folder));
            }
            if (!(info.parentFolderStore instanceof MountpointStore)) {
                return mReferent;
            }
        } catch (ServiceException e) {
            return mReferent;
        }
    }
    if (!(folder instanceof MountpointStore)) {
        return mReferent;
    }
    // somewhere along the specified path is a visible mountpoint owned by the user
    iidRemote = new ItemId(((MountpointStore) folder).getTargetItemIdentifier());
    // don't allow mountpoints that point at the same mailbox (as it can cause infinite loops)
    if (belongsTo(iidRemote.getAccountId())) {
        return mReferent;
    }
    Account target = Provisioning.getInstance().get(AccountBy.id, iidRemote.getAccountId());
    if (target == null) {
        return mReferent;
    }
    ImapMailboxStore imapMailboxStore = setupMailboxStoreForTarget(target, iidRemote);
    if (null == imapMailboxStore) {
        return mReferent;
    }
    FolderStore fldr = imapMailboxStore.getMailboxStore().getFolderById(getContext(), Integer.toString(iidRemote.getId()));
    if (fldr == null) {
        return mReferent;
    }
    String owner = getOwner(target);
    if (Strings.isNullOrEmpty(subpathRemote)) {
        mReferent = new ImapPath(owner, fldr, mCredentials);
    } else {
        mReferent = ImapPath.get(owner, fldr.getPath() + (fldr.getPath().equals("/") ? "" : "/") + subpathRemote, mCredentials, imapMailboxStore);
    }
    if (mReferent != this) {
        mReferent.mScope = Scope.REFERENCE;
    }
    return mReferent;
}
Also used : Account(com.zimbra.cs.account.Account) ExistingParentFolderStoreAndUnmatchedPart(com.zimbra.common.mailbox.ExistingParentFolderStoreAndUnmatchedPart) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) MountpointStore(com.zimbra.common.mailbox.MountpointStore) FolderStore(com.zimbra.common.mailbox.FolderStore) ItemId(com.zimbra.cs.service.util.ItemId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ExistingParentFolderStoreAndUnmatchedPart (com.zimbra.common.mailbox.ExistingParentFolderStoreAndUnmatchedPart)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ZFolder (com.zimbra.client.ZFolder)1 FolderStore (com.zimbra.common.mailbox.FolderStore)1 MountpointStore (com.zimbra.common.mailbox.MountpointStore)1 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 CreateFolder (com.zimbra.cs.redolog.op.CreateFolder)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 ItemId (com.zimbra.cs.service.util.ItemId)1