Search in sources :

Example 1 with ZSearchHit

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

the class TestSearchHeaders method testSearchNonTopLevelHeaders.

@Test
public void testSearchNonTopLevelHeaders() throws ServiceException {
    ZSearchParams params = new ZSearchParams("\"header search test\" #Content-Transfer-Encoding:8bit");
    params.setTypes("message");
    ZSearchResult result = mbox.search(params);
    boolean found = false;
    for (ZSearchHit hit : result.getHits()) {
        if (found == false && hit.getId().equals(id)) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams) Test(org.junit.Test)

Example 2 with ZSearchHit

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

the class TestDataSource method testPop3.

@Test
public void testPop3() throws Exception {
    Account pop3acct = TestUtil.getAccount(TEST_USER_NAME);
    ZMailbox pop3mbox = TestUtil.getZMailbox(TEST_USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String pop3DSFolder = NAME_PREFIX + " testPop3 source";
    String pop3DSFolderId = createFolderForDataSource(mbox, pop3DSFolder);
    String dsId = createPop3DataSource(mbox, pop3acct.getName(), pop3DSFolderId);
    String subj = NAME_PREFIX + " testtrashpop3";
    addMessage(pop3mbox, subj, "test");
    refreshPop3DatasourceData(mbox, dsId);
    ZSearchParams params = new ZSearchParams(String.format("subject:\"%s\"", subj));
    params.setTypes("MESSAGE");
    ZSearchResult result = mbox.search(params);
    ZSearchHit hit = result.getHits().get(0);
    String id = hit.getId();
    try {
        mbox.trashMessage(id);
    } catch (SoapFaultException sfe) {
        fail("SoapFaultException caught when deleting item from Pop3 datasource folder - " + sfe.getMessage());
    }
    params = new ZSearchParams("in:Trash");
    params.setTypes("MESSAGE");
    result = mbox.search(params);
    List<ZSearchHit> hits = result.getHits();
    assertEquals(1, hits.size());
    assertEquals(id, hits.get(0).getId());
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) Account(com.zimbra.cs.account.Account) ZSearchHit(com.zimbra.client.ZSearchHit) ZMailbox(com.zimbra.client.ZMailbox) ZSearchParams(com.zimbra.client.ZSearchParams) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 3 with ZSearchHit

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

the class TestUtil method searchMessageIds.

public static List<String> searchMessageIds(ZMailbox mbox, ZSearchParams params) throws ServiceException {
    List<String> msgsIds = new ArrayList<String>();
    ZSearchResult results = mbox.search(params);
    for (ZSearchHit hit : results.getHits()) {
        msgsIds.add(hit.getId());
    }
    return msgsIds;
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ArrayList(java.util.ArrayList)

Example 4 with ZSearchHit

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

the class ZMailboxUtil method dumpConvSearch.

private void dumpConvSearch(ZSearchResult sr, boolean verbose) {
    mConvSearchResult = sr;
    if (verbose) {
        stdout.println(sr.dump());
        return;
    }
    int offset = sr.getOffset();
    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;
    }
    int id_len = 4;
    for (ZSearchHit hit : sr.getHits()) {
        id_len = Math.max(id_len, hit.getId().length());
    }
    Calendar c = Calendar.getInstance();
    String headerFormat = String.format("%%%d.%ds  %%%d.%ds  %%-20.20s  %%-50.50s  %%s%%n", width, width, id_len, id_len);
    //String headerFormat = String.format("%10.10s  %-20.20s  %-50.50s  %-6.6s  %s%n");
    String itemFormat = String.format("%%%d.%ds. %%%d.%ds  %%-20.20s  %%-50.50s  %%tD %%<tR%%n", width, width, id_len, id_len);
    //String itemFormat = "%10.10s  %-20.20s  %-50.50s  %-6.6s  %tD %5$tR%n";
    stdout.format(headerFormat, "", "Id", "From", "Subject", "Date");
    stdout.format(headerFormat, "", "----------------------------------------------------------------------------------------------------", "--------------------", "--------------------------------------------------", "--------------");
    int i = first;
    for (ZSearchHit hit : sr.getHits()) {
        if (hit instanceof ZMessageHit) {
            ZMessageHit mh = (ZMessageHit) hit;
            c.setTimeInMillis(mh.getDate());
            String sub = mh.getSubject();
            String from = mh.getSender().getDisplay();
            mIndexToId.put(i, mh.getId());
            stdout.format(itemFormat, i++, mh.getId(), from, sub, c);
        }
    }
    stdout.println();
}
Also used : ZSearchHit(com.zimbra.client.ZSearchHit) Calendar(java.util.Calendar) ZMessageHit(com.zimbra.client.ZMessageHit) ZMountpoint(com.zimbra.client.ZMountpoint)

Example 5 with ZSearchHit

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

the class TestPurgeDataSource method doSearch.

private List<ZSearchHit> doSearch(String query) throws ServiceException {
    ZSearchParams params = new ZSearchParams(query);
    params.setFetch(Fetch.all);
    params.setSortBy(SearchSortBy.dateDesc);
    ZSearchResult result = mbox.search(params);
    List<ZSearchHit> hits = result.getHits();
    return hits;
}
Also used : ZSearchResult(com.zimbra.client.ZSearchResult) ZSearchHit(com.zimbra.client.ZSearchHit) ZSearchParams(com.zimbra.client.ZSearchParams)

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