use of com.zimbra.cs.mailbox.SearchFolder 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.cs.mailbox.SearchFolder in project zm-mailbox by Zimbra.
the class CreateSearchFolder method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element t = request.getElement(MailConstants.E_SEARCH);
String name = t.getAttribute(MailConstants.A_NAME);
String query = t.getAttribute(MailConstants.A_QUERY);
String types = t.getAttribute(MailConstants.A_SEARCH_TYPES, null);
String sort = t.getAttribute(MailConstants.A_SORTBY, null);
String flags = t.getAttribute(MailConstants.A_FLAGS, null);
byte color = (byte) t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR);
String rgb = t.getAttribute(MailConstants.A_RGB, null);
Color itemColor = rgb != null ? new Color(rgb) : new Color(color);
ItemId iidParent = new ItemId(t.getAttribute(MailConstants.A_FOLDER), zsc);
SearchFolder search = mbox.createSearchFolder(octxt, iidParent.getId(), name, query, types, sort, Flag.toBitmask(flags), itemColor);
Element response = zsc.createElement(MailConstants.CREATE_SEARCH_FOLDER_RESPONSE);
if (search != null)
ToXML.encodeSearchFolder(response, ifmt, search);
return response;
}
Aggregations