Search in sources :

Example 16 with Account

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

the class ItemQueryTest method testRangeOfItemsQuery.

@Test
public void testRangeOfItemsQuery() 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);
    Message msg2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject2"), dopt, null);
    Message msg3 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject3"), dopt, null);
    mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject4"), 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", 3, 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", msg2.getId(), msgId);
    msgId = Integer.parseInt(hits.get(2).getId());
    Assert.assertEquals("correct hit 3", 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 17 with Account

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

the class ItemQueryTest method testSyntax.

@Test
public void testSyntax() throws ServiceException {
    Account account = Provisioning.getInstance().getAccountByName("zero@zimbra.com");
    Mailbox mailbox = MailboxManager.getInstance().getMailboxByAccount(account);
    ItemQuery q = (ItemQuery) ItemQuery.create(mailbox, "1,2");
    Assert.assertEquals(String.format("Q(ITEMID,%s:1,%s:2)", MockProvisioning.DEFAULT_ACCOUNT_ID, MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
    q = (ItemQuery) ItemQuery.create(mailbox, "1");
    Assert.assertEquals(String.format("Q(ITEMID,%s:1)", MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
    q = (ItemQuery) ItemQuery.create(mailbox, "all");
    Assert.assertEquals("Q(ITEMID,all)", q.toString());
    q = (ItemQuery) ItemQuery.create(mailbox, "none");
    Assert.assertEquals("Q(ITEMID,none)", q.toString());
    q = (ItemQuery) ItemQuery.create(mailbox, "1--10");
    Assert.assertEquals(String.format("Q(ITEMID,%s:1--%s:10)", MockProvisioning.DEFAULT_ACCOUNT_ID, MockProvisioning.DEFAULT_ACCOUNT_ID), q.toString());
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Test(org.junit.Test)

Example 18 with Account

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

the class TextQueryTest method sortByHasAttach.

@Test
public void sortByHasAttach() throws Exception {
    Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
    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);
    Message msgWithAttach = mbox.addMessage(null, MailboxTestUtil.generateMessageWithAttachment("test subject has attach"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    int msgId;
    int msgWithAttachId;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery("test");
    sr.setSortBy(SortBy.ATTACHMENT_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
    msgId = Integer.parseInt(hits.get(0).getId());
    msgWithAttachId = Integer.parseInt(hits.get(1).getId());
    Assert.assertEquals("correct hit ascending no attachments", msg.getId(), msgId);
    Assert.assertEquals("correct hit ascending has attachments", msgWithAttach.getId(), msgWithAttachId);
    /* Check that we get them in the opposite order if we change the search direction */
    sr.setSortBy(SortBy.ATTACHMENT_DESC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
    msgId = Integer.parseInt(hits.get(1).getId());
    msgWithAttachId = Integer.parseInt(hits.get(0).getId());
    Assert.assertEquals("correct hit descending no attachments", msg.getId(), msgId);
    Assert.assertEquals("correct hit descending has attachments", msgWithAttach.getId(), msgWithAttachId);
}
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 19 with Account

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

the class TextQueryTest method sortByPriority.

@Test
public void sortByPriority() throws Exception {
    Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
    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);
    Message msgWithHighPri = mbox.addMessage(null, MailboxTestUtil.generateHighPriorityMessage("test subject is HI-PRI"), dopt, null);
    Message msgWithLowPri = mbox.addMessage(null, MailboxTestUtil.generateLowPriorityMessage("test subject is LOW-PRI"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    int msgId;
    int msgWithLowPriId;
    int msgWithHiPriId;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery("test");
    sr.setSortBy(SortBy.PRIORITY_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 3, hits.size());
    msgId = Integer.parseInt(hits.get(1).getId());
    msgWithHiPriId = Integer.parseInt(hits.get(2).getId());
    msgWithLowPriId = Integer.parseInt(hits.get(0).getId());
    Assert.assertEquals("correct hit ascending high", msgWithHighPri.getId(), msgWithHiPriId);
    Assert.assertEquals("correct hit ascending med", msg.getId(), msgId);
    Assert.assertEquals("correct hit ascending low", msgWithLowPri.getId(), msgWithLowPriId);
    /* Check that we get them in the opposite order if we change the search direction */
    sr.setSortBy(SortBy.PRIORITY_DESC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 3, hits.size());
    msgId = Integer.parseInt(hits.get(1).getId());
    msgWithHiPriId = Integer.parseInt(hits.get(0).getId());
    msgWithLowPriId = Integer.parseInt(hits.get(2).getId());
    Assert.assertEquals("correct hit descending high", msgWithHighPri.getId(), msgWithHiPriId);
    Assert.assertEquals("correct hit descending med", msg.getId(), msgId);
    Assert.assertEquals("correct hit descending low", msgWithLowPri.getId(), msgWithLowPriId);
}
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 20 with Account

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

the class TextQueryTest method sortByIsFlagged.

@Test
public void sortByIsFlagged() throws Exception {
    Account acct = Provisioning.getInstance().getAccountById(MockProvisioning.DEFAULT_ACCOUNT_ID);
    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);
    dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_FLAGGED);
    Message msgWithFlag = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject flag"), dopt, null);
    SearchResponse resp;
    List<SearchHit> hits;
    int msgId;
    int msgWithFlagId;
    SearchRequest sr = new SearchRequest();
    sr.setSearchTypes("message");
    sr.setQuery("test");
    sr.setSortBy(SortBy.FLAG_ASC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
    msgId = Integer.parseInt(hits.get(0).getId());
    msgWithFlagId = Integer.parseInt(hits.get(1).getId());
    Assert.assertEquals("correct hit ascending unflagged", msg.getId(), msgId);
    Assert.assertEquals("correct hit ascending flagged", msgWithFlag.getId(), msgWithFlagId);
    /* Check that we get them in the opposite order if we change the search direction */
    sr.setSortBy(SortBy.FLAG_DESC.toString());
    resp = doSearch(sr, acct);
    hits = resp.getSearchHits();
    Assert.assertEquals("Number of hits", 2, hits.size());
    msgId = Integer.parseInt(hits.get(1).getId());
    msgWithFlagId = Integer.parseInt(hits.get(0).getId());
    Assert.assertEquals("correct hit descending unflagged", msg.getId(), msgId);
    Assert.assertEquals("correct hit descending flagged", msgWithFlag.getId(), msgWithFlagId);
}
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)

Aggregations

Account (com.zimbra.cs.account.Account)1444 Test (org.junit.Test)691 Mailbox (com.zimbra.cs.mailbox.Mailbox)468 OperationContext (com.zimbra.cs.mailbox.OperationContext)354 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)331 Message (com.zimbra.cs.mailbox.Message)315 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)294 Element (com.zimbra.common.soap.Element)280 ServiceException (com.zimbra.common.service.ServiceException)261 ItemId (com.zimbra.cs.service.util.ItemId)248 Provisioning (com.zimbra.cs.account.Provisioning)234 HashMap (java.util.HashMap)179 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)175 Domain (com.zimbra.cs.account.Domain)149 MimeMessage (javax.mail.internet.MimeMessage)125 GuestAccount (com.zimbra.cs.account.GuestAccount)107 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)100 SyntaxException (org.apache.jsieve.exception.SyntaxException)90 AccountServiceException (com.zimbra.cs.account.AccountServiceException)87 Header (javax.mail.Header)84