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); } }
public Element sendRequest( Element request, boolean requiresAuth, boolean noSession, int timeout, SoapProtocol resProto, Map<String, ElementHandler> saxHandlers, String uri, ZAuthToken authToken, boolean sendAcctId) throws ServiceException { OfflineAccount acct = getOfflineAccount(); SoapHttpTransport transport = new SoapHttpTransport(uri); try { transport.setUserAgent(OfflineLC.zdesktop_name.value(), OfflineLC.getFullVersion()); transport.setTimeout(timeout); if (requiresAuth) transport.setAuthToken(authToken == null ? getAuthToken() : authToken); transport.setRequestProtocol(SoapProtocol.Soap12); if (resProto != null) transport.setResponseProtocol(resProto); if (acct.isDebugTraceEnabled()) { Element elt = null; String pswd = null; if (request.getName().equals(AccountConstants.AUTH_REQUEST.getName())) { elt = request.getElement(AccountConstants.E_PASSWORD); pswd = elt.getText(); elt.setText("*"); } OfflineLog.request.debug(request); if (pswd != null) elt.setText(pswd); } Element response = null; if (saxHandlers != null) { response = transport.invoke( request.detach(), false, true, null, null, null, new SoapHttpTransport.SAXResponseHandler(saxHandlers)); } else if (noSession) { if (sendAcctId) response = transport.invoke(request.detach(), false, true, acct.getId()); else response = transport.invokeWithoutSession(request.detach()); } else { if (mSessionId != null) transport.setSessionId(mSessionId); response = transport.invoke(request.detach()); } if (acct.isDebugTraceEnabled() && response != null) OfflineLog.response.debug(response); // update sessionId if changed if (transport.getSessionId() != null) mSessionId = transport.getSessionId(); return response; } catch (IOException e) { throw ServiceException.PROXY_ERROR(e, uri); } }