Search in sources :

Example 11 with SearchFolder

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();
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Folder(com.zimbra.cs.mailbox.Folder) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder)

Example 12 with SearchFolder

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;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Color(com.zimbra.common.mailbox.Color) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

SearchFolder (com.zimbra.cs.mailbox.SearchFolder)12 Mailbox (com.zimbra.cs.mailbox.Mailbox)8 Folder (com.zimbra.cs.mailbox.Folder)6 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)6 OperationContext (com.zimbra.cs.mailbox.OperationContext)6 ServiceException (com.zimbra.common.service.ServiceException)4 Element (com.zimbra.common.soap.Element)4 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)4 ItemId (com.zimbra.cs.service.util.ItemId)4 MailItem (com.zimbra.cs.mailbox.MailItem)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)3 ZFolder (com.zimbra.client.ZFolder)2 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)2 Contact (com.zimbra.cs.mailbox.Contact)2 Document (com.zimbra.cs.mailbox.Document)2 ExportPeriodNotSpecifiedException (com.zimbra.cs.mailbox.MailServiceException.ExportPeriodNotSpecifiedException)2 ExportPeriodTooLongException (com.zimbra.cs.mailbox.MailServiceException.ExportPeriodTooLongException)2 SetCalendarItemData (com.zimbra.cs.mailbox.Mailbox.SetCalendarItemData)2 Message (com.zimbra.cs.mailbox.Message)2 ParsedContact (com.zimbra.cs.mime.ParsedContact)2