public static Element encodeFolder(Element parent, ZimbraSoapContext lc, Folder folder, int fields) { if (folder instanceof SearchFolder) return encodeSearchFolder(parent, lc, (SearchFolder) folder, fields); else if (folder instanceof Mountpoint) return encodeMountpoint(parent, lc, (Mountpoint) folder, fields);  Element elem = parent.addElement(MailService.E_FOLDER); encodeFolderCommon(elem, lc, folder, fields); if (needToOutput(fields, Change.MODIFIED_SIZE)) { long size = folder.getSize(); if (size > 0 || fields != NOTIFY_FIELDS) elem.addAttribute(MailService.A_SIZE, size); } if (needToOutput(fields, Change.MODIFIED_MSG_COUNT)) { int msgs = folder.getMessageCount(); if (msgs > 0 || fields != NOTIFY_FIELDS) elem.addAttribute(MailService.A_NUM, msgs); } if (needToOutput(fields, Change.MODIFIED_URL)) { String url = folder.getUrl(); if (!url.equals("") || fields != NOTIFY_FIELDS) { if (url.indexOf('@') != -1) try { HttpURL httpurl = new HttpURL(url); if (httpurl.getPassword() != null) { httpurl.setPassword(""); url = httpurl.toString(); } } catch (org.apache.commons.httpclient.URIException urie) { } elem.addAttribute(MailService.A_URL, url); } } boolean remote = lc.isDelegatedRequest(), canAdminister = !remote; if (remote) {  try { Mailbox.OperationContext octxt = lc.getOperationContext(); short perms = folder.getMailbox().getEffectivePermissions(octxt, folder.getId(), MailItem.TYPE_FOLDER); elem.addAttribute(MailService.A_RIGHTS, ACL.rightsToString(perms)); canAdminister = (perms & ACL.RIGHT_ADMIN) != 0; } catch (ServiceException e) { mLog.warn("ignoring exception while fetching effective permissions for folder " + folder.getId(), e); } } if (canAdminister) {  if (needToOutput(fields, Change.MODIFIED_ACL)) { ACL acl = folder.getPermissions(); if (acl != null || fields != NOTIFY_FIELDS) { Element eACL = elem.addUniqueElement(MailService.E_ACL); if (acl != null) for (Iterator it = acl.grantIterator(); it.hasNext(); ) { ACL.Grant grant = (ACL.Grant) it.next(); NamedEntry nentry = FolderAction.lookupGranteeByZimbraId(grant.getGranteeId(), grant.getGranteeType()); eACL.addElement(MailService.E_GRANT) .addAttribute(MailService.A_ZIMBRA_ID, grant.getGranteeId()) .addAttribute(MailService.A_GRANT_TYPE, FolderAction.typeToString(grant.getGranteeType())) .addAttribute(MailService.A_INHERIT, grant.isGrantInherited()) .addAttribute(MailService.A_RIGHTS, ACL.rightsToString(grant.getGrantedRights())) .addAttribute(MailService.A_DISPLAY, nentry == null ? null : nentry.getName()); } } } } return elem;
public static Element encodeFolder(Element parent, ZimbraSoapContext lc, Folder folder) { return encodeFolder(parent, lc, folder, NOTIFY_FIELDS);
    public static Element encodeFolder(Element parent, ZimbraSoapContext lc, Folder folder, int fields) {        if (folder instanceof SearchFolder)            return encodeSearchFolder(parent, lc, (SearchFolder) folder, fields);        else if (folder instanceof Mountpoint)            return encodeMountpoint(parent, lc, (Mountpoint) folder, fields);        Element elem = parent.addElement(MailService.E_FOLDER);        encodeFolderCommon(elem, lc, folder, fields);        if (needToOutput(fields, Change.MODIFIED_SIZE)) {            long size = folder.getSize();            if (size > 0 || fields != NOTIFY_FIELDS)                elem.addAttribute(MailService.A_SIZE, size);        }        if (needToOutput(fields, Change.MODIFIED_MSG_COUNT)) {            int msgs = folder.getMessageCount();            if (msgs > 0 || fields != NOTIFY_FIELDS)                elem.addAttribute(MailService.A_NUM, msgs);        }        if (needToOutput(fields, Change.MODIFIED_URL)) {            String url = folder.getUrl();            if (!url.equals("") || fields != NOTIFY_FIELDS) {                if (url.indexOf('@') != -1)                    try {                        HttpURL httpurl = new HttpURL(url);                        if (httpurl.getPassword() != null) {                            httpurl.setPassword("");                            url = httpurl.toString();                        }                    } catch (org.apache.commons.httpclient.URIException urie) { }                    elem.addAttribute(MailService.A_URL, url);            }        }        boolean remote = lc.isDelegatedRequest(), canAdminister = !remote;        if (remote) {            // return only effective permissions for remote folders            try {                Mailbox.OperationContext octxt = lc.getOperationContext();                short perms = folder.getMailbox().getEffectivePermissions(octxt, folder.getId(), MailItem.TYPE_FOLDER);                elem.addAttribute(MailService.A_RIGHTS, ACL.rightsToString(perms));                canAdminister = (perms & ACL.RIGHT_ADMIN) != 0;            } catch (ServiceException e) {                mLog.warn("ignoring exception while fetching effective permissions for folder " + folder.getId(), e);            }        }        if (canAdminister) {            // return full ACLs for folders we have admin rights on            if (needToOutput(fields, Change.MODIFIED_ACL)) {                ACL acl = folder.getPermissions();                if (acl != null || fields != NOTIFY_FIELDS) {                    Element eACL = elem.addUniqueElement(MailService.E_ACL);                    if (acl != null)                        for (Iterator it = acl.grantIterator(); it.hasNext(); ) {                            ACL.Grant grant = (ACL.Grant) it.next();                            NamedEntry nentry = FolderAction.lookupGranteeByZimbraId(grant.getGranteeId(), grant.getGranteeType());                            eACL.addElement(MailService.E_GRANT)                            .addAttribute(MailService.A_ZIMBRA_ID, grant.getGranteeId())                            .addAttribute(MailService.A_GRANT_TYPE, FolderAction.typeToString(grant.getGranteeType()))                            .addAttribute(MailService.A_INHERIT, grant.isGrantInherited())                            .addAttribute(MailService.A_RIGHTS, ACL.rightsToString(grant.getGrantedRights()))                            .addAttribute(MailService.A_DISPLAY, nentry == null ? null : nentry.getName());                        }                }            }        }        return elem;    }