String queryExpr = LdapDomain.getFilterDef(filter);
String queryExpr = LdapProvisioning.getFilterDef(filter);
    public static SearchGalResult searchLdapGal(            String url[],            String bindDn,            String bindPassword,            String base,            String filter,             String n,            int maxResults,            LdapGalMapRules rules,            String token) throws NamingException, ServiceException {            SearchGalResult result = new SearchGalResult();        result.matches = new ArrayList<GalContact>();            if (url == null || url.length == 0 || base == null || filter == null) {            if (url == null || url.length == 0)                ZimbraLog.misc.warn("searchLdapGal url is null");            if (base == null)                ZimbraLog.misc.warn("searchLdapGal base is null");            if (filter == null)                ZimbraLog.misc.warn("searchLdapGal queryExpr is null");            return result;        }            if (filter.indexOf("(") == -1) {            String queryExpr = LdapDomain.getFilterDef(filter);            if (queryExpr != null)                filter = queryExpr;        }                        Map<String, String> vars = new HashMap<String, String>();        vars.put("s", n);        String query = LdapProvisioning.expandStr(filter, vars);        if (token != null) {            if (token.equals(""))                query = query.replaceAll("\\*\\*", "*");            else  {                String arg = LdapUtil.escapeSearchFilterArg(token);                                query = "(&(|(modifyTimeStamp>="+arg+")(createTimeStamp>="+arg+")(whenModified>="+arg+")(whenCreated>="+arg+"))"+query.replaceAll("\\*\\*", "*")+")";                            }                        }        ZimbraLog.misc.debug("searchLdapGal query:"+query);        SearchControls sc = new SearchControls(SearchControls.SUBTREE_SCOPE, maxResults, 0, rules.getLdapAttrs(), false, false);        result.token = token != null ? token : EARLIEST_SYNC_TOKEN;        DirContext ctxt = null;        try {            ctxt = getDirContext(url, bindDn, bindPassword);            NamingEnumeration ne = ctxt.search(base, query, sc);            while (ne.hasMore()) {                SearchResult sr = (SearchResult) ne.next();                String dn = sr.getNameInNamespace();                LdapGalContact lgc = new LdapGalContact(dn, rules.apply(sr.getAttributes()));                String mts = (String) lgc.getAttrs().get("modifyTimeStamp");                result.token = getLaterTimestamp(result.token, mts);                result.matches.add(lgc);            }            ne.close();        } catch (SizeLimitExceededException sle) {            result.hadMore = true;        } finally {            closeContext(ctxt);        }        return result;    }