use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.
the class TestZClient method testZMailboxGetContact.
@Test
public void testZMailboxGetContact() throws ServiceException {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Contact contact = TestUtil.createContactInDefaultFolder(mbox, "testzclient2@example.com");
ItemIdentifier contactId = ItemIdentifier.fromAccountIdAndItemId(zmbox.getAccountId(), contact.getId());
ZContact zcontact = zmbox.getContact(contactId);
assertNotNull("ZContact object", zcontact);
assertEquals("Expected=ZContact ID Actual=ZContact IMAP UID", zcontact.getIdInMailbox(), zcontact.getImapUid());
assertEquals("IMAP UID Expected=Contact Actual=ZContact", contact.getImapUid(), zcontact.getImapUid());
assertEquals("ModifiedSequence Expected=Contact Actual=ZContact", contact.getModifiedSequence(), zcontact.getModifiedSequence());
}
use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.
the class TestZClient method testOpenImapFolder.
@Test
public void testOpenImapFolder() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Folder folder = mbox.createFolder(null, "TestOpenImapFolder", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
ItemIdentifier folderId = folder.getFolderItemIdentifier();
List<ImapMessage> expected = new LinkedList<ImapMessage>();
for (int i = 1; i <= 10; i++) {
Message msg = TestUtil.addMessage(mbox, folderId.id, String.format("imap message %s", i), System.currentTimeMillis());
expected.add(new ImapMessage(msg));
}
// test pagination
OpenIMAPFolderParams params = new OpenIMAPFolderParams(folderId);
// test fetching all results
params.setLimit(100);
OpenIMAPFolderResponse result = zmbox.fetchImapFolderChunk(params);
assertEquals(10, result.getImapMessageInfo().size());
assertFalse(result.getHasMore());
// test fetching first 5
params.setLimit(5);
result = zmbox.fetchImapFolderChunk(params);
List<ImapMessageInfo> messages = result.getImapMessageInfo();
assertEquals(5, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i).getMsgId());
}
assertTrue(result.getHasMore());
// test fetching 5 items starting at 3rd item, (more results left)
Integer cursorId = expected.get(2).getMsgId();
params.setCursorId(String.valueOf(cursorId));
result = zmbox.fetchImapFolderChunk(params);
messages = result.getImapMessageInfo();
assertEquals(5, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i + 3).getMsgId());
}
assertTrue(result.getHasMore());
// test fetching 5 items starting at 7th item, exhausting all results
cursorId = expected.get(6).getMsgId();
params.setCursorId(String.valueOf(cursorId));
result = zmbox.fetchImapFolderChunk(params);
messages = result.getImapMessageInfo();
assertEquals(3, messages.size());
for (int i = 0; i < messages.size(); i++) {
assertEquals(messages.get(i).getId(), expected.get(i + 7).getMsgId());
}
assertFalse(result.getHasMore());
// test getting all messages in batches of 3, so pagination is used
List<ImapMessageInfo> actual = zmbox.openImapFolder(folderId, 3);
Collections.sort(expected);
Collections.sort(actual);
assertEquals("expected and actual lists have different lengths", expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertEquals(expected.get(i).getImapUid(), actual.get(i).getImapUid());
}
}
use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.
the class TestZClient method testAlterTag.
@Test
public void testAlterTag() throws Exception {
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
Message msg = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "testAlterTag message", System.currentTimeMillis());
int msgId = msg.getId();
String tagName = "testAlterTag tag";
zmbox.createTag(tagName, ZTag.Color.blue);
Collection<ItemIdentifier> ids = new ArrayList<ItemIdentifier>(1);
ids.add(new ItemIdentifier(mbox.getAccountId(), msgId));
// add tag via zmailbox
zmbox.alterTag(null, ids, tagName, true);
assertTrue("Message should be tagged", waitForTag(msgId, mbox, tagName, true, 3000));
assertTrue(msg.isTagged(tagName));
// remove tag via zmailbox
zmbox.alterTag(null, ids, tagName, false);
assertTrue("Message should NOT be tagged", waitForTag(msgId, mbox, tagName, false, 3000));
msg = mbox.getMessageById(null, msgId);
assertFalse(tagName + " should be removed", msg.isTagged(tagName));
// test setting/unsetting unread flag
zmbox.alterTag(null, ids, "\\Unread", true);
assertTrue("Message.isUnread should return TRUE", waitForFlag(msgId, mbox, "isUnread", true, 3000));
msg = mbox.getMessageById(null, msgId);
assertTrue("Message should be unread", msg.isUnread());
zmbox.alterTag(null, ids, "\\Unread", false);
assertTrue("Message.isUnread should return FALSE", waitForFlag(msgId, mbox, "isUnread", false, 3000));
msg = mbox.getMessageById(null, msgId);
assertFalse("Message should be read", msg.isUnread());
}
use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.
the class Mailbox method copyItemAction.
/**
* Copies the items identified in {@link idlist} to folder {@link targetFolder}
* @param idlist - list of item ids for items to copy
* @param targetFolder - Destination folder
* @return The item IDs of the created items - these may be full item IDs in the case of remote folders
*/
@Override
public List<String> copyItemAction(OpContext ctxt, ItemIdentifier targetFolder, List<ItemIdentifier> idlist) throws ServiceException {
if ((idlist == null) || idlist.isEmpty()) {
return Collections.emptyList();
}
List<Integer> ids = Lists.newArrayListWithExpectedSize(idlist.size());
for (ItemIdentifier ident : idlist) {
if (this.referencesOtherMailbox(ident)) {
// requests are proxied to the selected folder's owner.
throw ServiceException.FAILURE("Unexpected attempt to copy item from mountpoint", null);
}
ids.add(ident.id);
}
ItemActionHelper op = ItemActionHelper.COPY((OperationContext) ctxt, this, null, ids, MailItem.Type.UNKNOWN, null, new ItemId(targetFolder));
CopyActionResult caResult = (CopyActionResult) op.getResult();
return caResult.getCreatedIds();
}
use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.
the class RecordIMAPSession method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
com.zimbra.soap.mail.message.RecordIMAPSessionRequest req = zsc.elementToJaxb(request);
String folderId = req.getFolderId();
Mailbox mbox = getRequestedMailbox(zsc);
ItemIdentifier folderIdent = ItemIdentifier.fromEncodedAndDefaultAcctId(folderId, mbox.getAccountId());
mbox.recordImapSession(folderIdent.id);
int lastItemId = mbox.getLastItemId();
Folder folder = mbox.getFolderById(null, folderIdent.id);
RecordIMAPSessionResponse resp = new RecordIMAPSessionResponse(lastItemId, folder.getUuid());
return zsc.jaxbToElement(resp);
}
Aggregations