ContentType cType = new ContentType(type); if (cType.match("multipart/*")) { ((MimeMultipart)o).updateHeaders(); else throw new MessagingException("MIME part of type \"" + type + "\" contains object of type " + o.getClass().getName() + " instead of MimeMultipart"); } else if (cType.match("message/rfc822")) { composite = true; cType.match("text/*") && cType.getParameter("charset") == null) { charset = "us-ascii"; else charset = MimeUtility.getDefaultMIMECharset(); cType.setParameter("charset", charset); type = cType.toString(); ContentDisposition cd = new ContentDisposition(s); String filename = cd.getParameter("filename"); if (filename != null) { ParameterList p = cType.getParameterList(); if (p == null) { p = new ParameterList(); cType.setParameterList(p);
filename = ((MimeBodyPart) bp).getContentID(); ct = new ContentType(contentType); if ("text/plain".equalsIgnoreCase(ct.getBaseType())) { textFilename = "message.txt"; else if ("text/html".equalsIgnoreCase(ct.getBaseType())) { textFilename = "message.html";
private boolean isXmlType(String type) { try { ContentType ct = new ContentType(type); return ct.getSubType().equals("xml") && (ct.getPrimaryType().equals("text") || ct.getPrimaryType().equals("application")); } catch (ParseException ex) { return false; } catch (RuntimeException ex) { return false; } } }
protected IMAPBodyPart(BODYSTRUCTURE bs, String sid, IMAPMessage message) { super(); this.bs = bs; this.sectionId = sid; this.message = message; // generate content-type ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams); type = ct.toString(); }
/** * Set the subtype. This method should be invoked only on a new * MimeMultipart object created by the client. The default subtype * of such a multipart object is "mixed". <p> * * @param subtype Subtype * @exception MessagingException for failures */ public synchronized void setSubType(String subtype) throws MessagingException { ContentType cType = new ContentType(contentType); cType.setSubType(subtype); contentType = cType.toString(); }
protected void parse() throws MessagingException { if (parsed) { return; } try { ContentType cType = new ContentType(contentType); byte[] boundary = ("--" + cType.getParameter("boundary")).getBytes(); InputStream is = new BufferedInputStream(ds.getInputStream()); PushbackInputStream pushbackInStream = new PushbackInputStream(is, (boundary.length + 2)); readTillFirstBoundary(pushbackInStream, boundary); while (pushbackInStream.available()>0){ MimeBodyPartInputStream partStream; partStream = new MimeBodyPartInputStream(pushbackInStream, boundary); addBodyPart(new MimeBodyPart(partStream)); } } catch (Exception e){ throw new MessagingException(e.toString(),e); } parsed = true; }
String type = dh.getContentType(); ContentType content = new ContentType(type); String explicitType = getSingleHeader("Content-Type"); if (content.match("multipart/*")) { else if (!content.match("message/rfc822")) { if (SessionUtil.getBooleanProperty(MIME_SETDEFAULTTEXTCHARSET, true)) { if (content.match("text/*")) { if (content.getParameter("charset") == null) { String encoding = getEncoding(); content.setParameter("charset", "us-ascii"); content.setParameter("charset", MimeUtility.getDefaultMIMECharset()); type = content.toString(); content.setParameter("name", filename); type = content.toString();
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; }
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(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. setHeader("Content-Disposition", contentDisposition.toString()); // The Sun implementation appears to update the Content-type name parameter too, based on // another system property if (SessionUtil.getBooleanProperty(MIME_SETCONTENTTYPEFILENAME, true)) { ContentType type = new ContentType(getContentType()); type.setParameter("name", name); setHeader("Content-Type", type.toString()); } }
String type = dh.getContentType(); ContentType content = new ContentType(type); if (content.match("multipart/*")) { else if (!content.match("message/rfc822")) { setHeader("Content-Transfer-Encoding", MimeUtility.getEncoding(handler)); if (SessionUtil.getBooleanProperty(session, "MIME_MAIL_SETDEFAULTTEXTCHARSET", true)) { if (content.match("text/*")) { if (content.getParameter("charset") == null) { content.setParameter("charset", "us-ascii"); content.setParameter("charset", MimeUtility.getDefaultMIMECharset()); type = content.toString(); if (disp != null) { content.setParameter("name", filename); type = content.toString();
if (type == null) { // type not yet computed ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams); type = ct.toString(); dh = new DataHandler( new IMAPMultipartDataSource(this, bs.bodies, sectionId, this) dh = new DataHandler( new IMAPNestedMessage(this, bs.bodies[0],
parse(); (new ContentType(contentType)).getParameter("boundary"); LineOutputStream los = new LineOutputStream(os); throw new MessagingException("Empty multipart: " + contentType); ((MimeBodyPart)parts.elementAt(i)).writeTo(os);
String s = part.getHeader("Content-Disposition", null); ContentDisposition cd = new ContentDisposition(s == null ? Part.ATTACHMENT : s); else p.set("filename", name, charset); part.setHeader("Content-Disposition", cd.toString()); s = part.getHeader("Content-Type", null); s = MimeUtil.cleanContentType(part, s); if (s != null) { try { ContentType cType = new ContentType(s); p = cType.getParameterList(); if (p == null) { p = new ParameterList(); cType.setParameterList(p); else p.set("name", name, charset); part.setHeader("Content-Type", cType.toString()); } catch (ParseException pex) { } // ignore it
if (dh.getName() != null) return getEncoding(dh.getDataSource()); cType = new ContentType(dh.getContentType()); } catch (Exception ex) { return "base64"; // what else ?! if (cType.match("text/*")) {
@Override public void process(Exchange exchange) throws Exception { String newFileName = "internal-switchyard.jpeg"; Image input = exchange.getIn().getBody(Image.class); if (input == null) { throw new RuntimeException("Image for resize not found!"); } ContentType type = new ContentType("image/jpeg"); exchange.getOut().addAttachment(newFileName, new DataHandler(input, type.getBaseType())); exchange.getOut().setBody(newFileName); }
public String getFileName() throws MessagingException { // see if there is a disposition. If there is, parse off the filename parameter. String disposition = getSingleHeader("Content-Disposition"); String filename = null; if (disposition != null) { filename = new ContentDisposition(disposition).getParameter("filename"); } // if there's no filename on the disposition, there might be a name parameter on a // Content-Type header. if (filename == null) { String type = getSingleHeader("Content-Type"); if (type != null) { try { filename = new ContentType(type).getParameter("name"); } catch (ParseException e) { } } } // if we have a name, we might need to decode this if an additional property is set. if (filename != null && SessionUtil.getBooleanProperty(MIME_DECODEFILENAME, false)) { try { filename = MimeUtility.decodeText(filename); } catch (UnsupportedEncodingException e) { throw new MessagingException("Unable to decode filename", e); } } return filename; }
private void writeBodyPart(byte[] bodyContent, Part part, ContentType contentType) throws MessagingException { DataSource ds = new ByteArrayDataSource(bodyContent, contentType.toString()); part.setDataHandler(new DataHandler(ds)); part.setHeader(CONTENT_TYPE, contentType.toString()); if (contentType.match("text/*")) { part.setHeader(CONTENT_TRANSFER_ENCODING, "8bit"); } else if (binaryContent) { part.setHeader(CONTENT_TRANSFER_ENCODING, "binary"); } else { part.setHeader(CONTENT_TRANSFER_ENCODING, "base64"); } }
return; initializeProperties(); in = new BufferedInputStream(in); } catch (Exception ex) { throw new MessagingException("No inputstream from datasource", ex); ContentType cType = new ContentType(contentType); String boundary = null; if (!ignoreExistingBoundaryParameter) { String bp = cType.getParameter("boundary"); if (bp != null) boundary = "--" + bp; throw new MessagingException("Missing boundary parameter"); if (line.length() > 4 && allDashes(line)) { return; else throw new MessagingException("Missing start boundary"); headers = createInternetHeaders(in);
private void updateContentType(boolean cleanDefaultRoot) throws MessagingException { BodyPart part = null; if (rootId == null) { part = getBodyPart(0); } else { part = getBodyPart(rootId); if (part == null) { if (cleanDefaultRoot) rootId = null; else throw new MessagingException("Can not set root: " + rootId + ": not found"); } } if (part != null) { String primaryType = baseContentTypeObject.getPrimaryType(); String subType = baseContentTypeObject.getSubType(); ParameterList params = baseContentTypeObject.getParameterList(); ContentType newContentType = new ContentType(primaryType, subType, params); ContentType rootContentType = new ContentType(part.getDataHandler().getContentType()); newContentType.setParameter("type", rootContentType.getBaseType()); if (rootId != null) newContentType.setParameter("start", stripBrackets(rootId)); contentType = newContentType.toString(); } }
DataSource ds = handler.getDataSource(); if (ds != null) { return getEncoding(ds); ContentType content = new ContentType(ds.getContentType()); handler.writeTo(checker); if (content.match("text/*")) { return checker.getTextTransferEncoding();