UsernamePasswordCredentials creds = new UsernamePasswordCredentials(httpurl.getUser(), httpurl.getPassword());
String user = httpurl.getUser(); if (user.indexOf('%') != -1) try { user = URLDecoder.decode(httpurl.getUser()); } catch (Throwable t) { } UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, httpurl.getPassword());
    public static SubscriptionData retrieveRemoteDatasource(Account acct, String url, Folder.SyncData fsd) throws ServiceException {        HttpClient client = new HttpClient();        NetUtil.configureProxy(client);        client.setConnectionTimeout(10000);        client.setTimeout(20000);        HttpMethodParams params = new HttpMethodParams();        params.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, Mime.P_CHARSET_UTF8);        GetMethod get = null;        BufferedInputStream content = null;        try {            String expectedCharset = Mime.P_CHARSET_UTF8;            int redirects = 0;            do {                if (url == null || url.equals(""))                    return new SubscriptionData();                String lcurl = url.toLowerCase();                if (lcurl.startsWith("webcal:"))                    url = "http:" + url.substring(7);                else if (lcurl.startsWith("feed:"))                    url = "http:" + url.substring(5);                else if (!lcurl.startsWith("http:") && !lcurl.startsWith("https:"))                    throw ServiceException.INVALID_REQUEST("url must begin with http: or https:", null);                // username and password are encoded in the URL as http://user:pass@host/...                if (url.indexOf('@') != -1) {                    HttpURL httpurl = lcurl.startsWith("https:") ? new HttpsURL(url) : new HttpURL(url);                    if (httpurl.getUser() != null) {                        UsernamePasswordCredentials creds = new UsernamePasswordCredentials(httpurl.getUser(), httpurl.getPassword());                        client.getState().setCredentials(AuthScope.ANY, creds);                    }                }                get = new GetMethod(url);                get.setParams(params);                get.setFollowRedirects(true);                get.setDoAuthentication(true);                get.addRequestHeader("User-Agent", HTTP_USER_AGENT);                get.addRequestHeader("Accept", HTTP_ACCEPT);                client.executeMethod(get);                Header locationHeader = get.getResponseHeader("location");                if (locationHeader != null) {                    // update our target URL and loop again to do another HTTP GET                    url = locationHeader.getValue();                    get.releaseConnection();                } else if (get.getStatusCode() != HttpServletResponse.SC_OK) {                    throw ServiceException.RESOURCE_UNREACHABLE(get.getStatusLine().toString(), null);                } else {                    content = new BufferedInputStream(get.getResponseBodyAsStream());                    expectedCharset = get.getResponseCharSet();                    break;                }            } while (++redirects <= MAX_REDIRECTS);            if (redirects > MAX_REDIRECTS)                throw ServiceException.TOO_MANY_HOPS();            StringBuilder charset = new StringBuilder(expectedCharset);            switch (getLeadingChar(content, charset)) {                case -1:                    throw ServiceException.PARSE_ERROR("empty body in response when fetching remote subscription", null);                case '<':                    return parseRssFeed(Element.parseXML(content), fsd);                case 'B':  case 'b':                    Reader reader = new InputStreamReader(content, charset.toString());                    ZVCalendar ical = ZCalendarBuilder.build(reader);                    List<Invite> invites = Invite.createFromCalendar(acct, null, ical, false);                    // handle missing UIDs on remote calendars by generating them as needed                    for (Invite inv : invites)                    	if (inv.getUid() == null)                    		inv.setUid(LdapUtil.generateUUID());                    return new SubscriptionData(invites);                default:                    throw ServiceException.PARSE_ERROR("unrecognized remote content", null);            }        } catch (org.dom4j.DocumentException e) {            throw ServiceException.PARSE_ERROR("could not parse feed", e);        } catch (HttpException e) {            throw ServiceException.RESOURCE_UNREACHABLE("HttpException: " + e, e);        } catch (IOException e) {            throw ServiceException.RESOURCE_UNREACHABLE("IOException: " + e, e);        } finally {            if (get != null)                get.releaseConnection();        }    }