Search in sources :

Example 6 with FolderStore

use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.

the class ImapHandler method doDELETE.

private boolean doDELETE(String tag, ImapPath path) throws IOException {
    if (!checkState(tag, State.AUTHENTICATED)) {
        return true;
    }
    try {
        if (!path.isVisible()) {
            throw ImapServiceException.FOLDER_NOT_VISIBLE(path.asImapPath());
        }
        // don't want the DELETE to cause *this* connection to drop if the deleted folder is currently selected
        if (getState() == State.SELECTED) {
            ImapListener i4selected = getCurrentImapListener();
            if (i4selected != null && path.isEquivalent(i4selected.getPath())) {
                unsetSelectedFolder(true);
            } else if (imapProxy != null && path.isEquivalent(imapProxy.getPath())) {
                unsetSelectedFolder(true);
            }
        }
        MailboxStore mboxStore = path.getOwnerMailbox();
        if (path.useReferent()) {
            // when users try to remove mountpoints, the IMAP client hard-deletes the subfolders!
            // deal with this by only *pretending* to delete subfolders of mountpoints
            credentials.hideFolder(path);
            // even pretend-deleting the folder also unsubscribes from it...
            credentials.unsubscribe(path);
        } else if (null != mboxStore) {
            FolderStore folder = path.getFolder();
            if (!folder.isDeletable()) {
                throw ImapServiceException.CANNOT_DELETE_SYSTEM_FOLDER(folder.getPath());
            }
            if (!folder.hasSubfolders()) {
                mboxStore.deleteFolder(getContext(), folder.getFolderIdAsString());
                // deleting the folder also unsubscribes from it...
                credentials.unsubscribe(path);
            } else {
                // 6.3.4: "It is permitted to delete a name that has inferior hierarchical
                // names and does not have the \Noselect mailbox name attribute.
                // In this case, all messages in that mailbox are removed, and the
                // name will acquire the \Noselect mailbox name attribute."
                mboxStore.emptyFolder(getContext(), folder.getFolderIdAsString(), false);
            // FIXME: add \Deleted flag to folder
            }
        } else {
            throw AccountServiceException.NO_SUCH_ACCOUNT(path.getOwner());
        }
    } catch (ServiceException e) {
        if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
            ZimbraLog.imap.info("DELETE failed: no such folder: %s", path);
        } else if (e.getCode().equals(AccountServiceException.NO_SUCH_ACCOUNT)) {
            ZimbraLog.imap.info("DELETE failed: no such account: %s", path);
        } else if (e.getCode().equals(ImapServiceException.FOLDER_NOT_VISIBLE)) {
            ZimbraLog.imap.info("DELETE failed: folder not visible: %s", path);
        } else if (e.getCode().equals(ImapServiceException.CANT_DELETE_SYSTEM_FOLDER)) {
            ZimbraLog.imap.info("DELETE failed: system folder cannot be deleted: %s", path);
        } else if (e.getCode().equals(ServiceException.PERM_DENIED)) {
            ZimbraLog.imap.info("DELETE failed: permission denied: %s", path);
        } else {
            ZimbraLog.imap.warn("DELETE failed", e);
        }
        sendNO(tag, "DELETE failed");
        return canContinue(e);
    }
    sendNotifications(true, false);
    sendOK(tag, "DELETE completed");
    return true;
}
Also used : MailboxStore(com.zimbra.common.mailbox.MailboxStore) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) SearchFolderStore(com.zimbra.common.mailbox.SearchFolderStore) FolderStore(com.zimbra.common.mailbox.FolderStore)

Example 7 with FolderStore

use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.

the class RemoteImapMailboxStore method getVisibleFolders.

@Override
public Collection<FolderStore> getVisibleFolders(OperationContext octxt, ImapCredentials credentials, String owner, ImapPath relativeTo) throws ServiceException {
    String root = relativeTo == null ? "" : "/" + relativeTo.asResolvedPath();
    List<ZFolder> allZFolders = zMailbox.getAllFolders();
    Set<FolderStore> fStores = Sets.newHashSetWithExpectedSize(allZFolders.size());
    List<ZFolder> zfolders = null;
    zfolders = zMailbox.getAllFolders();
    for (ZFolder zfolder : zfolders) {
        if (!zfolder.getPath().startsWith(root) || zfolder.getPath().equals(root)) {
            continue;
        }
        ImapPath path;
        path = (relativeTo == null) ? new ImapPath(owner, zfolder, credentials) : new ImapPath(owner, zfolder, relativeTo);
        if (path.isVisible()) {
            fStores.add(zfolder);
        }
    }
    return fStores;
}
Also used : FolderStore(com.zimbra.common.mailbox.FolderStore) ZFolder(com.zimbra.client.ZFolder)

Example 8 with FolderStore

use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.

the class ImapSessionManager method cacheKey.

/**
 * Generates a cache key for the {@link ImapListener}.
 *
 * @param session IMAP session
 * @param active true to use active session cache, otherwise inactive session cache.
 * @return cache key
 */
protected String cacheKey(ImapListener session, boolean active) throws ServiceException {
    MailboxStore mbox = session.getMailbox();
    FolderStore fstore;
    if (mbox == null) {
        if (session instanceof ImapSession) {
            mbox = MailboxManager.getInstance().getMailboxByAccountId(session.getTargetAccountId());
        } else {
            ImapMailboxStore imapStore = session.mPath.getOwnerImapMailboxStore(true);
            mbox = imapStore.getMailboxStore();
        }
    }
    if (session instanceof ImapSession) {
        fstore = mbox.getFolderById((OpContext) null, session.getFolderItemIdentifier().toString());
    } else {
        if (session.getAuthenticatedAccountId() == session.getTargetAccountId()) {
            fstore = mbox.getFolderById((OpContext) null, session.getFolderItemIdentifier().toString());
        } else {
            fstore = ((ZMailbox) mbox).getSharedFolderById(session.getFolderItemIdentifier().toString());
        }
    }
    String cachekey = cacheKey(fstore, active);
    // ('+' is a good separator because it alpha-sorts before the '.' of the filename extension)
    return session.hasExpunges() ? cachekey + "+" + session.getQualifiedSessionId() : cachekey;
}
Also used : MailboxStore(com.zimbra.common.mailbox.MailboxStore) FolderStore(com.zimbra.common.mailbox.FolderStore) SearchFolderStore(com.zimbra.common.mailbox.SearchFolderStore) OpContext(com.zimbra.common.mailbox.OpContext)

Example 9 with FolderStore

use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.

the class SharedImapTests method checkImapPath.

private void checkImapPath(String mboxName, ImapCredentials creds, String expectedPathToString, boolean usingReferent, int expectedReferentFolderId, String expectedReferentFolderAcct) throws ServiceException {
    ImapPath path = new ImapPath(mboxName, creds);
    path.canonicalize();
    ImapPath referent = path.getReferent();
    assertEquals(String.format("toString() for ImapPath for mailbox '%s'", mboxName), expectedPathToString, path.toString());
    if (usingReferent) {
        assertNotSame(String.format("ImapPath=%s and it's getReferent() for mailbox '%s'", path, mboxName), path, referent);
    } else {
        assertSame(String.format("ImapPath=%s and it's getReferent() for mailbox '%s'", path, mboxName), path, referent);
    }
    FolderStore folderForPath = path.getFolder();
    assertEquals(String.format("Folder ID for path.getReferent().getFolder() for mailbox '%s'", mboxName), expectedReferentFolderId, folderIdForFolder(folderForPath));
    assertEquals(String.format("Account ID for path.getReferent().getFolder() for mailbox '%s'", mboxName), expectedReferentFolderAcct, acctIdForFolder(folderForPath));
}
Also used : FolderStore(com.zimbra.common.mailbox.FolderStore) ImapPath(com.zimbra.cs.imap.ImapPath)

Example 10 with FolderStore

use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.

the class ImapHandler method accumulatePaths.

private void accumulatePaths(ImapMailboxStore imapStore, String owner, ImapPath relativeTo, Map<ImapPath, ItemId> paths, Map<ImapPath, ItemId> mountPaths, boolean isMountPath) throws ServiceException {
    Collection<FolderStore> visibleFolders = imapStore.getVisibleFolders(getContext(), credentials, owner, relativeTo);
    // TODO - This probably needs to be the setting for the server for IMAP session's main mailbox
    boolean isMailFolders = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
    for (FolderStore folderStore : visibleFolders) {
        // chat has item type of message.  hence ignoring the chat folder by name.
        if (isMailFolders && (folderStore.isChatsFolder() || (folderStore.getName().equals("Chats")))) {
            continue;
        }
        /* In remote case, list includes children of mountpoints - filter them out here and instead
             * tackle them via accumulatePaths in the owner mailbox. */
        if (!(folderStore instanceof MountpointStore) && isInMountpointHierarchy(folderStore)) {
            continue;
        }
        ImapPath path = relativeTo == null ? new ImapPath(owner, folderStore, credentials) : new ImapPath(owner, folderStore, relativeTo);
        if (path.isVisible()) {
            if (userAgent != null && userAgent.startsWith(IDInfo.DATASOURCE_IMAP_CLIENT_NAME) && folderStore.isSyncFolder()) {
                // IMAP datasource connections
                continue;
            }
            // boolean alreadyTraversed = paths.put(path, path.asItemId()) != null;
            boolean alreadyTraversed = (!isMountPath) ? paths.put(path, path.asItemId()) != null : mountPaths.put(path, path.asItemId()) != null;
            if (folderStore instanceof MountpointStore && !alreadyTraversed) {
                // mountPaths.put(path, path.asItemId());
                accumulatePaths(path.getOwnerImapMailboxStore(), owner, path, paths, mountPaths, true);
            }
        }
    }
}
Also used : SearchFolderStore(com.zimbra.common.mailbox.SearchFolderStore) FolderStore(com.zimbra.common.mailbox.FolderStore) MountpointStore(com.zimbra.common.mailbox.MountpointStore)

Aggregations

FolderStore (com.zimbra.common.mailbox.FolderStore)20 SearchFolderStore (com.zimbra.common.mailbox.SearchFolderStore)14 ServiceException (com.zimbra.common.service.ServiceException)13 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)12 AccountServiceException (com.zimbra.cs.account.AccountServiceException)11 MailboxStore (com.zimbra.common.mailbox.MailboxStore)9 MountpointStore (com.zimbra.common.mailbox.MountpointStore)4 Account (com.zimbra.cs.account.Account)3 ZSharedFolder (com.zimbra.client.ZSharedFolder)2 ACLGrant (com.zimbra.common.mailbox.ACLGrant)2 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 ItemId (com.zimbra.cs.service.util.ItemId)2 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ZFolder (com.zimbra.client.ZFolder)1 BaseFolderInfo (com.zimbra.common.mailbox.BaseFolderInfo)1 BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)1 ExistingParentFolderStoreAndUnmatchedPart (com.zimbra.common.mailbox.ExistingParentFolderStoreAndUnmatchedPart)1