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;
}
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);
}
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;
}
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);
}
Aggregations