Search in sources :

Example 21 with ItemIdentifier

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

the class TestZClient method testRecordIMAPSession.

@Test
public void testRecordIMAPSession() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder testFolder = TestUtil.createFolder(zmbox, "foo");
    String folderId = testFolder.getId();
    ItemIdentifier folderIdent = testFolder.getFolderItemIdentifier();
    zmbox.recordImapSession(testFolder.getFolderItemIdentifier());
    int imapRecentCutoff0 = testFolder.getImapRECENTCutoff(false);
    TestUtil.addMessage(zmbox, "test Message", folderId);
    zmbox.recordImapSession(testFolder.getFolderItemIdentifier());
    // passing false here ensures that ZFolder is not manually refreshing
    // the cutoff value
    int imapRecentCutoff1 = testFolder.getImapRECENTCutoff(false);
    assertEquals(folderIdent.id, imapRecentCutoff0);
    assertEquals(folderIdent.id + 1, imapRecentCutoff1);
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Test(org.junit.Test)

Example 22 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier 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)

Example 23 with ItemIdentifier

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

the class TestZClient method testFlags.

@Test
public void testFlags() throws Exception {
    ZMailbox recipZMbox = TestUtil.getZMailbox(RECIPIENT_USER_NAME);
    ZMailbox senderZMbox = TestUtil.getZMailbox(USER_NAME);
    Mailbox recipMbox = TestUtil.getMailbox(RECIPIENT_USER_NAME);
    Mailbox senderMbox = TestUtil.getMailbox(USER_NAME);
    // UNREAD
    String id = TestUtil.addMessage(recipZMbox, "testFlags unread message");
    int numId = Integer.parseInt(id);
    recipZMbox.markItemRead(id, false, null);
    assertTrue("Message.isUnread should return TRUE", waitForFlag(numId, recipMbox, "isUnread", true, 3000));
    ZMessage zmsg = recipZMbox.getMessageById(id);
    assertTrue(zmsg.isUnread());
    Message msg = recipMbox.getMessageById(null, numId);
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    Collection<ItemIdentifier> ids = new ArrayList<ItemIdentifier>(1);
    ids.add(new ItemIdentifier(recipMbox.getAccountId(), numId));
    recipZMbox.markItemRead(id, true, null);
    assertTrue("Message.isUnread should return FALSE", waitForFlag(numId, recipMbox, "isUnread", false, 3000));
    zmsg = recipZMbox.getMessageById(id);
    assertFalse("ZMessage.isUnread() should be FALSE", zmsg.isUnread());
    msg = recipMbox.getMessageById(null, numId);
    assertFalse("Message.isUnread() should be FALSE", msg.isUnread());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // flag
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.FLAGGED, true, null);
    msg = recipMbox.getMessageById(null, numId);
    assertTrue("Message.isFlagged() should be TRUE", msg.isFlagged());
    recipZMbox.noOp();
    zmsg = recipZMbox.getMessageById(id);
    assertTrue("ZMessage.isFlagged() should be TRUE", zmsg.isFlagged());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // unflag
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.FLAGGED, false, null);
    msg = recipMbox.getMessageById(null, numId);
    assertFalse("Message.isFlagged() should be FALSE", msg.isFlagged());
    recipZMbox.noOp();
    zmsg = recipZMbox.getMessageById(id);
    assertFalse("ZMessage.isFlagged() should be FALSE", zmsg.isFlagged());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // HIGH_PRIORITY
    ZOutgoingMessage importantMsg = TestUtil.getOutgoingMessage(RECIPIENT_USER_NAME, "This is an important message", "about something", null);
    importantMsg.setPriority("!");
    ZMessage savedDraft = senderZMbox.saveDraft(importantMsg, null, null);
    numId = Integer.parseInt(savedDraft.getId());
    assertTrue("ZMessage.isHighPriority() should be TRUE", savedDraft.isHighPriority());
    assertTrue(String.format("SavedDraft modifiedSequence=%s should be > 0", savedDraft.getModifiedSequence()), savedDraft.getModifiedSequence() > 0);
    msg = senderMbox.getMessageById(null, numId);
    zmsg = senderZMbox.getMessageById(savedDraft.getId());
    assertTrue("Message should be tagged with '!' tag", msg.isTagged(Flag.FlagInfo.HIGH_PRIORITY));
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    assertEquals("Expected=savedDraft ModSeq, Actual=MBOX getMessageById ModSeq", savedDraft.getModifiedSequence(), msg.getModifiedSequence());
    assertEquals("Expected=savedDraft ModSeq, Actual=ZMBOX getMessageById ModSeq", savedDraft.getModifiedSequence(), zmsg.getModifiedSequence());
    // LOW_PRIORITY
    ZOutgoingMessage nonImportantMsg = TestUtil.getOutgoingMessage(RECIPIENT_USER_NAME, "This is an important message", "about something", null);
    nonImportantMsg.setPriority("?");
    savedDraft = senderZMbox.saveDraft(nonImportantMsg, null, null);
    numId = Integer.parseInt(savedDraft.getId());
    assertFalse("ZMessage.isHighPriority() should be FALSE", savedDraft.isHighPriority());
    msg = senderMbox.getMessageById(null, numId);
    zmsg = senderZMbox.getMessageById(savedDraft.getId());
    assertTrue("Message should be tagged with '?' tag", msg.isTagged(Flag.FlagInfo.LOW_PRIORITY));
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // NOTIFIED
    id = TestUtil.addMessage(recipZMbox, "testFlags notified message");
    numId = Integer.parseInt(id);
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.NOTIFIED, true, null);
    recipZMbox.clearMessageCache();
    msg = recipMbox.getMessageById(null, numId);
    zmsg = recipZMbox.getMessageById(id);
    assertTrue("Message should be tagged 'NOTIFIED'", msg.isTagged(FlagInfo.NOTIFIED));
    assertTrue("ZMessage.isNotificationSent() should be TRUE", zmsg.isNotificationSent());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // unset
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.NOTIFIED, false, null);
    recipZMbox.clearMessageCache();
    msg = recipMbox.getMessageById(null, numId);
    zmsg = recipZMbox.getMessageById(id);
    assertFalse("Message should not be tagged 'NOTIFIED' anymore", msg.isTagged(FlagInfo.NOTIFIED));
    assertFalse("ZMessage.isNotificationSent() should be FALSE", zmsg.isNotificationSent());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // FORWARDED
    id = TestUtil.addMessage(recipZMbox, "testFlags forwarded message");
    numId = Integer.parseInt(id);
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.FORWARDED, true, null);
    recipZMbox.clearMessageCache();
    msg = recipMbox.getMessageById(null, numId);
    zmsg = recipZMbox.getMessageById(id);
    assertTrue("Message should be tagged 'FORWARDED'", msg.isTagged(FlagInfo.FORWARDED));
    assertTrue("ZMessage.isForwarded() should be TRUE", zmsg.isForwarded());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // unset
    numId = Integer.parseInt(id);
    recipMbox.alterTag(null, numId, MailItem.Type.MESSAGE, Flag.FlagInfo.FORWARDED, false, null);
    recipZMbox.clearMessageCache();
    msg = recipMbox.getMessageById(null, numId);
    zmsg = recipZMbox.getMessageById(id);
    assertFalse("Message should NOT be tagged 'FORWARDED'", msg.isTagged(FlagInfo.FORWARDED));
    assertFalse("ZMessage.isForwarded() should be FALSE", zmsg.isForwarded());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // send an important message
    String subject = "tobesent";
    importantMsg = TestUtil.getOutgoingMessage(RECIPIENT_USER_NAME, subject, "about nothing", null);
    importantMsg.setPriority("!");
    savedDraft = senderZMbox.saveDraft(importantMsg, null, null);
    numId = Integer.parseInt(savedDraft.getId());
    msg = senderMbox.getMessageById(null, numId);
    zmsg = senderZMbox.getMessageById(savedDraft.getId());
    // send it
    senderZMbox.sendMessage(importantMsg, null, false);
    senderZMbox.clearMessageCache();
    zmsg = TestUtil.waitForMessage(senderZMbox, "in:sent subject:\"" + subject + "\"");
    numId = Integer.parseInt(zmsg.getId());
    msg = senderMbox.getMessageById(null, numId);
    assertTrue("sent message should be marked as 'from me'", msg.isFromMe());
    assertTrue("Message should be tagged with '!' tag", msg.isTagged(Flag.FlagInfo.HIGH_PRIORITY));
    assertTrue("sent ZMessage should be market as 'sent by me'", zmsg.isSentByMe());
    assertTrue("ZMessage.isHighPriority() should be TRUE", zmsg.isHighPriority());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
    // check recipient
    recipZMbox.clearMessageCache();
    zmsg = TestUtil.waitForMessage(recipZMbox, "in:inbox subject:\"" + subject + "\"");
    numId = Integer.parseInt(zmsg.getId());
    msg = recipMbox.getMessageById(null, numId);
    assertFalse("received message should NOT be marked as 'from me'", msg.isFromMe());
    assertTrue("Message should be tagged with '!' tag", msg.isTagged(Flag.FlagInfo.HIGH_PRIORITY));
    assertFalse("received ZMessage should NOT be market as 'sent by me'", zmsg.isSentByMe());
    assertTrue("ZMessage.isHighPriority() should be TRUE", zmsg.isHighPriority());
    assertEquals("ZMessage bitmask does not match Message bitmask", msg.getFlagBitmask(), zmsg.getFlagBitmask());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ImapMessage(com.zimbra.cs.imap.ImapMessage) ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList) ZMountpoint(com.zimbra.client.ZMountpoint) Test(org.junit.Test)

Example 24 with ItemIdentifier

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

the class TestZClient method testCopyItemAction.

@Test
public void testCopyItemAction() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String sender = TestUtil.getAddress(USER_NAME);
    String recipient = TestUtil.getAddress(RECIPIENT_USER_NAME);
    String subject = NAME_PREFIX + " testCopyItemAction";
    String content = new MessageBuilder().withSubject(subject).withFrom(sender).withToRecipient(recipient).create();
    // add a msg flagged as sent; filterSent=TRUE
    mbox.addMessage(Integer.toString(Mailbox.ID_FOLDER_DRAFTS), null, null, System.currentTimeMillis(), content, false, false);
    ZMessage msg = TestUtil.waitForMessage(mbox, "in:drafts " + subject);
    List<ItemIdentifier> ids = Lists.newArrayListWithCapacity(1);
    ids.add(new ItemIdentifier(msg.getId(), null));
    ItemActionResponse resp = mbox.copyItemAction(new ItemIdentifier(null, Mailbox.ID_FOLDER_SENT), ids);
    assertNotNull("item action response should not be null", resp);
    assertNotNull("action should not be null", resp.getAction());
    assertNotNull("action id should not be null", resp.getAction().getId());
    ZMessage copiedMessage = mbox.getMessageById(resp.getAction().getId());
    assertNotNull("copied msg should not be null", copiedMessage);
    assertEquals("subject of copied msg", subject, copiedMessage.getSubject());
// msg.getId()
}
Also used : ZMessage(com.zimbra.client.ZMessage) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) ItemActionResponse(com.zimbra.soap.mail.message.ItemActionResponse) Test(org.junit.Test)

Example 25 with ItemIdentifier

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

the class TestRemoteImapMailboxStore method testGetCurrentModseq.

@Test
public void testGetCurrentModseq() throws Exception {
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    Folder folder = mbox.createFolder(null, NAME_PREFIX, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    int folderId = folder.getId();
    ItemIdentifier folderIdent = folder.getFolderItemIdentifier();
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
    Assert.assertEquals("Before adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
    int oldModSeq = remoteStore.getCurrentMODSEQ(folderIdent);
    // add a message to the folder
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(folderId).setFlags(Flag.BITMASK_UNREAD);
    String message = TestUtil.getTestMessage(NAME_PREFIX, mbox.getAccount().getName(), "someone@zimbra.com", "nothing here", new Date(System.currentTimeMillis()));
    ParsedMessage pm = new ParsedMessage(message.getBytes(), System.currentTimeMillis(), false);
    mbox.addMessage(null, pm, dopt, null);
    zmbox.noOp();
    folder = mbox.getFolderById(null, folderId);
    Assert.assertEquals("After adding a message, remoteStore.getCurrentMODSEQ returns value different from folder.getImapMODSEQ", remoteStore.getCurrentMODSEQ(folderIdent), folder.getImapMODSEQ());
    Assert.assertFalse("Modseq should have changed after adding a message", remoteStore.getCurrentMODSEQ(folderIdent) == oldModSeq);
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Folder(com.zimbra.cs.mailbox.Folder) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)26 ZMailbox (com.zimbra.client.ZMailbox)12 Mailbox (com.zimbra.cs.mailbox.Mailbox)12 Test (org.junit.Test)11 ZMessage (com.zimbra.client.ZMessage)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)6 ArrayList (java.util.ArrayList)6 ZMountpoint (com.zimbra.client.ZMountpoint)5 MailboxStore (com.zimbra.common.mailbox.MailboxStore)5 ImapMessage (com.zimbra.cs.imap.ImapMessage)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Message (com.zimbra.cs.mailbox.Message)5 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)4 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)4 Folder (com.zimbra.cs.mailbox.Folder)4 ZContact (com.zimbra.client.ZContact)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Contact (com.zimbra.cs.mailbox.Contact)3 OperationContext (com.zimbra.cs.mailbox.OperationContext)3