Example #1
0
  private static void searchRemoteAccountCalendars(
      Element parent,
      SearchParams params,
      ZimbraSoapContext zsc,
      Account authAcct,
      Map<String, List<Integer>> accountFolders)
      throws ServiceException {
    String nominalTargetAcctId = null; // mail service soap requests want to see a target account
    StringBuilder queryStr = new StringBuilder();
    for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
      String acctId = entry.getKey();
      if (nominalTargetAcctId == null) nominalTargetAcctId = acctId;
      ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
      List<Integer> folderIds = entry.getValue();
      for (int folderId : folderIds) {
        if (queryStr.length() > 0) queryStr.append(" OR ");
        // must quote the qualified folder id
        queryStr.append("inid:\"").append(ifmt.formatItemId(folderId)).append("\"");
      }
    }
    Element req = zsc.createElement(MailConstants.SEARCH_REQUEST);
    req.addAttribute(MailConstants.A_SEARCH_TYPES, MailItem.Type.toString(params.getTypes()));
    if (params.getSortBy() != null) {
      req.addAttribute(MailConstants.A_SORTBY, params.getSortBy().toString());
    }
    req.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    if (params.getLimit() != 0) req.addAttribute(MailConstants.A_QUERY_LIMIT, params.getLimit());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_START, params.getCalItemExpandStart());
    req.addAttribute(MailConstants.A_CAL_EXPAND_INST_END, params.getCalItemExpandEnd());
    req.addAttribute(MailConstants.E_QUERY, queryStr.toString(), Element.Disposition.CONTENT);

    Account target = Provisioning.getInstance().get(Key.AccountBy.id, nominalTargetAcctId);
    String pxyAuthToken = zsc.getAuthToken().getProxyAuthToken();
    ZAuthToken zat = pxyAuthToken == null ? zsc.getRawAuthToken() : new ZAuthToken(pxyAuthToken);
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(target));
    zoptions.setTargetAccount(nominalTargetAcctId);
    zoptions.setTargetAccountBy(AccountBy.id);
    zoptions.setNoSession(true);
    ZMailbox zmbx = ZMailbox.getMailbox(zoptions);

    Element resp = zmbx.invoke(req);
    for (Element hit : resp.listElements()) {
      hit.detach();
      parent.addElement(hit);
    }
  }
Example #2
0
 public void parseSearchParams(Element request, String searchQuery) throws ServiceException {
   if (request == null || mSoapContext == null) {
     createSearchParams(searchQuery);
     return;
   }
   setRequest(request);
   // bug 69338
   // SearchParams.parse relies on A_SEARCH_TYPES on the request to determine search type,
   // which will then determine if cursor should be used to narrow db query.
   // If A_SEARCH_TYPES is not set, default type is conversation, cursor is not used to
   // narrow db query for conversations.   We do not require clients to set types
   // on GAL soap APIs.  Set it to "contact" here.
   request.addAttribute(MailConstants.A_SEARCH_TYPES, MailItem.Type.CONTACT.toString());
   mSearchParams = SearchParams.parse(request, mSoapContext, searchQuery);
   mSearchParams.setTypes(EnumSet.of(MailItem.Type.CONTACT));
   setLimit(mSearchParams.getLimit());
 }
Example #3
0
  private void putHits(
      ZimbraSoapContext zsc,
      OperationContext octxt,
      Element el,
      ZimbraQueryResults results,
      SearchParams params)
      throws ServiceException {

    if (params.getInlineRule() == ExpandResults.HITS) {
      // "hits" is not a valid value for Search...
      params.setInlineRule(ExpandResults.NONE);
    }

    ResultsPager pager = ResultsPager.create(results, params);
    if (params.getCursor() != null) {
      if (params.getCursor().isIncludeOffset()) {
        long offset = pager.getCursorOffset();
        if (offset >= 0) {
          el.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
        }
      }
    } else {
      el.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    }

    SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
    resp.setIncludeMailbox(false);
    resp.setSortOrder(pager.getSortOrder());

    while (pager.hasNext() && resp.size() < params.getLimit()) {
      ZimbraHit hit = pager.getNextHit();
      resp.add(hit);
    }

    resp.addHasMore(pager.hasNext());
    resp.add(results.getResultInfo());
  }