use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapPath method getReferent.
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;
}
ItemId iidRemote;
String subpathRemote = null;
Object mboxobj = getOwnerMailbox();
if (mboxobj instanceof Mailbox) {
try {
if (mFolder == null) {
Pair<Folder, String> resolved = ((Mailbox) mboxobj).getFolderByPathLongestMatch(getContext(), Mailbox.ID_FOLDER_USER_ROOT, asZimbraPath());
subpathRemote = resolved.getSecond();
boolean isMountpoint = resolved.getFirst() instanceof Mountpoint;
if (isMountpoint || resolved.getSecond() == null) {
mFolder = resolved.getFirst();
mItemId = new ItemId(resolved.getFirst());
}
if (!isMountpoint) {
return mReferent;
}
} else if (!(mFolder instanceof Mountpoint)) {
return mReferent;
}
// somewhere along the specified path is a visible mountpoint owned by the user
iidRemote = ((Mountpoint) mFolder).getTarget();
} catch (ServiceException e) {
return mReferent;
}
} else if (mboxobj instanceof ZMailbox) {
String accountId = mCredentials == null ? null : mCredentials.getAccountId();
if (mFolder == null) {
ZMailbox zmbx = (ZMailbox) mboxobj;
String path = asZimbraPath();
try {
for (int index = path.length(); index != -1; index = path.lastIndexOf('/', index - 1)) {
ZFolder zfolder = zmbx.getFolderByPath(path.substring(0, index));
if (zfolder != null) {
subpathRemote = path.substring(Math.min(path.length(), index + 1));
if (zfolder instanceof ZMountpoint || subpathRemote.isEmpty()) {
mFolder = zfolder;
mItemId = new ItemId(zfolder.getId(), accountId);
}
break;
}
}
} catch (ServiceException e) {
}
}
if (!(mFolder instanceof ZMountpoint)) {
return mReferent;
}
// somewhere along the specified path is a visible mountpoint owned by the user
iidRemote = new ItemId(((ZMountpoint) mFolder).getCanonicalRemoteId(), accountId);
} else {
return mReferent;
}
// 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;
}
String owner = mCredentials != null && mCredentials.getAccountId().equalsIgnoreCase(target.getId()) ? null : target.getName();
if (Provisioning.onLocalServer(target)) {
try {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(target);
Folder folder = mbox.getFolderById(getContext(), iidRemote.getId());
if (subpathRemote == null) {
mReferent = new ImapPath(owner, folder, mCredentials);
} else {
(mReferent = new ImapPath(owner, folder.getPath() + (folder.getPath().equals("/") ? "" : "/") + subpathRemote, mCredentials)).mMailbox = mbox;
}
} catch (ServiceException e) {
}
} else {
Account acct = mCredentials == null ? null : Provisioning.getInstance().get(AccountBy.id, mCredentials.getAccountId());
if (acct == null)
return mReferent;
try {
ZMailbox.Options options = new ZMailbox.Options(AuthProvider.getAuthToken(acct).getEncoded(), AccountUtil.getSoapUri(target));
options.setTargetAccount(target.getName());
options.setNoSession(true);
ZMailbox zmbx = ZMailbox.getMailbox(options);
ZFolder zfolder = zmbx.getFolderById(iidRemote.toString(mCredentials.getAccountId()));
if (zfolder == null) {
return mReferent;
}
if (subpathRemote == null) {
mReferent = new ImapPath(owner, zfolder, mCredentials);
} else {
(mReferent = new ImapPath(owner, zfolder.getPath() + (zfolder.getPath().equals("/") ? "" : "/") + subpathRemote, mCredentials)).mMailbox = zmbx;
}
} catch (AuthTokenException ate) {
throw ServiceException.FAILURE("error generating auth token", ate);
} catch (ServiceException e) {
}
}
if (mReferent != this) {
mReferent.mScope = Scope.REFERENCE;
}
return mReferent;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class CtagInfoCache method getFolder.
private CtagInfo getFolder(CalendarKey key) throws ServiceException {
String accountId = key.getAccountId();
int folderId = key.getFolderId();
CtagInfo calInfo = null;
Provisioning prov = Provisioning.getInstance();
Account acct = prov.get(AccountBy.id, accountId);
if (acct == null) {
ZimbraLog.calendar.warn("Invalid account %s during cache lookup", accountId);
return null;
}
if (Provisioning.onLocalServer(acct)) {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Folder folder = mbox.getFolderById(null, folderId);
if (folder != null)
calInfo = new CtagInfo(folder);
else
ZimbraLog.calendar.warn("Invalid folder %d in account %s during cache lookup", folderId, accountId);
} else {
ZAuthToken zat = AuthProvider.getAdminAuthToken().toZAuthToken();
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(acct));
zoptions.setNoSession(true);
zoptions.setTargetAccount(acct.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
ItemId iidFolder = new ItemId(accountId, folderId);
ZFolder zfolder = zmbx.getFolderById(iidFolder.toString());
if (zfolder != null)
calInfo = new CtagInfo(zfolder);
else
ZimbraLog.calendar.warn("Invalid folder %d in account %s during cache lookup", folderId, accountId);
}
return calInfo;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class UserServlet method getExternalRestUrl.
/**
* Constructs the exteral url for a mount point. This gets the link back to the correct server without need for proxying it
* @param authToken
* @param mpt The mount point to create the url for
* @return The url for the mountpoint/share that goes back to the original user/share/server
* @throws ServiceException
*/
public static String getExternalRestUrl(OperationContext octxt, Mountpoint mpt) throws ServiceException {
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
// no need to do anything
if (mpt.isLocal()) {
return null;
}
String folderPath = null;
// Figure out the target server from the target user's account.
// This will let us get the correct server/port
Provisioning prov = Provisioning.getInstance();
Account targetAccount = prov.get(AccountBy.id, mpt.getOwnerId());
if (targetAccount == null) {
// Remote owner account has been deleted.
return null;
}
Server targetServer = prov.getServer(targetAccount);
// Avoid the soap call if its a local mailbox
if (Provisioning.onLocalServer(targetAccount)) {
Mailbox mailbox = MailboxManager.getInstance().getMailboxByAccountId(targetAccount.getId());
if (mailbox == null) {
// no mailbox (shouldn't happen normally)
return null;
}
// Get the folder from the mailbox
Folder folder = mailbox.getFolderById(octxt, mpt.getRemoteId());
if (folder == null) {
return null;
}
folderPath = folder.getPath();
} else {
// The remote server case
// Get the target user's mailbox..
ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(targetAccount));
zoptions.setTargetAccount(mpt.getOwnerId());
zoptions.setTargetAccountBy(AccountBy.id);
zoptions.setNoSession(true);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
if (zmbx == null) {
// we didn't manage to get a mailbox
return null;
}
// Get an instance of their folder so we can build the path correctly
ZFolder folder = zmbx.getFolderById(mpt.getTarget().toString(authToken.getAccount().getId()));
// if for some reason we can't find the folder, return null
if (folder == null) {
return null;
}
folderPath = folder.getPath();
}
// For now we'll always use SSL
return URLUtil.getServiceURL(targetServer, SERVLET_PATH + HttpUtil.urlEscape(getAccountPath(targetAccount) + folderPath), true);
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ZMailboxUtil method computeStats.
private void computeStats(ZFolder f, Stats s) {
s.numMessages += f.getMessageCount();
s.numUnread += f.getUnreadCount();
for (ZFolder c : f.getSubFolders()) {
computeStats(c, s);
}
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ZMailboxUtil method doGetFolderRequest.
private void doGetFolderRequest(String[] args) throws ServiceException {
ZFolder f = mMbox.getFolderRequestById(args[0]);
stdout.println(f);
}
Aggregations