sb.append(scheme).append(hostname).append(":").append(port).append(path);
sb.append(scheme).append(hostname); if (printPort) sb.append(":").append(port); sb.append(path);
    public static String getMailURL(Server server, String path, boolean preferSSL) throws ServiceException {        String hostname = server.getAttr(Provisioning.A_zimbraServiceHostname);        if (hostname == null) {            throw ServiceException.INVALID_REQUEST("server " + server.getName() + " does not have " + Provisioning.A_zimbraServiceHostname, null);        }                String modeString = server.getAttr(Provisioning.A_zimbraMailMode, null);        if (modeString == null) {            throw ServiceException.INVALID_REQUEST("server " + server.getName() + " does not have " + Provisioning.A_zimbraMailMode + " set, maybe it is not a store server?", null);        }                Provisioning.MAIL_MODE mode;        try {            mode = Provisioning.MAIL_MODE.valueOf(modeString);        } catch (IllegalArgumentException iae) {            throw ServiceException.INVALID_REQUEST("server " + server.getName() + " has invalid " + Provisioning.A_zimbraMailMode + ": " + modeString, iae);        }                boolean ssl;                switch (mode) {        case both:        case mixed:            ssl = preferSSL;            break;        case https:            ssl = true;            break;        case http:            ssl = false;            break;        default:            throw ServiceException.INVALID_REQUEST("server " + server.getName() + " has unknown " + Provisioning.A_zimbraMailMode + ": " + mode, null);        }                String scheme;        int port = 0;        if (ssl) {            scheme = SCHEME_HTTPS;            port = server.getIntAttr(Provisioning.A_zimbraMailSSLPort, 0);            if (port < 1) {                throw ServiceException.INVALID_REQUEST("server " + server.getName() + " has invalid " + Provisioning.A_zimbraMailSSLPort + ": " + port, null);            }        } else {            scheme = SCHEME_HTTP;            port = server.getIntAttr(Provisioning.A_zimbraMailPort, 0);            if (port < 1) {                throw ServiceException.INVALID_REQUEST("server " + server.getName() + " has invalid " + Provisioning.A_zimbraMailPort + ": " + port, null);            }        }        StringBuffer sb = new StringBuffer(128);        sb.append(scheme).append(hostname).append(":").append(port).append(path);        return sb.toString();    }