Search in sources :

Example 36 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class GetMiniCal method resolveMountpoints.

// Resolve mountpoints for each requested folder.  Resolution can result in error per folder.  Typical errors
// include PERM_DENIED (if sharer revoked permission), NO_SUCH_FOLDER (if sharer deleted shared folder), and
// NO_SUCH_ACCOUNT (if sharer account has been deleted).
private static Map<ItemId, Resolved> resolveMountpoints(OperationContext octxt, Mailbox mbox, List<ItemId> folderIids) {
    Map<ItemId, Resolved> result = new HashMap<ItemId, Resolved>();
    for (ItemId iidFolder : folderIids) {
        String targetAccountId = iidFolder.getAccountId();
        int folderId = iidFolder.getId();
        try {
            ServiceException error = null;
            if (mbox.getAccountId().equals(targetAccountId)) {
                boolean isMountpoint = true;
                int hopCount = 0;
                // resolve local mountpoint to a real folder; deal with possible mountpoint chain
                while (isMountpoint && hopCount < ZimbraSoapContext.MAX_HOP_COUNT) {
                    Folder folder = mbox.getFolderById(octxt, folderId);
                    isMountpoint = folder instanceof Mountpoint;
                    if (isMountpoint) {
                        Mountpoint mp = (Mountpoint) folder;
                        folderId = mp.getRemoteId();
                        if (!mp.isLocal()) {
                            // done resolving if pointing to a different account
                            targetAccountId = mp.getOwnerId();
                            Account targetAcct = Provisioning.getInstance().get(Key.AccountBy.id, targetAccountId);
                            if (targetAcct == null)
                                error = AccountServiceException.NO_SUCH_ACCOUNT(targetAccountId);
                            break;
                        }
                        hopCount++;
                    }
                }
                if (hopCount >= ZimbraSoapContext.MAX_HOP_COUNT)
                    error = MailServiceException.TOO_MANY_HOPS(iidFolder);
            }
            result.put(iidFolder, new Resolved(new ItemId(targetAccountId, folderId), error));
        } catch (ServiceException e) {
            ItemIdFormatter ifmt = new ItemIdFormatter();
            ZimbraLog.calendar.warn("Error resolving calendar folder " + ifmt.formatItemId(iidFolder), e);
            result.put(iidFolder, new Resolved(new ItemId(targetAccountId, folderId), e));
        }
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashMap(java.util.HashMap) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 37 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class ItemAction method forceRemoteSession.

private Account forceRemoteSession(ZimbraSoapContext zsc, Map<String, Object> context, OperationContext octxt, String op, Element action) throws ServiceException {
    // only proxying notification from the user's home-server master session
    if (!zsc.isNotificationEnabled()) {
        return null;
    }
    Session session = (Session) context.get(SoapEngine.ZIMBRA_SESSION);
    if (session instanceof SoapSession.DelegateSession) {
        session = ((SoapSession.DelegateSession) session).getParentSession();
    }
    if (!(session instanceof SoapSession) || session.getMailbox() == null) {
        return null;
    }
    SoapSession ss = (SoapSession) session;
    // only have to worry about operations where things can get created in other mailboxes (regular notification works for all other cases)
    if (!op.equals(MailConstants.OP_MOVE) && !op.equals(MailConstants.OP_COPY) && !op.equals(MailConstants.OP_SPAM) && !op.equals(MailConstants.OP_RENAME) && !op.equals(MailConstants.OP_UPDATE)) {
        return null;
    }
    String folderStr = action.getAttribute(MailConstants.A_FOLDER, null);
    if (folderStr == null) {
        return null;
    }
    // recursively dereference mountpoints to find ultimate target folder
    ItemId iidFolder = new ItemId(folderStr, zsc), iidRequested = iidFolder;
    Account owner = null;
    int hopCount = 0;
    ZAuthToken zat = null;
    while (hopCount < ZimbraSoapContext.MAX_HOP_COUNT) {
        owner = Provisioning.getInstance().getAccountById(iidFolder.getAccountId());
        if (Provisioning.onLocalServer(owner)) {
            try {
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
                Folder folder = mbox.getFolderById(octxt, iidFolder.getId());
                if (!(folder instanceof Mountpoint))
                    break;
                iidFolder = ((Mountpoint) folder).getTarget();
            } catch (ServiceException e) {
                // could be a PERM_DENIED, could be something else -- this is not the right place to fail, however
                break;
            }
        } else {
            if (zat == null) {
                AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
                String pxyAuthToken = at.getProxyAuthToken();
                zat = pxyAuthToken == null ? at.toZAuthToken() : new ZAuthToken(pxyAuthToken);
            }
            ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(owner));
            zoptions.setNoSession(true);
            zoptions.setTargetAccount(owner.getId());
            zoptions.setTargetAccountBy(Key.AccountBy.id);
            ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
            zmbx.setName(owner.getName());
            /* need this when logging in using another user's auth */
            ZFolder zfolder = zmbx.getFolderById(iidFolder.toString(zsc.getAuthtokenAccountId()));
            if (!(zfolder instanceof ZMountpoint))
                break;
            iidFolder = new ItemId(((ZMountpoint) zfolder).getCanonicalRemoteId(), zsc.getAuthtokenAccountId());
        }
        hopCount++;
    }
    if (hopCount >= ZimbraSoapContext.MAX_HOP_COUNT) {
        throw MailServiceException.TOO_MANY_HOPS(iidRequested);
    }
    // avoid dereferencing the mountpoint again later on
    action.addAttribute(MailConstants.A_FOLDER, iidFolder.toString());
    // fault in a session to listen in on the target folder's mailbox
    if (iidFolder.belongsTo(session.getAuthenticatedAccountId())) {
        return null;
    } else if (iidFolder.isLocal()) {
        ss.getDelegateSession(iidFolder.getAccountId());
        return null;
    } else {
        try {
            proxyRequest(zsc.createElement(MailConstants.NO_OP_REQUEST), context, owner.getId());
            return owner;
        } catch (ServiceException e) {
            return null;
        }
    }
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) Account(com.zimbra.cs.account.Account) ImapFolder(com.zimbra.cs.datasource.imap.ImapFolder) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) ZAuthToken(com.zimbra.common.auth.ZAuthToken) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) SoapSession(com.zimbra.cs.session.SoapSession) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) SoapSession(com.zimbra.cs.session.SoapSession) Session(com.zimbra.cs.session.Session)

Example 38 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class ParseMimeMessage method attachDocument.

private static void attachDocument(MimeMultipart mmp, String path, String contentID, ParseMessageContext ctxt) throws MessagingException, ServiceException {
    MailItem item = null;
    try {
        // first, just blindly try to fetch the item
        item = ctxt.mbox.getItemByPath(ctxt.octxt, path);
    } catch (NoSuchItemException nsie) {
    }
    if (item == null) {
        // on a miss, check for a mountpoint and, if so, fetch via UserServlet
        Pair<Folder, String> match = ctxt.mbox.getFolderByPathLongestMatch(ctxt.octxt, Mailbox.ID_FOLDER_USER_ROOT, path);
        if (!(match.getFirst() instanceof Mountpoint)) {
            throw MailServiceException.NO_SUCH_DOC(path);
        }
        Map<String, String> params = new HashMap<String, String>(3);
        params.put(UserServlet.QP_NAME, match.getSecond());
        attachRemoteItem(mmp, ((Mountpoint) match.getFirst()).getTarget(), contentID, ctxt, params, null);
        return;
    }
    // on a hit, attach it directly
    if (!(item instanceof Document))
        throw MailServiceException.NO_SUCH_DOC(path);
    attachDocument(mmp, (Document) item, contentID, ctxt);
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) HashMap(java.util.HashMap) Folder(com.zimbra.cs.mailbox.Folder) Document(com.zimbra.cs.mailbox.Document) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 39 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class ItemActionHelper method schedule.

protected void schedule() throws ServiceException {
    boolean targeted = mOperation == Op.MOVE || mOperation == Op.SPAM || mOperation == Op.COPY || mOperation == Op.RENAME || (mOperation == Op.UPDATE && mIidFolder != null);
    // deal with local mountpoints pointing at local folders here
    if (targeted && mIidFolder.belongsTo(mMailbox) && mIidFolder.getId() > 0 && mIidFolder.getId() != Mailbox.ID_FOLDER_TRASH && mIidFolder.getId() != Mailbox.ID_FOLDER_SPAM) {
        try {
            Folder folder = mMailbox.getFolderById(mOpCtxt, mIidFolder.getId());
            if (folder instanceof Mountpoint && !((Mountpoint) folder).getOwnerId().equals(mIidFolder.getAccountId())) {
                mIidFolder = ((Mountpoint) folder).getTarget();
                mHopCount++;
            }
        } catch (ServiceException e) {
        // could be a PERM_DENIED, could be something else -- this is not the right place to fail, however
        }
    }
    try {
        if (!targeted || mIidFolder.belongsTo(mMailbox))
            mResult = executeLocal();
        else
            mResult = executeRemote();
    } catch (IOException | HttpException ioe) {
        throw ServiceException.FAILURE("exception reading item blob", ioe);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) Folder(com.zimbra.cs.mailbox.Folder) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 40 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class DBQueryOperation method expandLocalRemotePart.

@Override
QueryOperation expandLocalRemotePart(Mailbox mbox) throws ServiceException {
    if (constraints instanceof DbSearchConstraints.Leaf) {
        boolean added = false;
        if (includeIsLocalFolders) {
            // expanded!
            includeIsLocalFolders = false;
            DbSearchConstraints.Leaf leaf = (DbSearchConstraints.Leaf) constraints;
            for (Folder f : mbox.getFolderById(null, Mailbox.ID_FOLDER_ROOT).getSubfolderHierarchy()) {
                if (!(f instanceof Mountpoint) && !(f instanceof SearchFolder)) {
                    // add local folder ref
                    leaf.folders.add(f);
                    added = true;
                }
            }
            if (!added) {
                return new NoResultsQueryOperation();
            } else {
                return this;
            }
        } else if (includeIsRemoteFolders) {
            UnionQueryOperation toRet = new UnionQueryOperation();
            // expanded
            includeIsRemoteFolders = false;
            for (Folder f : mbox.getFolderById(null, Mailbox.ID_FOLDER_ROOT).getSubfolderHierarchy()) {
                if (f instanceof Mountpoint) {
                    Mountpoint mpt = (Mountpoint) f;
                    if (!mpt.isLocal()) {
                        // add remote folder ref
                        DBQueryOperation db = new DBQueryOperation();
                        db.addInRemoteFolder(mpt.getTarget(), "", true, true);
                        toRet.add(db);
                        added = true;
                    }
                }
            }
            if (!added) {
                return new NoResultsQueryOperation();
            } else {
                return toRet;
            }
        } else {
            return this;
        }
    } else {
        throw new IllegalStateException("expandLocalRemotePart must be called before optimize() is called");
    }
}
Also used : SearchFolder(com.zimbra.cs.mailbox.SearchFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Folder(com.zimbra.cs.mailbox.Folder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Aggregations

Mountpoint (com.zimbra.cs.mailbox.Mountpoint)43 Folder (com.zimbra.cs.mailbox.Folder)30 ServiceException (com.zimbra.common.service.ServiceException)23 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 Account (com.zimbra.cs.account.Account)17 MailItem (com.zimbra.cs.mailbox.MailItem)14 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)14 ZFolder (com.zimbra.client.ZFolder)11 ItemId (com.zimbra.cs.service.util.ItemId)11 ZMailbox (com.zimbra.client.ZMailbox)8 Element (com.zimbra.common.soap.Element)8 OperationContext (com.zimbra.cs.mailbox.OperationContext)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Provisioning (com.zimbra.cs.account.Provisioning)6 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)6 ZMountpoint (com.zimbra.client.ZMountpoint)5 Pair (com.zimbra.common.util.Pair)5 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)5 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)5