ContentType( final String mimeType, final NameValuePair[] params) throws UnsupportedCharsetException { this.mimeType = mimeType; this.params = params; final String s = getParameter("charset"); this.charset = !TextUtils.isBlank(s) ? Charset.forName(s) : null; }
ContentType( final String mimeType, final NameValuePair[] params) throws UnsupportedCharsetException { this.mimeType = mimeType; this.params = params; final String s = getParameter("charset"); this.charset = !TextUtils.isBlank(s) ? Charset.forName(s) : null; }
public static String cleanContentType(MimePart mp, String contentType) { String ct = "TEXT/PLAIN; charset=\"=?utf-8?B?ICJVVEYtOCI=?=\""; ContentType content = new ContentType(ct); System.out.println(content.getBaseType()); System.out.println(content.getParameter("charset")); System.out.println(MimeUtility.decodeText(content.getParameter("charset"))); }
/** * Find a matching format info instance from a content type. * @param contentType The content type to use for matching against known formats * @return The format info entry that matches the content type */ public static YoutubeFormatInfo get(ContentType contentType) { String mimeType = contentType.getMimeType(); String codec = contentType.getParameter("codecs"); // Check accurate matches for (YoutubeFormatInfo formatInfo : YoutubeFormatInfo.class.getEnumConstants()) { if (formatInfo.mimeType.equals(mimeType) && formatInfo.codec.equals(codec)) { return formatInfo; } } // Check for substring matches for (YoutubeFormatInfo formatInfo : YoutubeFormatInfo.class.getEnumConstants()) { if (formatInfo.mimeType.equals(mimeType) && codec.contains(formatInfo.codec)) { return formatInfo; } } return null; } }
public static String cleanContentType(MimePart mp, String contentType) { try { ContentType content = new ContentType(contentType); String charset = MimeUtility.decodeText(content.getParameter("charset")); charset = charset.replace("\"", ""); content.setParameter("charset", charset); return content.toString(); } catch (MessagingException | UnsupportedEncodingException ex) { return contentType; } }
// source is the encrypted MimeMessage // MimeMessageWrapper is a wrapper which can copy a messgae but keep the message ID unchanged boolean keepMessageId = true; MimeMessageWrapper newMime = new MimeMessageWrapper(source, keepMessageId); MimeMultipart mmp = new MimeMultipart("mixed"); List<MimePart> parts = MimeMultipartUtils.findPartsByMimeType(mime, "*"); for (MimePart part : parts) { // Do some part processing // Decrypt Adn verify individual parts // End of processing ContentType type = new ContentType(part.getContentType()); String encoding = part.getEncoding(); String name = type.getParameter("name"); part.setContent(new String(decPart.toByteArray()), type.toString()); // Add the part to the brand new MimeMultipart mmp.addBodyPart((BodyPart) part); } // Set the original copy Message with the new modified content (decrypted parts) mime.setContent(mmp); mime.saveChanges();
MultipartFormEntity buildEntity() { String boundaryCopy = boundary; if (boundaryCopy == null && contentType != null) { boundaryCopy = contentType.getParameter("boundary");
MultipartFormEntity buildEntity() { String boundaryCopy = boundary; if (boundaryCopy == null && contentType != null) { boundaryCopy = contentType.getParameter("boundary");
try { ContentType ct = new ContentType(mimeType); String cs = ct.getParameter("charset"); if ("big-5".equalsIgnoreCase(cs)) { ct.setParameter("charset", "big5");