use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemActionTest method moveConversationPreviousFolderTest.
@Test
public void moveConversationPreviousFolderTest() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
// setup: add the root message
ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
Message msg1 = mbox.addMessage(null, pm, dopt, null);
Folder.FolderOptions fopt = new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE);
int folder1Id = mbox.createFolder(null, "folder1", fopt).getId();
ItemId iid1 = new ItemId(mbox, folder1Id);
int folder2Id = mbox.createFolder(null, "folder2", fopt).getId();
new ItemId(mbox, folder2Id);
int folder3Id = mbox.createFolder(null, "folder3", fopt).getId();
ItemId iid3 = new ItemId(mbox, folder3Id);
ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(msg1.getId()), MailItem.Type.MESSAGE, null, iid1);
String msg1PrevFolder = mbox.getLastChangeID() + ":" + Mailbox.ID_FOLDER_INBOX;
Assert.assertEquals(msg1PrevFolder, msg1.getPrevFolders());
dopt = new DeliveryOptions().setFolderId(folder2Id);
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("Re: test subject"), dopt, null);
Assert.assertNull(msg2.getPrevFolders());
Element request = new Element.XMLElement(MailConstants.CONV_ACTION_REQUEST);
request.addElement(MailConstants.E_ACTION).addAttribute(MailConstants.A_OPERATION, ItemAction.OP_MOVE).addAttribute(MailConstants.A_ID, msg1.getConversationId()).addAttribute("l", iid3.getId());
new ConvAction().handle(request, ServiceTestUtil.getRequestContext(acct));
msg1PrevFolder = msg1PrevFolder + ";" + mbox.getLastChangeID() + ":" + folder1Id;
String msg2PrevFolder = mbox.getLastChangeID() + ":" + folder2Id;
Assert.assertEquals(msg1PrevFolder, msg1.getPrevFolders());
Assert.assertEquals(msg2PrevFolder, msg2.getPrevFolders());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class ItemActionTest method mute.
@Test
public void mute() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Assert.assertTrue("root unread", msg.isUnread());
Assert.assertFalse("root not muted", msg.isTagged(Flag.FlagInfo.MUTED));
// mute virtual conv
Element request = new Element.XMLElement(MailConstants.CONV_ACTION_REQUEST);
Element action = request.addElement(MailConstants.E_ACTION).addAttribute(MailConstants.A_OPERATION, ItemAction.OP_MUTE).addAttribute(MailConstants.A_ID, msg.getConversationId());
new ConvAction().handle(request, ServiceTestUtil.getRequestContext(acct));
msg = mbox.getMessageById(null, msg.getId());
Assert.assertFalse("root now read", msg.isUnread());
Assert.assertTrue("root now muted", msg.isTagged(Flag.FlagInfo.MUTED));
// unmute virtual conv
action.addAttribute(MailConstants.A_OPERATION, "!" + ItemAction.OP_MUTE);
new ConvAction().handle(request, ServiceTestUtil.getRequestContext(acct));
msg = mbox.getMessageById(null, msg.getId());
Assert.assertFalse("root still read", msg.isUnread());
Assert.assertFalse("root now unmuted", msg.isTagged(Flag.FlagInfo.MUTED));
// add another message to create a real conv
dopt.setConversationId(msg.getConversationId());
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("Re: test subject"), dopt, null);
Assert.assertTrue("reply unread", msg2.isUnread());
Assert.assertFalse("reply not muted", msg2.isTagged(Flag.FlagInfo.MUTED));
Assert.assertFalse("reply in real conv", msg2.getConversationId() < 0);
// mute real conv
action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_MUTE).addAttribute(MailConstants.A_ID, msg2.getConversationId());
new ConvAction().handle(request, ServiceTestUtil.getRequestContext(acct));
msg2 = mbox.getMessageById(null, msg2.getId());
Assert.assertFalse("reply now read", msg2.isUnread());
Assert.assertTrue("reply now muted", msg2.isTagged(Flag.FlagInfo.MUTED));
// unmute real conv
action.addAttribute(MailConstants.A_OPERATION, "!" + ItemAction.OP_MUTE);
new ConvAction().handle(request, ServiceTestUtil.getRequestContext(acct));
msg2 = mbox.getMessageById(null, msg2.getId());
Assert.assertFalse("reply still read", msg2.isUnread());
Assert.assertFalse("reply now unmuted", msg2.isTagged(Flag.FlagInfo.MUTED));
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class SearchActionTest method testSearchActionMove.
@Test
public void testSearchActionMove() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testMove@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// Add two messages to inbox, one with search match and other with no match
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
TypedIdList ids = mbox.getItemIds(null, 2);
Assert.assertEquals(2, ids.size());
SearchRequest sRequest = new SearchRequest();
sRequest.setSearchTypes("conversation");
// search with query 'test'
sRequest.setQuery("test");
BulkAction bAction = new BulkAction();
// search action - move search result to 'Trash'
bAction.setOp(BulkAction.Operation.move);
bAction.setFolder("Trash");
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
List<SearchHit> searchHits = sResponse.getSearchHits();
SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
// check inbox contains only 1 unmatched mail item after move
List<MailItem> mailItems = mbox.getItemList(null, MailItem.Type.MESSAGE, 2, com.zimbra.cs.index.SortBy.DATE_DESC);
Assert.assertEquals(1, mailItems.size());
Assert.assertEquals("unmatched subject", mailItems.get(0).getSubject());
// check trash contains mail item having 'test subject' after move
mailItems = mbox.getItemList(null, MailItem.Type.MESSAGE, 3, com.zimbra.cs.index.SortBy.DATE_DESC);
Assert.assertEquals(1, mailItems.size());
Assert.assertEquals("test subject", mailItems.get(0).getSubject());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class SearchTest method mute.
@Test
public void mute() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("test@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// setup: add a message
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
Message msg = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
Assert.assertTrue("root unread", msg.isUnread());
Assert.assertTrue("root muted", msg.isTagged(Flag.FlagInfo.MUTED));
// search for the conversation (normal)
Element request = new Element.XMLElement(MailConstants.SEARCH_REQUEST).addAttribute(MailConstants.A_SEARCH_TYPES, "conversation");
request.addAttribute(MailConstants.E_QUERY, "test", Element.Disposition.CONTENT);
Element response = new Search().handle(request, ServiceTestUtil.getRequestContext(acct));
List<Element> hits = response.listElements(MailConstants.E_CONV);
Assert.assertEquals("1 hit", 1, hits.size());
Assert.assertEquals("correct hit", msg.getConversationId(), hits.get(0).getAttributeLong(MailConstants.A_ID));
// search for the conversation (no muted items)
request.addAttribute(MailConstants.A_INCLUDE_TAG_MUTED, false);
response = new Search().handle(request, ServiceTestUtil.getRequestContext(acct));
hits = response.listElements(MailConstants.E_CONV);
Assert.assertTrue("no hits", hits.isEmpty());
}
use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.
the class SearchTest method testZCS3705.
@Test
public void testZCS3705() throws Exception {
Account acct = Provisioning.getInstance().getAccountByName("testZCS3705@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
// add two messages - msg1 and msg2
DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
Message msg1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("read subject"), dopt, null);
Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("unread subject"), dopt, null);
Assert.assertTrue("msg unread", msg1.isUnread());
Assert.assertTrue("msg unread", msg2.isUnread());
// read msg1
Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
Element action = request.addElement(MailConstants.E_MSG);
action.addAttribute(MailConstants.A_ID, msg1.getId());
action.addAttribute(MailConstants.A_MARK_READ, 1);
new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
Assert.assertFalse("msg read", msg1.isUnread());
Assert.assertTrue("msg unread", msg2.isUnread());
// search for the conversation (sortBy readDesc) - msg2 should be listed before msg1
Element searchRequest = new Element.XMLElement(MailConstants.SEARCH_REQUEST).addAttribute(MailConstants.A_SEARCH_TYPES, "conversation");
searchRequest.addAttribute(MailConstants.E_QUERY, "subject", Element.Disposition.CONTENT);
searchRequest.addAttribute("sortBy", "readDesc");
Element searchResponse = new Search().handle(searchRequest, ServiceTestUtil.getRequestContext(acct));
List<Element> hits = searchResponse.listElements(MailConstants.E_CONV);
Assert.assertEquals("2 hits", 2, hits.size());
Assert.assertEquals("correct hit", msg2.getConversationId(), hits.get(0).getAttributeLong(MailConstants.A_ID));
Assert.assertEquals("correct hit", msg1.getConversationId(), hits.get(1).getAttributeLong(MailConstants.A_ID));
// search for the conversation (sortBy unreadDesc) - msg1 should be listed before msg2
searchRequest = new Element.XMLElement(MailConstants.SEARCH_REQUEST).addAttribute(MailConstants.A_SEARCH_TYPES, "conversation");
searchRequest.addAttribute(MailConstants.E_QUERY, "subject", Element.Disposition.CONTENT);
searchRequest.addAttribute("sortBy", "readAsc");
searchResponse = new Search().handle(searchRequest, ServiceTestUtil.getRequestContext(acct));
hits = searchResponse.listElements(MailConstants.E_CONV);
Assert.assertEquals("2 hits", 2, hits.size());
Assert.assertEquals("correct hit", msg1.getConversationId(), hits.get(0).getAttributeLong(MailConstants.A_ID));
Assert.assertEquals("correct hit", msg2.getConversationId(), hits.get(1).getAttributeLong(MailConstants.A_ID));
}
Aggregations