Search in sources :

Example 51 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemQueryTest method testNoneItemsQuery.

@Test
public void testNoneItemsQuery() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery("item:{none}");
    sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 0, hits.size());
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 52 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemQueryTest method testListOfItemsQuery.

@Test
public void testListOfItemsQuery() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD);
    Message msg1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
    Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery(String.format("item:{%d,%d}", msg1.getId(), msg3.getId()));
    sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
    int msgId = Integer.parseInt(hits.get(0).getId());
    Assert.assertEquals("correct hit 1", msg1.getId(), msgId);
    msgId = Integer.parseInt(hits.get(1).getId());
    Assert.assertEquals("correct hit 2", msg3.getId(), msgId);
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SearchResponse(com.zimbra.soap.mail.message.SearchResponse) Test(org.junit.Test)

Example 53 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemActionTest method deleteAllTagKeepsStatusOfFlags.

@Test
public void deleteAllTagKeepsStatusOfFlags() throws Exception {
    // Bug 76781
    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);
    mbox.addMessage(null, pm, dopt, null);
    // add additional messages for conversation
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    int msgId = mbox.addMessage(null, pm, dopt, null).getId();
    // set flag to unread for  this message
    MailboxTestUtil.setFlag(mbox, msgId, Flag.FlagInfo.UNREAD);
    MailItem item = mbox.getItemById(null, msgId, MailItem.Type.UNKNOWN);
    // verify message unread flag is set
    Assert.assertEquals("Verifying Unread flag is set.", Flag.BITMASK_UNREAD, item.getFlagBitmask());
    // add 2 tags
    mbox.alterTag(null, msgId, MailItem.Type.MESSAGE, tag1, true, null);
    mbox.alterTag(null, msgId, MailItem.Type.MESSAGE, tag2, true, null);
    Element request = new Element.XMLElement(MailConstants.ITEM_ACTION_REQUEST);
    Element action = request.addElement(MailConstants.E_ACTION);
    action.addAttribute(MailConstants.A_OPERATION, ItemAction.OP_UPDATE);
    action.addAttribute(MailConstants.A_ITEM_TYPE, "");
    action.addAttribute(MailConstants.A_ID, msgId);
    new ItemAction().handle(request, ServiceTestUtil.getRequestContext(acct));
    Assert.assertEquals("Verifying unread flag is set after tag deletion", Flag.BITMASK_UNREAD, item.getFlagBitmask());
    Tag tag = mbox.getTagByName(null, tag1);
    Assert.assertEquals(tag1 + " (tag messages)", 0, tag.getSize());
    tag = mbox.getTagByName(null, tag2);
    Assert.assertEquals(tag1 + " (tag messages)", 0, tag.getSize());
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) Tag(com.zimbra.cs.mailbox.Tag) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 54 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemActionTest method copyMessageFromDraftsToSent.

@Test
public void copyMessageFromDraftsToSent() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    ParsedMessage pm = MailboxTestUtil.generateMessage("test subject copyMessageFromDraftsToSent");
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_DRAFTS);
    int msgId = mbox.addMessage(null, pm, dopt, null).getId();
    ItemId iidTarget = new ItemId(mbox, Mailbox.ID_FOLDER_SENT);
    ItemActionHelper op = ItemActionHelper.COPY(null, mbox, SoapProtocol.Soap12, Arrays.asList(msgId), MailItem.Type.MESSAGE, null, iidTarget);
    Assert.assertNotNull("test non-null response", op);
    Assert.assertTrue("test CopyActionResult", op.getResult() instanceof CopyActionResult);
    CopyActionResult copyActionResult = (CopyActionResult) op.getResult();
    Assert.assertNotNull("test non-null success info", copyActionResult.getSuccessIds());
    Assert.assertEquals("test correct success count", 1, copyActionResult.getSuccessIds().size());
    ItemId iid = new ItemId(copyActionResult.getCreatedIds().get(0), acct.getId());
    Assert.assertNotNull("test non-null created info", iid);
    Message copiedMessage = mbox.getMessageById(null, iid.getId());
    Assert.assertNotNull("test non-null message", copiedMessage);
    Assert.assertNotNull("test non-null subject in copied message", copiedMessage.getSubject());
    Assert.assertEquals("test subject copyMessageFromDraftsToSent", copiedMessage.getSubject());
    Assert.assertEquals("test parent folder of copied message", Mailbox.ID_FOLDER_SENT, copiedMessage.getFolderId());
}
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) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 55 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemActionTest method moveConversationToAcctRelativePath.

@Test
public void moveConversationToAcctRelativePath() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
    ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int msgId = mbox.addMessage(null, pm, dopt, null).getId();
    String targetFolderName = "folder1";
    ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(msgId * -1), null, targetFolderName);
    Folder newFolder = mbox.getFolderByName(null, Mailbox.ID_FOLDER_USER_ROOT, targetFolderName);
    Message msg = mbox.getMessageById(null, msgId);
    Assert.assertEquals(msg.getFolderId(), newFolder.getId());
}
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) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Folder(com.zimbra.cs.mailbox.Folder) 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