accounts = d.searchAccounts(query, attrs, sortBy, sortAscending, flags);
accounts = prov.searchAccounts(d, query, attrs, sortBy, sortAscending, flags);
    public Element handle(Element request, Map<String, Object> context) throws ServiceException {        ZimbraSoapContext lc = getZimbraSoapContext(context);        Provisioning prov = Provisioning.getInstance();        String query = request.getAttribute(AdminService.E_QUERY);        int limit = (int) request.getAttributeLong(AdminService.A_LIMIT, Integer.MAX_VALUE);        if (limit == 0)            limit = Integer.MAX_VALUE;        int offset = (int) request.getAttributeLong(AdminService.A_OFFSET, 0);                String domain = request.getAttribute(AdminService.A_DOMAIN, null);        boolean applyCos = request.getAttributeBool(AdminService.A_APPLY_COS, true);        String attrsStr = request.getAttribute(AdminService.A_ATTRS, null);        String sortBy = request.getAttribute(AdminService.A_SORT_BY, null);                String types = request.getAttribute(AdminService.A_TYPES, "accounts");        boolean sortAscending = request.getAttributeBool(AdminService.A_SORT_ASCENDING, true);                int flags = 0;                if (types.indexOf("accounts") != -1) flags |= Provisioning.SA_ACCOUNT_FLAG;        if (types.indexOf("aliases") != -1) flags |= Provisioning.SA_ALIAS_FLAG;        if (types.indexOf("distributionlists") != -1) flags |= Provisioning.SA_DISTRIBUTION_LIST_FLAG;        if (types.indexOf("resources") != -1) flags |= Provisioning.SA_CALENDAR_RESOURCE_FLAG;        if (types.indexOf("domains") != -1) flags |= Provisioning.SA_DOMAIN_FLAG;        String[] attrs = attrsStr == null ? null : attrsStr.split(",");        // if we are a domain admin only, restrict to domain        if (isDomainAdminOnly(lc)) {            if ((flags & Provisioning.SA_DOMAIN_FLAG) == Provisioning.SA_DOMAIN_FLAG)                throw ServiceException.PERM_DENIED("can not search for domains");            if (domain == null) {                domain = getAuthTokenAccountDomain(lc).getName();            } else {                if (!canAccessDomain(lc, domain))                     throw ServiceException.PERM_DENIED("can not access domain");             }        }        Domain d = null;        if (domain != null) {            d = prov.get(DomainBy.NAME, domain);            if (d == null)                throw AccountServiceException.NO_SUCH_DOMAIN(domain);        }        List accounts;        AdminSession session = (AdminSession) lc.getSession(SessionCache.SESSION_ADMIN);        if (session != null) {            accounts = session.searchAccounts(d, query, attrs, sortBy, sortAscending, flags, offset);        } else {            if (d != null) {                accounts = d.searchAccounts(query, attrs, sortBy, sortAscending, flags);            } else {                accounts = prov.searchAccounts(query, attrs, sortBy, sortAscending, flags);            }        }        Element response = lc.createElement(AdminService.SEARCH_ACCOUNTS_RESPONSE);        int i, limitMax = offset+limit;        for (i=offset; i < limitMax && i < accounts.size(); i++) {            NamedEntry entry = (NamedEntry) accounts.get(i);        	if (entry instanceof CalendarResource) {            ToXML.encodeCalendarResource(response, (CalendarResource) entry, applyCos);        	} else if (entry instanceof Account) {                ToXML.encodeAccount(response, (Account) entry, applyCos);            } else if (entry instanceof DistributionList) {                doDistributionList(response, (DistributionList) entry);            } else if (entry instanceof Alias) {                doAlias(response, (Alias) entry);            } else if (entry instanceof Domain) {                GetDomain.doDomain(response, (Domain) entry, applyCos);            }        }                  response.addAttribute(AdminService.A_MORE, i < accounts.size());        response.addAttribute(AdminService.A_SEARCH_TOTAL, accounts.size());                return response;    }