Search in sources :

Example 1 with OpContext

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;
}
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 2 with OpContext

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) {
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) ZClientException(com.zimbra.common.zclient.ZClientException) ZContact(com.zimbra.client.ZContact) Contact(com.zimbra.cs.mailbox.Contact) OpContext(com.zimbra.common.mailbox.OpContext) ZContact(com.zimbra.client.ZContact) Test(org.junit.Test)

Aggregations

OpContext (com.zimbra.common.mailbox.OpContext)2 ZContact (com.zimbra.client.ZContact)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZMessage (com.zimbra.client.ZMessage)1 FolderStore (com.zimbra.common.mailbox.FolderStore)1 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)1 MailboxStore (com.zimbra.common.mailbox.MailboxStore)1 SearchFolderStore (com.zimbra.common.mailbox.SearchFolderStore)1 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)1 ZClientException (com.zimbra.common.zclient.ZClientException)1 Contact (com.zimbra.cs.mailbox.Contact)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Test (org.junit.Test)1