use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapPath method canonicalize.
ImapPath canonicalize() throws ServiceException {
getFolder();
String path;
if (mFolder instanceof Folder) {
path = ((Folder) mFolder).getPath();
} else {
path = ((ZFolder) mFolder).getPath();
}
while (path.startsWith("/")) {
path = path.substring(1);
}
while (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
int excess = mPath.length() - path.length();
if (mReferent == this || excess == 0) {
mPath = path;
} else {
mPath = path + "/" + mReferent.canonicalize().mPath.substring(mReferent.mPath.length() - excess + 1);
}
return this;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapPath method getFolderRights.
short getFolderRights() throws ServiceException {
if (getFolder() instanceof Folder) {
Folder folder = (Folder) getFolder();
return folder.getMailbox().getEffectivePermissions(getContext(), folder.getId(), folder.getType());
} else {
ZFolder zfolder = (ZFolder) getFolder();
String rights = zfolder.getEffectivePerms();
return rights == null ? ~0 : ACL.stringToRights(rights);
}
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapPath method isValidImapPath.
/**
* Mostly checking that the path doesn't clash with any paths we don't want to expose via IMAP.
* Separated out from isVisible() to aid IMAP LSUB command support.
*/
boolean isValidImapPath() throws ServiceException {
if (mCredentials != null) {
if (mCredentials.isHackEnabled(ImapCredentials.EnabledHack.WM5)) {
String lcname = mPath.toLowerCase();
if (lcname.startsWith("sent items") && (lcname.length() == 10 || lcname.charAt(10) == '/'))
return false;
}
}
try {
// you cannot access your own mailbox via the /home/username mechanism
if (mOwner != null && belongsTo(mCredentials))
return false;
getFolder();
if (mFolder instanceof Folder) {
Folder folder = (Folder) mFolder;
// hide all system folders and the user root folder
if (folder.getId() == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
return false;
}
// hide spam folder unless anti-spam feature is enabled.
if (folder.getId() == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
return false;
}
boolean isMailFolders = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
if (!isVisible(folder.getDefaultView(), isMailFolders)) {
return false;
}
// hide subfolders of trashed mountpoints
if (mReferent != this && folder.inTrash() && !((Mountpoint) folder).getTarget().equals(mReferent.asItemId())) {
return false;
}
// hide other users' mountpoints and mountpoints that point to the same mailbox
if (folder instanceof Mountpoint && mReferent == this && mScope != Scope.UNPARSED) {
return false;
}
// search folder visibility depends on an account setting
if (folder instanceof SearchFolder) {
return ((SearchFolder) folder).isImapVisible() && ImapFolder.getTypeConstraint((SearchFolder) folder).size() > 0;
}
} else {
ZFolder zfolder = (ZFolder) mFolder;
int folderId = asItemId().getId();
// the mailbox root folder is not visible
if (folderId == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
return false;
}
// hide spam folder unless anti-spam feature is enabled.
if (folderId == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
return false;
}
// calendars, briefcases, etc. are not surfaced in IMAP
ZFolder.View view = zfolder.getDefaultView();
if (view == ZFolder.View.appointment || view == ZFolder.View.task || view == ZFolder.View.wiki || view == ZFolder.View.document) {
return false;
}
// hide other users' mountpoints and mountpoints that point to the same mailbox
if (zfolder instanceof ZMountpoint && mReferent == this && mScope != Scope.UNPARSED) {
return false;
}
// hide all remote searchfolders
if (zfolder instanceof ZSearchFolder) {
return false;
}
}
} catch (NoSuchItemException ignore) {
// 6.3.9. LSUB Command
// The server MUST NOT unilaterally remove an existing mailbox name from the subscription list even if a
// mailbox by that name no longer exists.
} catch (AccountServiceException ase) {
if (!AccountServiceException.NO_SUCH_ACCOUNT.equals(ase.getCode())) {
throw ase;
}
} catch (ServiceException se) {
if (ServiceException.PERM_DENIED.equals(se.getCode())) {
// Path probably OK. For subscriptions, don't disallow path for possibly temporary permissions issue
return true;
}
throw se;
}
return mReferent == this ? true : mReferent.isValidImapPath();
}
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;
}
Aggregations