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());
}
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;
}
Aggregations