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

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

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

MimeMessage.getContentType介绍

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

This implementation uses the getHeader method to obtain the requisite header field.
[中]返回RFC 822“内容类型”标题字段的值。这表示此消息内容的内容类型。此值不能为空。如果此字段不可用,则应返回“text/plain”。
此实现使用getHeader方法来获取所需的头字段。

代码示例

代码示例来源: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: spring-projects/spring-integration

headers.put(MailHeaders.CONTENT_TYPE, source.getContentType());

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

/**
 * Get the Content-Type.
 *
 * Generate this header from the BODYSTRUCTURE. Append parameters
 * as well.
 */
public synchronized String getContentType() throws MessagingException {
checkExpunged();
if (bodyLoaded)
  return super.getContentType();
// If we haven't cached the type yet ..
if (type == null) {
  loadBODYSTRUCTURE();
  // generate content-type from BODYSTRUCTURE
  ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams);
  type = ct.toString();
}
return type;
}

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

/**
 * Get the Content-Type.
 *
 * Generate this header from the BODYSTRUCTURE. Append parameters
 * as well.
 */
@Override
public synchronized String getContentType() throws MessagingException {
checkExpunged();
if (bodyLoaded)
  return super.getContentType();
// If we haven't cached the type yet ..
if (type == null) {
  loadBODYSTRUCTURE();
  // generate content-type from BODYSTRUCTURE
  ContentType ct = new ContentType(bs.type, bs.subtype, bs.cParams);
  type = ct.toString();
}
return type;
}

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

public static void assertEmailSend(WiserMessage emailMessage, boolean htmlMail, String subject, String message,
    String from, List<String> to, List<String> cc) throws IOException {
 try {
  MimeMessage mimeMessage = emailMessage.getMimeMessage();
  if (htmlMail) {
   assertTrue(mimeMessage.getContentType().contains("multipart/mixed"));
  } else {
   assertTrue(mimeMessage.getContentType().contains("text/plain"));
  }
  assertEquals(subject, mimeMessage.getHeader("Subject", null));
  assertEquals(from, mimeMessage.getHeader("From", null));
  assertTrue(getMessage(mimeMessage).contains(message));
  for (String t : to) {
   assertTrue(mimeMessage.getHeader("To", null).contains(t));
  }
  if (cc != null) {
   for (String c : cc) {
    assertTrue(mimeMessage.getHeader("Cc", null).contains(c));
   }
  }
 } catch (MessagingException e) {
  fail(e.getMessage());
 }
}

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

private void assertEmailSend(WiserMessage emailMessage, boolean htmlMail, String subject, String message,
    String from, List<String> to, List<String> cc) throws IOException {
 try {
  MimeMessage mimeMessage = emailMessage.getMimeMessage();
  if (htmlMail) {
   assertTrue(mimeMessage.getContentType().contains("multipart/mixed"));
  } else {
   assertTrue(mimeMessage.getContentType().contains("text/plain"));
  }
  assertEquals(subject, mimeMessage.getHeader("Subject", null));
  assertEquals(from, mimeMessage.getHeader("From", null));
  assertTrue(getMessage(mimeMessage).contains(message));
  for (String t : to) {
   assertTrue(mimeMessage.getHeader("To", null).contains(t));
  }
  if (cc != null) {
   for (String c : cc) {
    assertTrue(mimeMessage.getHeader("Cc", null).contains(c));
   }
  }
 } catch (MessagingException e) {
  fail(e.getMessage());
 }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax.mail

/**
 * Return the content type, mapping from SunV3 types to MIME types
 * as necessary.
 */
public String getContentType()  throws MessagingException {
String ct = super.getContentType();
if (ct.indexOf('/') < 0)
  ct = SunV3BodyPart.MimeV3Map.toMime(ct);
return ct;
}

代码示例来源:origin: org.nhind/agent

private static ContentType getContentType(MimeMessage entity)
{
  try
  {
    return new ContentType(entity.getContentType());
  }
  catch (MessagingException e) {/* no-op */}
  
  return null;
}

代码示例来源:origin: org.nhind/agent

private static ContentType getContentType(MimeMessage msg)
{
  try
  {
    return new ContentType(msg.getContentType());
  }
  catch (MessagingException e) {/* no-op */}
  
  return null;
}

代码示例来源:origin: org.apache.james/james-server-core-library

/**
 * @see javax.mail.Part#getContentType()
 */
public String getContentType() throws MessagingException {
  return getWrappedMessage().getContentType();
}

代码示例来源: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: org.apache.james/apache-jsieve-mailet

public String getContentType() throws SieveMailException {
  try {
    return getMessage().getContentType();
  } catch (MessagingException e) {
    throw new SieveMailException(e);
  }
}

代码示例来源: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: org.apache.james/james-server-mailets

@Override
public String getContentType() throws SieveMailException {
  try {
    return getMessage().getContentType();
  } catch (MessagingException e) {
    throw new SieveMailException(e);
  }
}

代码示例来源:origin: no.difi.oxalis/oxalis-as2

public static String extractMicalg(MimeMessage message) throws OxalisAs2Exception {
    try {
      ContentType contentType = new ContentType(message.getContentType());
      String micalg = contentType.getParameter("micalg");
      if (micalg == null)
        throw new OxalisAs2Exception("Parameter 'micalg' is not provided.");

      return micalg;
    } catch (MessagingException e) {
      throw new OxalisAs2Exception("Unable to fetch content type.", e);
    }
  }
}

代码示例来源:origin: apache/oozie

public void testContentTypeDefault() throws Exception {
  EmailActionExecutor email = new EmailActionExecutor();
  email.validateAndMail(createAuthContext("email-action"), prepareEmailElement(true, true));
  checkEmail(server.getReceivedMessages()[0], true, true);
  assertTrue(server.getReceivedMessages()[0].getContentType().contains("text/plain"));
}

代码示例来源:origin: io.vertx/vertx-mail-client

protected AdditionalAsserts assertExampleMessage() {
 return () -> {
  final WiserMessage message = wiser.getMessages().get(0);
  testContext.assertEquals("from@example.com", message.getEnvelopeSender());
  final MimeMessage mimeMessage = message.getMimeMessage();
  assertThat(mimeMessage.getContentType(), containsString("text/plain"));
  testContext.assertEquals("Subject", mimeMessage.getSubject());
  testContext.assertEquals("Message\n", TestUtils.conv2nl(TestUtils.inputStreamToString(mimeMessage.getInputStream())));
 };
}

代码示例来源:origin: org.apache.james/james-core

@Test
public void buildShouldAllowToSpecifyMultipartSubtype() throws Exception {
  MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
    .setContent(MimeMessageBuilder.multipartBuilder()
      .subType("alternative")
      .addBody(MimeMessageBuilder.bodyPartBuilder().data("Body 1"))
      .addBody(MimeMessageBuilder.bodyPartBuilder().data("Body 2")))
    .build();
  assertThat(mimeMessage.getContentType())
    .startsWith("multipart/alternative");
}

代码示例来源:origin: apache/james-project

@Test
public void buildShouldAllowToSpecifyMultipartSubtype() throws Exception {
  MimeMessage mimeMessage = MimeMessageBuilder.mimeMessageBuilder()
    .setContent(MimeMessageBuilder.multipartBuilder()
      .subType("alternative")
      .addBody(MimeMessageBuilder.bodyPartBuilder().data("Body 1"))
      .addBody(MimeMessageBuilder.bodyPartBuilder().data("Body 2")))
    .build();
  assertThat(mimeMessage.getContentType())
    .startsWith("multipart/alternative");
}

相关文章

MimeMessage类方法