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(); } }
public static ContentType addCharset(ContentType contentType, String charset) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); if (orgParamList != null) { for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); paramList.set(name, orgParamList.get(name)); } } paramList.set("charset", charset); return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); }
public static ContentType removeCharset(ContentType contentType) { ParameterList orgParamList = contentType.getParameterList(); ParameterList paramList = new ParameterList(); for (Enumeration<?> e = orgParamList.getNames(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); if (!name.equalsIgnoreCase("charset")) { paramList.set(name, orgParamList.get(name)); } } return new ContentType(contentType.getPrimaryType(), contentType.getSubType(), paramList); }