boolean isAdmin = uri.getPort() == 7071;  Cookie cookie = new Cookie(uri.getHost(), isAdmin ? ZimbraServlet.COOKIE_ZM_ADMIN_AUTH_TOKEN : ZimbraServlet.COOKIE_ZM_AUTH_TOKEN, mTransport.getAuthToken(), "/", -1, false); HttpState initialState = new HttpState(); initialState.addCookie(cookie); HttpClient client = new HttpClient(); client.setState(initialState); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
HttpClient client = getHttpClient(uri);
    public String uploadAttachments(File[] files, int msTimeout) throws ServiceException {        String aid = null;                URI uri = getUploadURI();        boolean isAdmin = uri.getPort() == 7071; // TODO???                Cookie cookie = new Cookie(uri.getHost(),                         isAdmin ? ZimbraServlet.COOKIE_ZM_ADMIN_AUTH_TOKEN : ZimbraServlet.COOKIE_ZM_AUTH_TOKEN,                         mTransport.getAuthToken(), "/", -1, false);        HttpState initialState = new HttpState();        initialState.addCookie(cookie);        HttpClient client = new HttpClient();        client.setState(initialState);        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);                // make the post        PostMethod post = new PostMethod(uri.toString());        client.getHttpConnectionManager().getParams().setConnectionTimeout(msTimeout);        int statusCode = -1;        try {            Part[] parts = new Part[files.length];            for (int i=0; i < files.length; i++) {                File file = files[i];                String contentType = URLConnection.getFileNameMap().getContentTypeFor(file.getName());                parts[i] = new FilePart(file.getName(), file, contentType, "UTF-8");            }            post.setRequestEntity( new MultipartRequestEntity(parts, post.getParams()) );            statusCode = client.executeMethod(post);            // parse the response            if (statusCode == 200) {                String response = post.getResponseBodyAsString();                aid = getAttachmentId(response);                if (aid == null)                    throw SoapFaultException.FAILURE("Attachment post failed, unable to parse response: " + response, null);            } else {                throw SoapFaultException.FAILURE("Attachment post failed, status=" + statusCode, null);            }        } catch (IOException e) {            throw ZClientException.IO_ERROR(e.getMessage(), e);        } finally {            post.releaseConnection();        }        return aid;    }