Search in sources :

Example 6 with ZimbraQueryHitResults

use of com.zimbra.common.mailbox.ZimbraQueryHitResults in project zm-mailbox by Zimbra.

the class TestZClient method searchImapWithCursor.

@Test(timeout = 50000)
public void searchImapWithCursor() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    assertNotNull("ZMailbox", zmbox);
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    int numMsgs = 400;
    for (int i = 0; i < numMsgs; i++) {
        TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "same subject");
    }
    // A simple in:INBOX search worked fine but this complex search doesn't
    ZimbraSearchParams params = zmbox.createSearchParams("in:\"INBOX\" (item:{266--399} -tag:\\Deleted)");
    params.setIncludeTagDeleted(true);
    params.setMailItemTypes(MailItem.Type.toCommon(ImapMessage.SUPPORTED_TYPES));
    params.setZimbraSortBy(ZimbraSortBy.dateAsc);
    params.setLimit(10);
    /* Small sized window */
    params.setPrefetch(false);
    params.setZimbraFetchMode(ZimbraFetchMode.IDS);
    int numHits = 0;
    try (ZimbraQueryHitResults zqr = zmbox.searchImap((OpContext) null, params)) {
        for (ZimbraQueryHit hit = zqr.getNext(); hit != null; hit = zqr.getNext()) {
            numHits++;
        }
    } catch (Exception e) {
        throw ServiceException.FAILURE("failure opening search folder", e);
    }
    assertEquals("Number of hits", 399 - 266 + 1, numHits);
}
Also used : ZimbraQueryHitResults(com.zimbra.common.mailbox.ZimbraQueryHitResults) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) ZimbraQueryHit(com.zimbra.common.mailbox.ZimbraQueryHit) ZMountpoint(com.zimbra.client.ZMountpoint) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) ZClientException(com.zimbra.common.zclient.ZClientException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) MessagingException(javax.mail.MessagingException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) Test(org.junit.Test)

Aggregations

ZimbraQueryHitResults (com.zimbra.common.mailbox.ZimbraQueryHitResults)6 ZimbraQueryHit (com.zimbra.common.mailbox.ZimbraQueryHit)4 ServiceException (com.zimbra.common.service.ServiceException)4 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 ZMailbox (com.zimbra.client.ZMailbox)3 ZMountpoint (com.zimbra.client.ZMountpoint)3 Test (org.junit.Test)3 ZSearchParams (com.zimbra.client.ZSearchParams)2 ZTag (com.zimbra.client.ZTag)2 MailboxStore (com.zimbra.common.mailbox.MailboxStore)2 ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 ArrayList (java.util.ArrayList)2 ZContact (com.zimbra.client.ZContact)1 ZFolder (com.zimbra.client.ZFolder)1 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)1 ZMessage (com.zimbra.client.ZMessage)1 MailItemType (com.zimbra.common.mailbox.MailItemType)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1