Search in sources :

Example 56 with DeliveryOptions

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());
}
Also used : Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 57 with DeliveryOptions

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));
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 58 with DeliveryOptions

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());
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) SearchHit(com.zimbra.soap.type.SearchHit) Element(com.zimbra.common.soap.Element) BulkAction(com.zimbra.soap.mail.type.BulkAction) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 59 with DeliveryOptions

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());
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) Element(com.zimbra.common.soap.Element) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 60 with DeliveryOptions

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));
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) Element(com.zimbra.common.soap.Element) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Aggregations

DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)73 Mailbox (com.zimbra.cs.mailbox.Mailbox)63 Test (org.junit.Test)57 Message (com.zimbra.cs.mailbox.Message)53 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)51 Account (com.zimbra.cs.account.Account)28 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 ItemId (com.zimbra.cs.service.util.ItemId)13 ServiceException (com.zimbra.common.service.ServiceException)12 Element (com.zimbra.common.soap.Element)12 MimeMessage (javax.mail.internet.MimeMessage)12 Volume (com.zimbra.cs.volume.Volume)11 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)11 SearchHit (com.zimbra.soap.type.SearchHit)10 IOException (java.io.IOException)10 Folder (com.zimbra.cs.mailbox.Folder)9 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)8 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 MailItem (com.zimbra.cs.mailbox.MailItem)6