Refine search
String type = dh.getContentType(); boolean composite = false; boolean needCTHeader = part.getHeader("Content-Type") == null; ContentType cType = new ContentType(type); if (cType.match("multipart/*")) { if (mpart != part) { if (needCTHeader) part.setHeader("Content-Type", mpart.getContentType()); setEncoding(part, MimeUtility.getEncoding(dh)); charset = "us-ascii"; else charset = MimeUtility.getDefaultMIMECharset(); if (s != null) { ContentDisposition cd = new ContentDisposition(s); String filename = cd.getParameter("filename"); MimeUtility.encodeText(filename)); else p.set("name", filename, throw new MessagingException("IOException updating headers", ex);
if (encodeFileName && name != null) { try { name = MimeUtility.encodeText(name); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Can't encode filename", ex); String s = part.getHeader("Content-Disposition", null); ContentDisposition cd = new ContentDisposition(s == null ? Part.ATTACHMENT : s); String charset = MimeUtility.getDefaultMIMECharset(); ParameterList p = cd.getParameterList(); if (p == null) { p = new ParameterList(); cd.setParameterList(p); else p.set("filename", name, charset); part.setHeader("Content-Disposition", cd.toString()); p = cType.getParameterList(); if (p == null) { p = new ParameterList(); cType.setParameterList(p);
static String getDisposition(MimePart part) throws MessagingException { String s = part.getHeader("Content-Disposition", null); if (s == null) return null; ContentDisposition cd = new ContentDisposition(s); return cd.getDisposition(); }
static void setDisposition(MimePart part, String disposition) throws MessagingException { if (disposition == null) part.removeHeader("Content-Disposition"); else { String s = part.getHeader("Content-Disposition", null); if (s != null) { /* A Content-Disposition header already exists .. * * Override disposition, but attempt to retain * existing disposition parameters */ ContentDisposition cd = new ContentDisposition(s); cd.setDisposition(disposition); disposition = cd.toString(); } part.setHeader("Content-Disposition", disposition); } }
static String getFileName(MimePart part) throws MessagingException { String filename = null; String s = part.getHeader("Content-Disposition", null); if (s != null) { // Parse the header .. ContentDisposition cd = new ContentDisposition(s); filename = cd.getParameter("filename"); } if (filename == null) { // Still no filename ? Try the "name" ContentType parameter s = part.getHeader("Content-Type", null); s = MimeUtil.cleanContentType(part, s); if (s != null) { try { ContentType ct = new ContentType(s); filename = ct.getParameter("name"); } catch (ParseException pex) { } // ignore it } } if (decodeFileName && filename != null) { try { filename = MimeUtility.decodeText(filename); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Can't decode filename", ex); } } return filename; }
static void setFileName(MimePart part, String name) throws MessagingException { if (encodeFileName && name != null) { try { name = MimeUtility.encodeText(name); } catch (UnsupportedEncodingException ex) { throw new MessagingException("Can't encode filename", ex); } } // Set the Content-Disposition "filename" parameter String s = part.getHeader("Content-Disposition", null); ContentDisposition cd = new ContentDisposition(s == null ? Part.ATTACHMENT : s); cd.setParameter("filename", name); part.setHeader("Content-Disposition", cd.toString()); /* * Also attempt to set the Content-Type "name" parameter, * to satisfy ancient MUAs. XXX - This is not RFC compliant. */ if (setContentTypeFileName) { s = part.getHeader("Content-Type", null); if (s != null) { try { ContentType cType = new ContentType(s); cType.setParameter("name", name); part.setHeader("Content-Type", cType.toString()); } catch (ParseException pex) { } // ignore it } } }
ContentType content = new ContentType(type); if (content.match("multipart/*")) { part.updateHeaders(); } catch (ClassCastException e) { throw new MessagingException("Message content is not MimeMultipart", e); else if (!content.match("message/rfc822")) { setHeader("Content-Transfer-Encoding", MimeUtility.getEncoding(handler)); content.setParameter("charset", MimeUtility.getDefaultMIMECharset()); if (disp != null) { ContentDisposition disposition = new ContentDisposition(disp); String filename = disposition.getParameter("filename"); throw new MessagingException("Error updating message headers", e);
static void updateHeaders(MimePart part) throws MessagingException { DataHandler dh = part.getDataHandler(); if (dh == null) // Huh ? return; String type = dh.getContentType(); boolean composite = false; boolean needCTHeader = part.getHeader("Content-Type") == null; ContentType cType = new ContentType(type); if (cType.match("multipart/*")) { if (part.getHeader("Content-Transfer-Encoding") == null) setEncoding(part, MimeUtility.getEncoding(dh)); charset = "us-ascii"; else charset = MimeUtility.getDefaultMIMECharset(); cType.setParameter("charset", charset); type = cType.toString(); if (s != null) { ContentDisposition cd = new ContentDisposition(s); String filename = cd.getParameter("filename"); if (filename != null) { cType.setParameter("name", filename); throw new MessagingException("IOException updating headers", ex);
public void setFileName(String name) throws MessagingException { // there's an optional session property that requests file name encoding...we need to process this before // setting the value. if (name != null && SessionUtil.getBooleanProperty(session, MIME_ENCODEFILENAME, false)) { try { name = MimeUtility.encodeText(name); } catch (UnsupportedEncodingException e) { throw new MessagingException("Unable to encode filename", e); } } // get the disposition string. String disposition = getDisposition(); // if not there, then this is an attachment. if (disposition == null) { disposition = Part.ATTACHMENT; } // now create a disposition object and set the parameter. ContentDisposition contentDisposition = new ContentDisposition(disposition); contentDisposition.setParameter("filename", name); // serialize this back out and reset. setDisposition(contentDisposition.toString()); }
public String getFileName() throws MessagingException { String filename = bodyStructure.disposition.getParameter("filename"); if (filename == null) { filename = bodyStructure.mimeType.getParameter("name"); } return filename; }
/** * Set a new dispostion value for the "Content-Disposition" field. * If the new value is null, the header is removed. * * @param disposition * The new disposition value. * * @exception MessagingException */ public void setDisposition(String disposition) throws MessagingException { if (disposition == null) { removeHeader("Content-Disposition"); } else { // the disposition has parameters, which we'll attempt to preserve in any existing header. String currentHeader = getSingleHeader("Content-Disposition"); if (currentHeader != null) { ContentDisposition content = new ContentDisposition(currentHeader); content.setDisposition(disposition); setHeader("Content-Disposition", content.toString()); } else { // set using the raw string. setHeader("Content-Disposition", disposition); } } }
/** * Retrieve the message "Content-Disposition" header field. * This value represents how the part should be represented to * the user. * * @return The string value of the Content-Disposition field. * @exception MessagingException */ public String getDisposition() throws MessagingException { String disp = getSingleHeader("Content-Disposition"); if (disp != null) { return new ContentDisposition(disp).getDisposition(); } return null; }
public ContentDisposition(String disposition, ParameterList list) { setDisposition(disposition); setParameterList(list); }
MimeBodyPart formPart = new MimeBodyPart(); formPart.setContent( URLEncoder.encode(requestData.toString(), "UTF-8"), "application/x-www-form-urlencoded"); formPart.setDisposition("form-data; name=\"form\""); MimeBodyPart filePart = new MimeBodyPart(); filePart.attachFile(fileToUpload); ContentDisposition disposition = new ContentDisposition("form-data"); disposition.getParameterList().set("name", "file"); disposition.getParameterList().set("filename", fileToUpload.toString(), "UTF-8"); filePart.setDisposition(disposition.toString()); MimeMultipart multipart = new MimeMultipart("form-data"); multipart.addBodyPart(formPart); multipart.addBodyPart(filePart); try (OutputStream out = con.getOutputStream()) { multipart.writeTo(out); }
ContentDisposition cd = new ContentDisposition(s); tmpFilename = cd.getParameter("filename");
disposition = new ContentDisposition(); disposition.setDisposition(source.readString()); disposition.setParameterList(source.readParameterList()); source.checkRightParen(); } else if (source.peek(true) == IMAPResponseTokenizer.NIL) {
WebClient client = WebClient.create("http://books"); client.type("multipart/form-data"); ContentDisposition cd = new ContentDisposition("attachment;filename=image.jpg"); Attachment att = new Attachment("root", imageInputStream, cd); client.post(new MultipartBody(att)); // or just post the attachment if it's a single part request only client.post(att); // or just use a file client.post(getClass().getResource("image.png").getFile());
@POST @Path( "/<service_path>" ) @Consumes( "multipart/form-data" ) public Response importShapeFile( final MultipartBody body ) { String filename = null; String InputStream stream = null; for ( Attachment attachment : body.getAllAttachments() ) { ContentDisposition disposition = attachment.getContentDisposition(); if ( disposition != null && PARAM_NAME.equals( disposition.getParameter( "name" ) ) ) { filename = disposition.getParameter( "filename" ); stream = attachment.getDataHandler().getInputStream(); break; } } // Read extension from filename to get the file's type and // read the stream accordingly. }
/** * Retrieve the disposition information about this * body part. * * @return The disposition information, as a string value. * @exception MessagingException */ public String getDisposition() throws MessagingException { return bodyStructure.disposition.getDisposition(); }