throw ServiceException.FAILURE("unable to search GAL", e);
throw ServiceException.FAILURE("unable to search GAL: "+query, e);
    private SearchGalResult searchZimbraWithQuery(Domain d, String query, int maxResults, String token)        throws ServiceException     {        LdapDomain ld = (LdapDomain) d;        SearchGalResult result = new SearchGalResult();        result.matches = new ArrayList<GalContact>();        if (query == null)            return result;        // filter out hidden entries        query = "(&("+query+")(!(zimbraHideInGal=TRUE)))";        LdapGalMapRules rules = getGalRules(d);        SearchControls sc = new SearchControls(SearchControls.SUBTREE_SCOPE, maxResults, 0, rules.getLdapAttrs(), false, false);        result.token = token != null ? token : LdapUtil.EARLIEST_SYNC_TOKEN;        DirContext ctxt = null;        NamingEnumeration ne = null;        try {            ctxt = LdapUtil.getDirContext(false);            String searchBase = d.getAttr(Provisioning.A_zimbraGalInternalSearchBase, "DOMAIN");            if (searchBase.equalsIgnoreCase("DOMAIN"))                searchBase = "ou=people,"+ld.getDN();            else if (searchBase.equalsIgnoreCase("SUBDOMAINS"))                searchBase = ld.getDN();            else if (searchBase.equalsIgnoreCase("ROOT"))                searchBase = "";            ne = ctxt.search(searchBase, query, sc);            while (ne.hasMore()) {                SearchResult sr = (SearchResult) ne.next();                String dn = sr.getNameInNamespace();                GalContact lgc = new GalContact(dn, rules.apply(sr.getAttributes()));                 String mts = (String) lgc.getAttrs().get("modifyTimeStamp");                result.token = LdapUtil.getLaterTimestamp(result.token, mts);                String cts = (String) lgc.getAttrs().get("createTimeStamp");                result.token = LdapUtil.getLaterTimestamp(result.token, cts);                result.matches.add(lgc);            }            ne.close();            ne = null;        } catch (SizeLimitExceededException sle) {            result.hadMore = true;        } catch (NamingException e) {            throw ServiceException.FAILURE("unable to search GAL", e);        } finally {            LdapUtil.closeEnumContext(ne);            LdapUtil.closeContext(ctxt);        }        //Collections.sort(result);        return result;    }