Search in sources :

Example 1 with ZimbraSearchParams

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

the class Mailbox method createSearchParams.

@Override
public ZimbraSearchParams createSearchParams(String queryString) {
    SearchParams sp = new SearchParams();
    sp.setQueryString(queryString);
    return sp;
}
Also used : ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) SearchParams(com.zimbra.cs.index.SearchParams)

Example 2 with ZimbraSearchParams

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

the class ImapHandler method runSearch.

private ZimbraQueryHitResults runSearch(ImapSearch i4search, ImapFolder i4folder, SortBy sort, SearchParams.Fetch fetch) throws ImapParseException, ServiceException {
    MailboxStore mbox = i4folder.getMailbox();
    if (mbox == null) {
        throw ServiceException.FAILURE("unexpected session close during search", null);
    }
    Account acct = credentials == null ? null : credentials.getAccount();
    TimeZone tz = acct == null ? null : WellKnownTimeZones.getTimeZoneById(acct.getAttr(Provisioning.A_zimbraPrefTimeZoneId));
    String search;
    mbox.lock(false);
    try {
        search = i4search.toZimbraSearch(i4folder);
        if (!i4folder.isVirtual()) {
            search = "in:" + i4folder.getQuotedPath() + ' ' + search;
        } else if (i4folder.getSize() <= LARGEST_FOLDER_BATCH) {
            search = ImapSearch.sequenceAsSearchTerm(i4folder, i4folder.getAllMessages(), false) + ' ' + search;
        } else {
            search = '(' + i4folder.getQuery() + ") " + search;
        }
        ZimbraLog.imap.info("[ search is: " + search + " ]");
    } finally {
        mbox.unlock();
    }
    ZimbraSearchParams params = mbox.createSearchParams(search);
    params.setIncludeTagDeleted(true);
    params.setMailItemTypes(MailItem.Type.toCommon(i4folder.getTypeConstraint()));
    params.setZimbraSortBy(sort.toZimbraSortBy());
    params.setLimit(2000);
    params.setPrefetch(false);
    params.setZimbraFetchMode(fetch.toZimbraFetchMode());
    params.setTimeZone(tz);
    return mbox.searchImap(getContext(), params);
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) TimeZone(java.util.TimeZone) MailboxStore(com.zimbra.common.mailbox.MailboxStore) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams)

Example 3 with ZimbraSearchParams

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

the class ImapSessionManager method loadVirtualFolder.

/**
 * Fetches the messages contained within a search folder.  When a search folder is IMAP-visible, it appears in
 * folder listings, is SELECTable READ-ONLY, and appears to have all matching messages as its contents.
 * If it is not visible, it will be completely hidden from all IMAP commands.
 * @param octxt   Encapsulation of the authenticated user.
 * @param search  The search folder being exposed.
 */
private static List<ImapMessage> loadVirtualFolder(OperationContext octxt, SearchFolderStore search) throws ServiceException {
    List<ImapMessage> i4list = Lists.newArrayList();
    Set<MailItemType> types = ImapFolder.getMailItemTypeConstraint(search);
    if (types.isEmpty()) {
        return i4list;
    }
    MailboxStore mbox = search.getMailboxStore();
    ZimbraSearchParams params = mbox.createSearchParams(search.getQuery());
    params.setIncludeTagDeleted(true);
    params.setMailItemTypes(types);
    params.setZimbraSortBy(ZimbraSortBy.dateAsc);
    params.setLimit(1000);
    params.setZimbraFetchMode(ZimbraFetchMode.IMAP);
    try {
        ZimbraQueryHitResults zqr = mbox.searchImap(octxt, params);
        try {
            for (ZimbraQueryHit hit = zqr.getNext(); hit != null; hit = zqr.getNext()) {
                i4list.add(new ImapMessage(hit));
            }
        } finally {
            zqr.close();
        }
    } catch (ServiceException e) {
        throw e;
    } catch (Exception e) {
        throw ServiceException.FAILURE("failure opening search folder", e);
    }
    return i4list;
}
Also used : ZimbraQueryHitResults(com.zimbra.common.mailbox.ZimbraQueryHitResults) MailboxStore(com.zimbra.common.mailbox.MailboxStore) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZimbraQueryHit(com.zimbra.common.mailbox.ZimbraQueryHit) MailItemType(com.zimbra.common.mailbox.MailItemType) ServiceException(com.zimbra.common.service.ServiceException) MailboxInMaintenanceException(com.zimbra.cs.mailbox.MailServiceException.MailboxInMaintenanceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 4 with ZimbraSearchParams

use of com.zimbra.common.mailbox.ZimbraSearchParams 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

ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)4 MailboxStore (com.zimbra.common.mailbox.MailboxStore)2 ZimbraQueryHit (com.zimbra.common.mailbox.ZimbraQueryHit)2 ZimbraQueryHitResults (com.zimbra.common.mailbox.ZimbraQueryHitResults)2 ServiceException (com.zimbra.common.service.ServiceException)2 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 ZMailbox (com.zimbra.client.ZMailbox)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 MailItemType (com.zimbra.common.mailbox.MailItemType)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 ZClientException (com.zimbra.common.zclient.ZClientException)1 Account (com.zimbra.cs.account.Account)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 SearchParams (com.zimbra.cs.index.SearchParams)1 MailboxInMaintenanceException (com.zimbra.cs.mailbox.MailServiceException.MailboxInMaintenanceException)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 IOException (java.io.IOException)1 TimeZone (java.util.TimeZone)1