本文整理汇总了Java中javax.mail.internet.ContentType.toString方法的典型用法代码示例。如果您正苦于以下问题:Java ContentType.toString方法的具体用法?Java ContentType.toString怎么用?Java ContentType.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.ContentType
的用法示例。
在下文中一共展示了ContentType.toString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanContentType
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
/**
* 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();
}
示例2: updateContentType
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
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();
}
}
示例3: AlfrescoMimeMultipart
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
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();
}
示例4: SoapMimeMultipart
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
public SoapMimeMultipart (@Nonnull final ESOAPVersion eSOAPVersion,
@Nonnull final Charset aCharset) throws ParseException
{
super ("related");
// type parameter is essential for Axis to work!
// But no charset! RFC 2387, section 3.4 has a special definition
final ContentType aContentType = new ContentType (contentType);
aContentType.setParameter ("type", eSOAPVersion.getMimeType ().getAsString ());
aContentType.setParameter ("charset", aCharset.name ());
contentType = aContentType.toString ();
}
示例5: writeBodyPart
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
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");
}
}
示例6: sendMessage
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
protected String sendMessage(ContentType contentType, byte[] message) throws Exception {
String msgId = UUIDGenerator.getUUID();
MimeMessage msg = new MimeMessage(session);
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(channel.getRecipient().getAddress()));
msg.setFrom(new InternetAddress(channel.getSender().getAddress()));
msg.setSentDate(new Date());
msg.setHeader(MailConstants.MAIL_HEADER_MESSAGE_ID, msgId);
msg.setHeader(MailConstants.MAIL_HEADER_X_MESSAGE_ID, msgId);
DataHandler dh = new DataHandler(new ByteArrayDataSource(message, contentType.toString()));
layout.setupMessage(msg, dh);
Transport.send(msg);
return msgId;
}