Search in sources :

Example 11 with MailboxStore

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

the class ImapHandler method doSTATUS.

private boolean doSTATUS(String tag, ImapPath path, StatusDataItemNames dataItemNames) throws ImapException, IOException {
    if (!checkState(tag, State.AUTHENTICATED)) {
        return true;
    }
    try {
        path.canonicalize();
        if (imapProxy != null && path.isEquivalent(imapProxy.getPath())) {
            return imapProxy.status(tag, dataItemNames.toString());
        }
        if (!path.isVisible()) {
            ZimbraLog.imap.info("STATUS failed: folder not visible: %s", path);
            sendNO(tag, "STATUS failed");
            return true;
        }
        if (credentials != null) {
            MailboxStore mbox = credentials.getMailbox();
            if (mbox != null) {
                mbox.noOp();
            }
        }
        sendUntagged(status(path, dataItemNames.cmdStatus));
    } catch (ServiceException e) {
        if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
            ZimbraLog.imap.info("STATUS failed: no such folder: %s", path);
        } else {
            ZimbraLog.imap.warn("STATUS failed", e);
        }
        sendNO(tag, "STATUS failed");
        return canContinue(e);
    }
    sendNotifications(true, false);
    sendOK(tag, "STATUS 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)

Example 12 with MailboxStore

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

the class ImapListener method unload.

/**
 * Unload this session data into cache.
 *
 * @param active true to use active session cache, otherwise use inactive session cache
 */
protected void unload(boolean active) throws ServiceException {
    // mailbox reference is volatile, so we need to acquire a local reference to avoid an NPE
    MailboxStore mbox = getMailbox();
    if (mbox == null) {
        return;
    }
    // Mailbox.endTransaction() -> ImapSession.notifyPendingChanges() locks in the order of Mailbox -> ImapSession.
    // Need to lock in the same order here, otherwise can result in deadlock.
    // serialize() locks Mailbox deep inside of it
    mbox.lock(true);
    try {
        synchronized (this) {
            if (mFolder instanceof ImapFolder) {
                // if the data's already paged out, we can short-circuit
                mFolder = createPagedFolderData(active, (ImapFolder) mFolder);
            } else if (mFolder instanceof PagedFolderData) {
                PagedFolderData paged = (PagedFolderData) mFolder;
                if (paged.getCacheKey() == null || !paged.getCacheKey().equals(MANAGER.cacheKey(this, active))) {
                    // currently cached to wrong cache need to move it so it doesn't get expired or LRU'd
                    ZimbraLog.imap.trace("relocating cached item to %s already unloaded but cache key mismatched %s", (active ? "active" : "inactive"), this);
                    ImapFolder folder = null;
                    try {
                        folder = reload();
                        if (folder != null) {
                            mFolder = createPagedFolderData(active, folder);
                        } else {
                            ZimbraLog.imap.debug("folder not found while reloading for relocate. probably already evicted. %s", this);
                        }
                    } catch (ImapSessionClosedException e) {
                        throw ServiceException.FAILURE("Session closed while relocating paged item", e);
                    }
                }
            }
        }
    } finally {
        mbox.unlock();
    }
}
Also used : MailboxStore(com.zimbra.common.mailbox.MailboxStore)

Example 13 with MailboxStore

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

the class ImapFolder method restore.

protected synchronized void restore(ImapListener sess, SessionData sdata) throws ImapSessionClosedException, ServiceException {
    session = sess;
    MailboxStore sessMbox = session.getMailbox();
    if (sessMbox == null) {
        mailboxStore = null;
        throw new ImapSessionClosedException();
    }
    mailboxStore = ImapMailboxStore.get(sessMbox, sessMbox.getAccountId());
    if (mailboxStore == null) {
        ZimbraLog.imap.warn("Unable to get mailboxStore corresponding to mailbox=%s sessionPath=%s", sessMbox, session.getPath());
        throw new ImapSessionClosedException();
    }
    path = session.getPath();
    // FIXME: NOT RESTORING sequence.msg.sflags PROPERLY -- need to serialize it!!!
    sessionData = sdata;
    if (folderIdentifier == null) {
        ZimbraLog.imap.warn("Restored ImapFolder has null folderIdentifier mailbox=%s sessionPath=%s", sessMbox, session.getPath());
        /* We're going to have big problems with this anyway, if this is true */
        throw new ImapSessionClosedException();
    }
}
Also used : MailboxStore(com.zimbra.common.mailbox.MailboxStore)

Example 14 with MailboxStore

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

the class ImapPath method setupMailboxStoreForTarget.

private ImapMailboxStore setupMailboxStoreForTarget(Account target, ItemId iidRemote) throws ServiceException {
    ImapMailboxStore imapMailboxStore = null;
    // if both target and owner are on local server and using local imap
    if (Provisioning.onLocalServer(target) && onLocalServer()) {
        try {
            MailboxStore mbox = MailboxManager.getInstance().getMailboxByAccount(target);
            imapMailboxStore = ImapMailboxStore.get(mbox, target.getId());
        } catch (ServiceException se) {
            ZimbraLog.imap.debug("Unexpected exception", se);
        }
    } else {
        Account acct = mCredentials == null ? null : Provisioning.getInstance().get(AccountBy.id, mCredentials.getAccountId());
        if (acct == null) {
            return null;
        }
        try {
            ZMailbox zmbx = getZMailboxForAccount(target);
            ZFolder zfolder = zmbx.getFolderById(iidRemote.toString(mCredentials.getAccountId()));
            if (zfolder == null) {
                return null;
            }
            imapMailboxStore = ImapMailboxStore.get(zmbx);
        } catch (ServiceException e) {
            ZimbraLog.imap.debug("Unexpected exception", e);
        }
    }
    return imapMailboxStore;
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) MailboxStore(com.zimbra.common.mailbox.MailboxStore) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZFolder(com.zimbra.client.ZFolder)

Example 15 with MailboxStore

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

the class ImapRemoteSession method unregisterFromRemoteServer.

private void unregisterFromRemoteServer() {
    try {
        MailboxStore mbs = mailbox;
        if (mbs == null) {
            ZimbraLog.imap.info("ImapRemoteSession.unregisterFromRemoteServer called but mailbox=null - %s\n%s", this, ZimbraLog.getStackTrace(5));
            return;
        }
        ImapServerListener listener = ImapServerListenerPool.getInstance().getForAccountId(mbs.getAccountId());
        if (listener == null) {
            ZimbraLog.imap.info("ImapRemoteSession.unregisterFromRemoteServer called but listener=null - %s\n%s", this, ZimbraLog.getStackTrace(5));
            return;
        }
        listener.removeListener(this);
    } catch (ServiceException e) {
        ZimbraLog.imap.error(e);
    }
}
Also used : MailboxStore(com.zimbra.common.mailbox.MailboxStore) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

MailboxStore (com.zimbra.common.mailbox.MailboxStore)34 ServiceException (com.zimbra.common.service.ServiceException)22 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)17 AccountServiceException (com.zimbra.cs.account.AccountServiceException)14 SearchFolderStore (com.zimbra.common.mailbox.SearchFolderStore)10 FolderStore (com.zimbra.common.mailbox.FolderStore)9 ArrayList (java.util.ArrayList)6 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)5 Account (com.zimbra.cs.account.Account)4 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)3 ImapMessageSet (com.zimbra.cs.imap.ImapMessage.ImapMessageSet)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 IOException (java.io.IOException)3 ZMailbox (com.zimbra.client.ZMailbox)2 ZSharedFolder (com.zimbra.client.ZSharedFolder)2 MountpointStore (com.zimbra.common.mailbox.MountpointStore)2 ZimbraQueryHit (com.zimbra.common.mailbox.ZimbraQueryHit)2 ZimbraQueryHitResults (com.zimbra.common.mailbox.ZimbraQueryHitResults)2 ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)2 GuestAccount (com.zimbra.cs.account.GuestAccount)2