Search in sources :

Example 6 with ZSearchHit

use of com.zimbra.client.ZSearchHit in project zm-mailbox by Zimbra.

the class ZMailboxUtil method dumpSearch.

private void dumpSearch(ZSearchResult sr, boolean verbose) {
    if (verbose) {
        stdout.println(sr.dump());
        return;
    }
    int offset = mSearchPage * mSearchParams.getLimit();
    int first = offset + 1;
    int last = offset + sr.getHits().size();
    stdout.printf("num: %d, more: %s%n%n", sr.getHits().size(), sr.hasMore());
    int width = colWidth(last);
    if (sr.getHits().size() == 0) {
        return;
    }
    final int FROM_LEN = 20;
    int id_len = 4;
    for (ZSearchHit hit : sr.getHits()) {
        id_len = Math.max(id_len, hit.getId().length());
    }
    Calendar cal = Calendar.getInstance();
    String headerFormat = String.format("%%%d.%ds  %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%s%%n", width, width, id_len, id_len);
    String itemFormat = String.format("%%%d.%ds. %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%tD %%<tR%%n", width, width, id_len, id_len);
    stdout.format(headerFormat, "", "Id", "Type", "From", "Subject", "Date");
    stdout.format(headerFormat, "", "----------------------------------------------------------------------------------------------------", "----", "--------------------", "--------------------------------------------------", "--------------");
    int i = first;
    for (ZSearchHit hit : sr.getHits()) {
        if (hit instanceof ZConversationHit) {
            ZConversationHit ch = (ZConversationHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String sub = ch.getSubject();
            String from = emailAddrs(ch.getRecipients());
            if (ch.getMessageCount() > 1) {
                String numMsg = " (" + ch.getMessageCount() + ")";
                int space = FROM_LEN - numMsg.length();
                from = ((from.length() < space) ? from : from.substring(0, space)) + numMsg;
            }
            //if (ch.getFragment() != null || ch.getFragment().length() > 0)
            //    sub += " (" + ch.getFragment()+")";
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "conv", from, sub, cal);
        } else if (hit instanceof ZContactHit) {
            ZContactHit ch = (ZContactHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String from = getFirstEmail(ch);
            String sub = ch.getFileAsStr();
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "cont", from, sub, cal);
        } else if (hit instanceof ZMessageHit) {
            ZMessageHit mh = (ZMessageHit) hit;
            cal.setTimeInMillis(mh.getDate());
            String sub = mh.getSubject();
            String from = mh.getSender() == null ? "<none>" : mh.getSender().getDisplay();
            mIndexToId.put(i, mh.getId());
            stdout.format(itemFormat, i++, mh.getId(), "mess", from, sub, cal);
        } else if (hit instanceof ZAppointmentHit) {
            ZAppointmentHit ah = (ZAppointmentHit) hit;
            if (ah.getInstanceExpanded()) {
                cal.setTimeInMillis(ah.getStartTime());
            } else {
                cal.setTimeInMillis(ah.getHitDate());
            }
            String sub = ah.getName();
            String from = "<na>";
            mIndexToId.put(i, ah.getId());
            stdout.format(itemFormat, i++, ah.getId(), ah.getIsTask() ? "task" : "appo", from, sub, cal);
        } else if (hit instanceof ZDocumentHit) {
            ZDocumentHit dh = (ZDocumentHit) hit;
            ZDocument doc = dh.getDocument();
            cal.setTimeInMillis(doc.getModifiedDate());
            String name = doc.getName();
            String editor = doc.getEditor();
            mIndexToId.put(i, dh.getId());
            stdout.format(itemFormat, i++, dh.getId(), doc.isWiki() ? "wiki" : "doc", editor, name, cal);
        }
    }
    stdout.println();
}
Also used : ZSearchHit(com.zimbra.client.ZSearchHit) ZAppointmentHit(com.zimbra.client.ZAppointmentHit) ZContactHit(com.zimbra.client.ZContactHit) ZDocument(com.zimbra.client.ZDocument) Calendar(java.util.Calendar) ZMessageHit(com.zimbra.client.ZMessageHit) ZConversationHit(com.zimbra.client.ZConversationHit) ZMountpoint(com.zimbra.client.ZMountpoint) ZDocumentHit(com.zimbra.client.ZDocumentHit)

Example 7 with ZSearchHit

use of com.zimbra.client.ZSearchHit in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doSearchConvNext.

private void doSearchConvNext() throws ServiceException {
    ZSearchParams sp = mConvSearchParams;
    ZSearchResult sr = mConvSearchResult;
    if (sp == null || sr == null || !sr.hasMore())
        return;
    List<ZSearchHit> hits = sr.getHits();
    if (hits.size() == 0)
        return;
    sp.setOffset(sp.getOffset() + hits.size());
    dumpConvSearch(mMbox.searchConversation(mConvSearchConvId, sp), verboseOpt());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams)

Example 8 with ZSearchHit

use of com.zimbra.client.ZSearchHit in project zm-mailbox by Zimbra.

the class TestDraftCount method deleteFromQuery.

private void deleteFromQuery(String query) throws Exception {
    //delete all messages currently in drafts folder
    ZSearchParams params = new ZSearchParams(query);
    params.setTypes("message");
    params.setOffset(0);
    ZSearchResult results = mbox.search(params);
    for (ZSearchHit hit : results.getHits()) {
        ZMessageHit msg = (ZMessageHit) hit;
        mbox.deleteMessage(hit.getId());
    }
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams) ZMessageHit(com.zimbra.client.ZMessageHit)

Example 9 with ZSearchHit

use of com.zimbra.client.ZSearchHit in project zm-mailbox by Zimbra.

the class TestTrashImapMessage method testTrashImapMessage.

@Test
public void testTrashImapMessage() throws Exception {
    String subj = "testtrashimap";
    addMessage(imapDsMbox1, subj, "test");
    refreshImapData();
    ZSearchParams params = new ZSearchParams("subject:" + subj);
    params.setTypes("MESSAGE");
    ZSearchResult result = mbox.search(params);
    ZSearchHit hit = result.getHits().get(0);
    String id = hit.getId();
    msgIds.add(id);
    mbox.trashMessage(id);
    params = new ZSearchParams("in:\"" + IMAP_DS_1_FOLDER_NAME + "/Trash\"");
    params.setTypes("MESSAGE");
    result = mbox.search(params);
    List<ZSearchHit> hits = result.getHits();
    Assert.assertEquals(1, hits.size());
    Assert.assertEquals(id, hits.get(0).getId());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 10 with ZSearchHit

use of com.zimbra.client.ZSearchHit in project zm-mailbox by Zimbra.

the class TestSearchConv method searchConversation.

@Test
public void searchConversation() throws Exception {
    ZimbraLog.search.debug("test %s", toString());
    markMessagesUnreadByIndex(unread);
    ZSearchParams params = new ZSearchParams(query);
    params.setFetch(fetch);
    ZSearchResult result = mbox.searchConversation(convId, params);
    List<ZSearchHit> hits = result.getHits();
    List<String> expandedList = new ArrayList<String>();
    for (Integer idx : expected) {
        expandedList.add(msgIds.get(idx));
    }
    for (ZSearchHit hit : hits) {
        boolean expanded = isExpanded(hit);
        if (expandedList.contains(hit.getId())) {
            assertTrue(String.format("%s expanded should be true for msgId=%s", toString(), hit.getId()), expanded);
            expandedList.remove(hit.getId());
        } else {
            assertFalse(String.format("%s expanded should be false for msgId=%s", toString(), hit.getId()), expanded);
        }
    }
    assertEquals(String.format("%s expandedList size", toString()), 0, expandedList.size());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ZSearchHit (com.zimbra.client.ZSearchHit)13 ZSearchParams (com.zimbra.client.ZSearchParams)9 ZSearchResult (com.zimbra.client.ZSearchResult)8 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 ZMessageHit (com.zimbra.client.ZMessageHit)3 ZMountpoint (com.zimbra.client.ZMountpoint)2 Calendar (java.util.Calendar)2 ZAppointmentHit (com.zimbra.client.ZAppointmentHit)1 ZContactHit (com.zimbra.client.ZContactHit)1 ZConversationHit (com.zimbra.client.ZConversationHit)1 ZDocument (com.zimbra.client.ZDocument)1 ZDocumentHit (com.zimbra.client.ZDocumentHit)1 ZGetMessageParams (com.zimbra.client.ZGetMessageParams)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZMessage (com.zimbra.client.ZMessage)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1