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;
}
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();
}
}
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();
}
}
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;
}
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);
}
}
Aggregations