use of com.zimbra.common.mailbox.OpContext 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;
}
use of com.zimbra.common.mailbox.OpContext in project zm-mailbox by Zimbra.
the class TestZClient method testZMailboxGetItemById.
@Test
public void testZMailboxGetItemById() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Integer id = Integer.valueOf(TestUtil.addMessage(zmbox, "testGetItemById test msg"));
ItemIdentifier msgItemId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), id);
Contact contact = TestUtil.createContactInDefaultFolder(mbox, "testzclient@example.com");
ItemIdentifier contactId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), contact.getId());
/* getting message using message id */
ZimbraMailItem mItemAsMsg = zmbox.getItemById((OpContext) null, msgItemId, MailItemType.MESSAGE);
assertNotNull("getItemById returned null when got with type MESSAGE", mItemAsMsg);
assertEquals("Different ID when got with type MESSAGE", id, Integer.valueOf(mItemAsMsg.getIdInMailbox()));
assertTrue(String.format("%s Not a ZMessage when got with type MESSAGE", mItemAsMsg.getClass().getName()), mItemAsMsg instanceof ZMessage);
/* getting item using message id */
mItemAsMsg = zmbox.getItemById((OpContext) null, msgItemId, MailItemType.UNKNOWN);
assertNotNull("getItemById returned null when got with type UNKNOWN", mItemAsMsg);
assertEquals("Different ID when got with type UNKNOWN", id, Integer.valueOf(mItemAsMsg.getIdInMailbox()));
assertTrue(String.format("%s Not a ZMessage when got with type UNKNOWN", mItemAsMsg.getClass().getName()), mItemAsMsg instanceof ZMessage);
/* getting contact using id of contact */
ZimbraMailItem mItemAsContact = zmbox.getItemById((OpContext) null, contactId, MailItemType.CONTACT);
assertNotNull("getItemById returned null when got with type CONTACT", mItemAsContact);
assertEquals("Different ID when got with type CONTACT", contactId.id, mItemAsContact.getIdInMailbox());
assertTrue(String.format("%s Not a ZContact when got with type CONTACT", mItemAsContact.getClass().getName()), mItemAsContact instanceof ZContact);
ZContact zContact = (ZContact) mItemAsContact;
assertEquals("Imap UID of ZContact should be same as Contact", contact.getImapUid(), zContact.getImapUid());
assertTrue(String.format("IMAP UID %s of ZContact not 0", zContact.getImapUid()), 0 != zContact.getImapUid());
/* getting message using contact id */
try {
zmbox.getItemById((OpContext) null, contactId, MailItemType.MESSAGE);
fail("ZClientNoSuchItemException was not thrown when getting contact as message");
} catch (ZClientException.ZClientNoSuchItemException zcnsie) {
}
/* getting message using non-existent id */
ItemIdentifier nonexistent = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), 9099);
try {
zmbox.getItemById((OpContext) null, nonexistent, MailItemType.UNKNOWN);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchItemException zcnsie) {
}
/* getting contact using id of message */
try {
zmbox.getItemById((OpContext) null, msgItemId, MailItemType.CONTACT);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchContactException zcnsce) {
}
/* getting document using id of message */
try {
zmbox.getItemById((OpContext) null, msgItemId, MailItemType.DOCUMENT);
fail("ZClientNoSuchItemException was not thrown");
} catch (ZClientException.ZClientNoSuchItemException zcnsce) {
}
}
Aggregations