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 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()); }
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 } } }
ContentDisposition cd = new ContentDisposition(s == null ? Part.ATTACHMENT : s); cd.setParameter("filename", name); part.setHeader("Content-Disposition", cd.toString());
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()); } }
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. setDisposition(contentDisposition.toString()); 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()); } }