boolean isAdminRequest = (req.getServerPort() == ADMIN_PORT);
boolean isAdminRequest = (req.getLocalPort() == ADMIN_PORT);
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {		int status = HttpServletResponse.SC_OK;        List<FileItem> items = null;        String attachmentId = null;        String reqId = null;        do {            // file upload requires authentication            boolean isAdminRequest = (req.getServerPort() == ADMIN_PORT);    		AuthToken authToken = isAdminRequest ? getAdminAuthTokenFromCookie(req, resp, true) : getAuthTokenFromCookie(req, resp, true);            if (authToken == null) {                status = HttpServletResponse.SC_UNAUTHORIZED;                break;            }            if (!isAdminRequest) {                try {                    // make sure we're on the right host; proxy if we're not...                    Provisioning prov = Provisioning.getInstance();                    Account acct = prov.get(AccountBy.id, authToken.getAccountId());                    if (!Provisioning.onLocalServer(acct)) {                        proxyServletRequest(req, resp, prov.getServer(acct), null);                        return;                    }                } catch (ServiceException e) {                    throw new ServletException(e);                }            }            // file upload requires multipart enctype            if (!FileUploadBase.isMultipartContent(req)) {            	status = HttpServletResponse.SC_BAD_REQUEST;                break;            }            DiskFileUpload upload = getUploader();            try {            	items = upload.parseRequest(req);            } catch (FileUploadBase.SizeLimitExceededException e) {                // at least one file was over max allowed size                status = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;                mLog.info("Exceeded maximum upload size of " + upload.getSizeMax() + " bytes: " + e);                break;            } catch (FileUploadBase.InvalidContentTypeException e) {                // at least one file was of a type not allowed                status = HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE;                mLog.info("File upload failed", e);                break;            } catch (FileUploadException e) {            	// parse of request failed for some other reason                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;                mLog.info("File upload failed", e);                break;            }            String lastName = null, charset = "utf-8";            HashMap<FileItem, String> filenames = new HashMap<FileItem, String>();            if (items != null)                for (Iterator<FileItem> it = items.iterator(); it.hasNext(); ) {                    FileItem fi = it.next();                    if (fi == null)                        continue;                    if (fi.isFormField()) {                        // correlate this file upload session's request and response                        if (fi.getFieldName().equals("requestId"))                            reqId = fi.getString();                        // get the form value charset, if specified                        if (fi.getFieldName().equals("_charset_"))                            charset = fi.getString();                        // allow a client to explicitly provide filenames for the uploads                        if (fi.getFieldName().startsWith("filename"))                            lastName = fi.getString(charset);                        // strip form fields out of the list of uploads                        it.remove();                    } else {                        if (fi.getName() == null || fi.getName().trim().equals("")) {                            it.remove();                        } else {                            filenames.put(fi, lastName);                            lastName = null;                        }                    }                }            // empty upload is not a "success"            if (items == null || items.isEmpty()) {                status = HttpServletResponse.SC_NO_CONTENT;                break;            }            // cache the uploaded files in the hash and construct the list of upload IDs            try {                for (FileItem fi : items) {                    String name = filenames.get(fi);                    if (name == null || name.trim().equals(""))                        name = fi.getName();                    Upload up = new Upload(authToken.getAccountId(), fi, name);                    mLog.debug("doPost(): added " + up);                    synchronized (mPending) {                    	mPending.put(up.uuid, up);                    }                    attachmentId = (attachmentId == null ? up.uuid : attachmentId + UPLOAD_DELIMITER + up.uuid);                }            } catch (ServiceException e) {                status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;                mLog.info("File upload failed", e);            }        } while (false);        StringBuffer results = new StringBuffer();    	results.append(status).append(",'").append(reqId != null ? reqId : "null").append('\'');        if (status == HttpServletResponse.SC_OK)        	results.append(",'").append(attachmentId).append('\'');        resp.setContentType("text/html");        PrintWriter out = resp.getWriter();        String fmt = req.getParameter(ContentServlet.PARAM_FORMAT);        if (ContentServlet.FORMAT_RAW.equals(fmt))			out.println(results);        else {						out.println("<html><head></head><body onload=\"window.parent._uploadManager.loaded(" + results + ");\">");			out.println("</body></html>");		}		out.close();        // handle failure by cleaning up the failed upload        if (status != HttpServletResponse.SC_OK && items != null && items.size() > 0)            for (FileItem fi : items)                fi.delete();	}