本文整理汇总了Java中javax.mail.internet.ContentType.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ContentType.setParameter方法的具体用法?Java ContentType.setParameter怎么用?Java ContentType.setParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.mail.internet.ContentType
的用法示例。
在下文中一共展示了ContentType.setParameter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getContentType
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
private ContentType getContentType(Exchange exchange) throws ParseException {
String contentTypeStr = ExchangeHelper.getContentType(exchange);
if (contentTypeStr == null) {
contentTypeStr = DEFAULT_CONTENT_TYPE;
}
ContentType contentType = new ContentType(contentTypeStr);
String contentEncoding = ExchangeHelper.getContentEncoding(exchange);
// add a charset parameter for text subtypes
if (contentEncoding != null && contentType.match("text/*")) {
contentType.setParameter("charset", MimeUtility.mimeCharset(contentEncoding));
}
return contentType;
}
示例6: addAttachments
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
private void addAttachments( Enumeration<fileAttachment> _attach, Multipart _parent, boolean _isInline ) throws MessagingException{
while ( _attach.hasMoreElements() ){
fileAttachment nextFile = _attach.nextElement();
FileDataSource fds = new FileDataSource( nextFile.getFilepath() );
String mimeType = nextFile.getMimetype();
if (mimeType == null){
// if mime type not supplied then auto detect
mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(nextFile.getFilepath());
}else{
// since mime type is not null then it the mime type has been set manually therefore
// we need to ensure that any call to the underlying FileDataSource.getFileTypeMap()
// returns a FileTypeMap that will map to this type
fds.setFileTypeMap(new CustomFileTypeMap(mimeType));
}
String filename = cleanName(fds.getName());
try {
// encode the filename to ensure that it contains US-ASCII characters only
filename = MimeUtility.encodeText( filename, "utf-8", "b" );
} catch (UnsupportedEncodingException e5) {
// shouldn't occur
}
MimeBodyPart mimeAttach = new MimeBodyPart();
mimeAttach.setDataHandler( new DataHandler(fds) );
mimeAttach.setFileName( filename );
ContentType ct = new ContentType(mimeType);
ct.setParameter("name", filename );
mimeAttach.setHeader("Content-Type", ct.toString() );
if ( _isInline ){
mimeAttach.setDisposition( "inline" );
mimeAttach.addHeader( "Content-id", "<" + nextFile.getContentid() + ">" );
}
_parent.addBodyPart(mimeAttach);
}
}
示例7: createAlternativePart
import javax.mail.internet.ContentType; //导入方法依赖的package包/类
private MimeMultipart createAlternativePart(ZCalendar.ZVCalendar cal, String desc, String descHtml)
throws MessagingException, ZimbraException
{
MimeMultipart multipart = new MimeMultipart("alternative");
cal.addDescription(desc, null);
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(desc, MimeConstants.P_CHARSET_UTF8);
multipart.addBodyPart(textPart);
if (descHtml == null || descHtml.isEmpty())
{
descHtml = mPlainTextToHtmlConverter.plainText2HTML(desc);
}
if (!descHtml.isEmpty())
{
MimeBodyPart htmlPart = new MimeBodyPart();
ContentType ct = new ContentType(MimeConstants.CT_TEXT_HTML);
ct.setParameter(MimeConstants.P_CHARSET, MimeConstants.P_CHARSET_UTF8);
htmlPart.setText(descHtml, MimeConstants.P_CHARSET_UTF8);
htmlPart.setHeader("Content-Type", ct.toString());
multipart.addBodyPart(htmlPart);
}
MimeBodyPart icalPart;
try {
icalPart = CalendarMailSender.makeICalIntoMimePart(cal);
}
catch (ServiceException ex)
{
throw ExceptionWrapper.wrap(ex);
}
multipart.addBodyPart(icalPart);
return multipart;
}