下面列出了javax.mail.internet.ContentType#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Attempt to repair the given contentType if broken.
* @param mp Mimepart holding the contentType
* @param contentType ContentType
* @return fixed contentType String
* @throws MessagingException
*/
public static String cleanContentType(MimePart mp, String contentType) throws MessagingException {
ContentType ct = parseContentType(contentType);
if (ct == null) {
ct = getParsableContentType(contentType);
}
if (ct.getBaseType().equalsIgnoreCase("text/plain") || ct.getBaseType().equalsIgnoreCase("text/html")) {
Charset charset = parseCharset(ct);
if (charset == null) {
Logger.debug("Charset of the ContentType could not be read, try to decode the contentType as quoted-printable");
ContentType ctTmp = decodeContentTypeAsQuotedPrintable(contentType);
if (parseCharset(ctTmp) != null) {
ct = ctTmp;
} else {
ct.setParameter("charset", ContentTypeCleaner.DEFAULT_CHARSET);
}
}
}
return ct.toString();
}
public AlfrescoMimeMultipart(String subtype, FileInfo messageFileInfo)
{
super();
String boundary = getBoundaryValue(messageFileInfo);
ContentType cType = new ContentType("multipart", subtype, null);
cType.setParameter("boundary", boundary);
contentType = cType.toString();
}
private String getContentType(Mail mail, Optional<Charset> charset) throws MessagingException, ParseException {
String contentTypeAsString = mail.getMessage().getContentType();
if (charset.isPresent()) {
ContentType contentType = new ContentType(contentTypeAsString);
contentType.setParameter("charset", charset.get().name());
return contentType.toString();
}
return contentTypeAsString;
}
private static void setContentFromPart(Message m, Part p, String newText, boolean setTextPlain) throws MessagingException, IOException {
String contentType = p.getContentType();
if (setTextPlain) {
ContentType ct = new ContentType(contentType);
ct.setPrimaryType("text");
ct.setSubType("plain");
contentType = ct.toString();
}
m.setContent(newText != null ? newText : p.getContent(), contentType);
String[] h = p.getHeader("Content-Transfer-Encoding");
if (h != null && h.length > 0) {
m.setHeader("Content-Transfer-Encoding", h[0]);
}
m.saveChanges();
}
/**
* Sets the content type
* @param aContentType
*/
protected void setContentType(ContentType aContentType) {
contentType = aContentType.toString();
}