javax.mail.internet.MimeBodyPart.getContentType()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(184)

本文整理了Java中javax.mail.internet.MimeBodyPart.getContentType()方法的一些代码示例,展示了MimeBodyPart.getContentType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.getContentType()方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:getContentType

MimeBodyPart.getContentType介绍

[英]Returns the value of the RFC 822 "Content-Type" header field. This represents the content type of the content of this body part. This value must not be null. If this field is unavailable, "text/plain" should be returned.

This implementation uses getHeader(name) to obtain the requisite header field.
[中]

代码示例

代码示例来源:origin: stackoverflow.com

System.out.println( "HTML Content Type: " + htmlPart.getContentType() );
System.out.println( "HTML Content Type: " + htmlPart.getContentType() );
System.out.println( "HTML Data Handler: " + htmlPart.getDataHandler().getContentType() );

代码示例来源:origin: camunda/camunda-bpm-platform

dh = new DataHandler(cachedContent, getContentType());
cachedContent = null;
content = null;

代码示例来源:origin: com.sun.mail/javax.mail

dh = new DataHandler(cachedContent, getContentType());
cachedContent = null;
content = null;

代码示例来源:origin: camunda/camunda-bpm-platform

final String contentType = msgHtml.getContentType();
if (contentType == null || !contentType.equals(EmailConstants.TEXT_HTML))

代码示例来源:origin: OpenAS2/OpenAs2App

public boolean isSigned(MimeBodyPart part) throws MessagingException
{
  ContentType contentType = new ContentType(part.getContentType());
  String baseType = contentType.getBaseType().toLowerCase();
  return baseType.equalsIgnoreCase("multipart/signed");
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

/**
 * Tests to see if this message has a mime-type match with the
 * given type name.
 *
 * @param type   The tested type name.
 *
 * @return If this is a type match on the primary and secondare portion of the types.
 * @exception MessagingException
 */
public boolean isMimeType(String type) throws MessagingException {
  return new ContentType(getContentType()).match(type);
}

代码示例来源:origin: phax/as2-lib

public boolean isSigned (@Nonnull final MimeBodyPart aPart) throws MessagingException
{
 ValueEnforcer.notNull (aPart, "Part");
 final ContentType aContentType = AS2HttpHelper.parseContentType (aPart.getContentType ());
 if (aContentType == null)
  return false;
 final String sBaseType = aContentType.getBaseType ();
 return sBaseType.equalsIgnoreCase ("multipart/signed");
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

/**
 * Tests to see if this message has a mime-type match with the
 * given type name.
 *
 * @param type   The tested type name.
 *
 * @return If this is a type match on the primary and secondare portion of the types.
 * @exception MessagingException
 */
public boolean isMimeType(String type) throws MessagingException {
  return new ContentType(getContentType()).match(type);
}

代码示例来源:origin: OpenAS2/OpenAs2App

public boolean isEncrypted(MimeBodyPart part) throws MessagingException
{
  ContentType contentType = new ContentType(part.getContentType());
  String baseType = contentType.getBaseType().toLowerCase();
  if (baseType.equalsIgnoreCase("application/pkcs7-mime"))
  {
    String smimeType = contentType.getParameter("smime-type");
    boolean checkResult = (smimeType != null) && smimeType.equalsIgnoreCase("enveloped-data");
    if (!checkResult && logger.isDebugEnabled())
    {
      logger.debug("Check for encrypted data failed on SMIME content type: " + smimeType);
    }
    return (checkResult);
  }
  if (logger.isDebugEnabled())
  {
    logger.debug("Check for encrypted data failed on BASE content type: " + baseType);
  }
  return false;
}

代码示例来源:origin: stackoverflow.com

MimeMultipart multipart = (MimeMultipart) message.getContent();
System.out.println("This message consists of " + multipart.getCount() + " parts");
for (int i = 0; i < multipart.getCount(); i++) {
  // Note we're downcasting here, MimeBodyPart is the only subclass
  // of BodyPart available in the Java EE spec.
  MimeBodyPart bodyPart = (MimeBodyPart) multipart.getBodyPart(i); 

  System.out.println("Part " + i + " has type " + bodyPart.getContentType());
  System.out.println("Part " + i " + has filename " + bodyPart.getFileName()); // if it was an attachment
  // So on, so forth.
}

代码示例来源:origin: phax/as2-lib

public boolean isEncrypted (@Nonnull final MimeBodyPart aPart) throws MessagingException
{
 ValueEnforcer.notNull (aPart, "Part");
 // Content-Type is sthg like this if encrypted:
 // application/pkcs7-mime; name=smime.p7m; smime-type=enveloped-data
 final ContentType aContentType = AS2HttpHelper.parseContentType (aPart.getContentType ());
 if (aContentType == null)
  return false;
 final String sBaseType = aContentType.getBaseType ().toLowerCase (Locale.US);
 if (!sBaseType.equals ("application/pkcs7-mime"))
  return false;
 final String sSmimeType = aContentType.getParameter ("smime-type");
 return sSmimeType != null && sSmimeType.equalsIgnoreCase ("enveloped-data");
}

代码示例来源:origin: stackoverflow.com

SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
JceKeyAgreeRecipientInfoGenerator rig = new JceKeyAgreeRecipientInfoGenerator(CMSAlgorithm.ECDH_SHA1KDF, senderPrivateKey, senderPublicKey, CMSAlgorithm.AES128_WRAP);
rig.setProvider("BC");
gen.addRecipientInfoGenerator(rig);

MimeBodyPart msg = new MimeBodyPart();
msg.setText("This is a secret message");

MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.AES128_CBC).setProvider("BC").build());

Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);

String to = "bob@example.com";

Address fromUser = new InternetAddress("alice@example.com");
Address toUser = new InternetAddress(to);

MimeMessage body = new MimeMessage(session);
body.setFrom(fromUser);
body.setRecipient(Message.RecipientType.TO, toUser);
body.setSubject("example encrypted message");
body.setContent(mp.getContent(), mp.getContentType());
body.saveChanges();

body.writeTo(new FileOutputStream("/tmp/encrypted.msg"));

代码示例来源:origin: OpenAS2/OpenAs2App

public DataHistoryItem setData(MimeBodyPart data) throws OpenAS2Exception {
  try {
    DataHistoryItem historyItem = new DataHistoryItem(data.getContentType());
    setData(data, historyItem);
    return historyItem;
  } catch (Exception e) {
    throw new WrappedException(e);
  }
}

代码示例来源:origin: phax/as2-lib

public void setData (@Nullable final MimeBodyPart aData)
{
 // Remember data
 m_aData = aData;
 if (aData != null)
 {
  // Set content type from data
  try
  {
   setContentType (aData.getContentType ());
  }
  catch (final MessagingException ex)
  {
   LOGGER.warn ("Failed to set the Content-Type from the MimeBodyPart. Defaulting to null.");
   setContentType (null);
  }
  // Set content disposition from data
  try
  {
   setContentDisposition (aData.getHeader (CHttpHeader.CONTENT_DISPOSITION, null));
  }
  catch (final MessagingException ex)
  {
   LOGGER.warn ("Failed to set the Content-Disposition from the MimeBodyPart. Defaulting to null.");
   setContentDisposition (null);
  }
 }
}

代码示例来源:origin: pavansolapure/opencodez-samples

public static MimeMessage encryptMessage(MimeMessage message) throws Exception  {
  
  Security.addProvider(new BouncyCastleProvider());
  
  // create the generator for creating an smime/encrypted message
  SMIMEEnvelopedGenerator  gen = new SMIMEEnvelopedGenerator();
  
  X509Certificate recipientCert = getRecipientPublicCertificate(message);
  
  gen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(recipientCert).setProvider("BC"));
  
  MimeBodyPart msg = new MimeBodyPart();
  msg.setContent(message.getContent(), message.getContentType());
  
  MimeBodyPart mp = gen.generate(msg, new JceCMSContentEncryptorBuilder(CMSAlgorithm.RC2_CBC).setProvider("BC").build());
  message.setContent(mp.getContent(), mp.getContentType());
  message.saveChanges();
  
  return message;
}

代码示例来源:origin: OpenAS2/OpenAs2App

public MimeBodyPart compress(Message msg, MimeBodyPart mbp, String compressionType, String contentTxfrEncoding)
    throws SMIMEException, OpenAS2Exception
{
  OutputCompressor compressor = null;
  if (compressionType != null)
  {
    if (compressionType.equalsIgnoreCase(ICryptoHelper.COMPRESSION_ZLIB))
    {
      compressor = new ZlibCompressor();
    } else
    {
      throw new OpenAS2Exception("Unsupported compression type: " + compressionType);
    }
  }
  SMIMECompressedGenerator sCompGen = new SMIMECompressedGenerator();
  sCompGen.setContentTransferEncoding(getEncoding(contentTxfrEncoding));
  MimeBodyPart smime = sCompGen.generate(mbp, compressor);
  if (logger.isTraceEnabled())
  {
    try
    {
      logger.trace("Compressed MIME msg AFTER COMPRESSION Content-Type:" + smime.getContentType());
      logger.trace("Compressed MIME msg AFTER COMPRESSION Content-Disposition:" + smime.getDisposition());
    } catch (MessagingException e)
    {
    }
  }
  return smime;
}

代码示例来源:origin: OpenAS2/OpenAs2App

public void setData(MimeBodyPart data, DataHistoryItem historyItem) {
  this.data = data;
  if (data != null) {
    try {
      setContentType(data.getContentType());
    } catch (MessagingException e) {
      setContentType(null);
    }
    try { 
      setContentDisposition(data.getHeader("Content-Disposition", null)); 
    }
    catch (MessagingException e) { 
      setContentDisposition(null); // TODO: why ignore?????
    } 
  }
  if (historyItem != null) {
    getHistory().getItems().add(historyItem);
  }
}

代码示例来源:origin: org.openspml/openspml

/**
 * Retrieve a response to a previous <code>send</code> call and
 * return it as a string of XML.
 */
public String receive()
throws SOAPException, MessagingException, IOException {
String payload = null;
if (_responseContext != null && _responseReader != null) {
  MimeBodyPart rootPart = _responseContext.getRootPart();
  if (rootPart.isMimeType("text/*")) {
  // Get the input stream to read the response envelope from.
  payload = IOUtils.getStringFromReader(_responseReader);
  }
  // Check Content-Type of root part of response to see if it's
  // consistent with a SOAP envelope (text/xml).
  if (!rootPart.isMimeType(Constants.HEADERVAL_CONTENT_TYPE)) {
  throw new SOAPException(Constants.FAULT_CODE_PROTOCOL,
        "Unsupported response content type \"" +
        rootPart.getContentType() + "\", must be: \"" +
        Constants.HEADERVAL_CONTENT_TYPE + "\"." +
        (payload == null ? "" : " Response was:\n" + payload));
  }
}
  if (_monitor != null)
    _monitor.receive(payload);
return payload;
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

public void setFileName(String name) throws MessagingException {
  // there's an optional session property that requests file name encoding...we need to process this before
  // setting the value.
  if (name != null && SessionUtil.getBooleanProperty(MIME_ENCODEFILENAME, false)) {
    try {
      name = MimeUtility.encodeText(name);
    } catch (UnsupportedEncodingException e) {
      throw new MessagingException("Unable to encode filename", e);
    }
  }
  // get the disposition string.
  String disposition = getDisposition();
  // if not there, then this is an attachment.
  if (disposition == null) {
    disposition = Part.ATTACHMENT;
  }
  // now create a disposition object and set the parameter.
  ContentDisposition contentDisposition = new ContentDisposition(disposition);
  contentDisposition.setParameter("filename", name);
  // serialize this back out and reset.
  setHeader("Content-Disposition", contentDisposition.toString());
  // The Sun implementation appears to update the Content-type name parameter too, based on
  // another system property
  if (SessionUtil.getBooleanProperty(MIME_SETCONTENTTYPEFILENAME, true)) {
    ContentType type = new ContentType(getContentType());
    type.setParameter("name", name);
    setHeader("Content-Type", type.toString());
  }
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

public void setFileName(String name) throws MessagingException {
  // there's an optional session property that requests file name encoding...we need to process this before
  // setting the value.
  if (name != null && SessionUtil.getBooleanProperty(MIME_ENCODEFILENAME, false)) {
    try {
      name = MimeUtility.encodeText(name);
    } catch (UnsupportedEncodingException e) {
      throw new MessagingException("Unable to encode filename", e);
    }
  }
  // get the disposition string.
  String disposition = getDisposition();
  // if not there, then this is an attachment.
  if (disposition == null) {
    disposition = Part.ATTACHMENT;
  }
  // now create a disposition object and set the parameter.
  ContentDisposition contentDisposition = new ContentDisposition(disposition);
  contentDisposition.setParameter("filename", name);
  // serialize this back out and reset.
  setDisposition(contentDisposition.toString());
  setHeader("Content-Disposition", contentDisposition.toString());
  // The Sun implementation appears to update the Content-type name parameter too, based on
  // another system property
  if (SessionUtil.getBooleanProperty(MIME_SETCONTENTTYPEFILENAME, true)) {
    ContentType type = new ContentType(getContentType());
    type.setParameter("name", name);
    setHeader("Content-Type", type.toString());
  }
}

相关文章