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

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

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

MimeMessage.getHeader介绍

[英]Get all the headers for this header_name. Note that certain headers may be encoded as per RFC 2047 if they contain non US-ASCII characters and these should be decoded.

This implementation obtains the headers from the headers InternetHeaders object.
[中]获取此标题名称的所有标题。请注意,如果某些标头包含非US-ASCII字符,则可以按照RFC 2047对其进行编码,并应对其进行解码。
此实现从headersInternetHeaders对象获取头。

代码示例

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

Session session=Session.getDefaultInstance(new Properties());
MimeMessage mimeMsg= new MimeMessage(session);
String subject="Herr Müller reist nach \u0141\u00f3d\u017a.";
mimeMsg.setSubject(subject,"utf-8");
System.out.println(subject);
System.out.println(mimeMsg.getHeader("Subject")[0]);

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldSendTestEmail() throws Exception {
 configure();
 underTest.sendTestEmail("user@nowhere", "Test Message from SonarQube", "This is a test message from SonarQube.");
 List<WiserMessage> messages = smtpServer.getMessages();
 assertThat(messages).hasSize(1);
 MimeMessage email = messages.get(0).getMimeMessage();
 assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8");
 assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube from NoWhere <server@nowhere>");
 assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>");
 assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube");
 assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube.");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldSendNonThreadedEmail() throws Exception {
 configure();
 EmailMessage emailMessage = new EmailMessage()
  .setTo("user@nowhere")
  .setSubject("Foo")
  .setMessage("Bar");
 boolean delivered = underTest.deliver(emailMessage);
 List<WiserMessage> messages = smtpServer.getMessages();
 assertThat(messages).hasSize(1);
 MimeMessage email = messages.get(0).getMimeMessage();
 assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8");
 assertThat(email.getHeader("In-Reply-To", null)).isNull();
 assertThat(email.getHeader("References", null)).isNull();
 assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>");
 assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org");
 assertThat(email.getHeader("From", null)).isEqualTo("SonarQube from NoWhere <server@nowhere>");
 assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>");
 assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo");
 assertThat((String) email.getContent()).startsWith("Bar");
 assertThat(delivered).isTrue();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldSendThreadedEmail() throws Exception {
 configure();
 EmailMessage emailMessage = new EmailMessage()
  .setMessageId("reviews/view/1")
  .setFrom("Full Username")
  .setTo("user@nowhere")
  .setSubject("Review #3")
  .setMessage("I'll take care of this violation.");
 boolean delivered = underTest.deliver(emailMessage);
 List<WiserMessage> messages = smtpServer.getMessages();
 assertThat(messages).hasSize(1);
 MimeMessage email = messages.get(0).getMimeMessage();
 assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8");
 assertThat(email.getHeader("In-Reply-To", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>");
 assertThat(email.getHeader("References", null)).isEqualTo("<reviews/view/1@nemo.sonarsource.org>");
 assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube <sonar.nemo.sonarsource.org>");
 assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org");
 assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube from NoWhere)\" <server@nowhere>");
 assertThat(email.getHeader("To", null)).isEqualTo("<user@nowhere>");
 assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3");
 assertThat((String) email.getContent()).startsWith("I'll take care of this violation.");
 assertThat(delivered).isTrue();
}

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

/**
 * Returns the value of the "Content-ID" header field. Returns
 * <code>null</code> if the field is unavailable or its value is 
 * absent. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          content-ID
 * @exception    MessagingException for failures
 */
public String getContentID() throws MessagingException {
return getHeader("Content-Id", null);
}

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

/**
 * Return the value of the "Content-MD5" header field. Returns 
 * <code>null</code> if this field is unavailable or its value
 * is absent. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          content-MD5
 * @exception    MessagingException for failures
 */
public String getContentMD5() throws MessagingException {
return getHeader("Content-MD5", null);
}

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

/**
 * Return the value of the "Content-MD5" header field. Returns 
 * <code>null</code> if this field is unavailable or its value
 * is absent. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          content-MD5
 * @exception    MessagingException for failures
 */
@Override
public String getContentMD5() throws MessagingException {
return getHeader("Content-MD5", null);
}

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

/**
 * Returns the value of the "Content-ID" header field. Returns
 * <code>null</code> if the field is unavailable or its value is 
 * absent. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          content-ID
 * @exception    MessagingException for failures
 */
@Override
public String getContentID() throws MessagingException {
return getHeader("Content-Id", null);
}

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

/**
 * Returns the value of the "Message-ID" header field. Returns
 * null if this field is unavailable or its value is absent. <p>
 *
 * The default implementation provided here uses the
 * <code>getHeader</code> method to return the value of the
 * "Message-ID" field.
 *
 * @return     Message-ID
 * @exception  MessagingException if the retrieval of this field
 *            causes any exception.
 * @see        javax.mail.search.MessageIDTerm
 * @since        JavaMail 1.1
 */
public String getMessageID() throws MessagingException {
return getHeader("Message-ID", null);
}

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

/**
 * Returns the value of the "Message-ID" header field. Returns
 * null if this field is unavailable or its value is absent. <p>
 *
 * The default implementation provided here uses the
 * <code>getHeader</code> method to return the value of the
 * "Message-ID" field.
 *
 * @return     Message-ID
 * @exception  MessagingException if the retrieval of this field
 *            causes any exception.
 * @see        javax.mail.search.MessageIDTerm
 * @since        JavaMail 1.1
 */
public String getMessageID() throws MessagingException {
return getHeader("Message-ID", null);
}

代码示例来源:origin: cloudfoundry/uaa

@Test
void testCreatingAnAccountWithNoClientRedirect() throws Exception {
  PredictableGenerator generator = new PredictableGenerator();
  JdbcExpiringCodeStore store = webApplicationContext.getBean(JdbcExpiringCodeStore.class);
  store.setGenerator(generator);
  mockMvc.perform(post("/create_account.do")
      .with(cookieCsrf())
      .param("email", userEmail)
      .param("password", "secr3T")
      .param("password_confirmation", "secr3T"))
      .andExpect(status().isFound())
      .andExpect(redirectedUrl("accounts/email_sent"));
  FakeJavaMailSender.MimeMessageWrapper message = fakeJavaMailSender.getSentMessages().get(0);
  assertTrue(message.getContentString().contains("Cloud Foundry"));
  assertThat(message.getMessage().getHeader("From"), hasItemInArray("Cloud Foundry <admin@localhost>"));
  mockMvc.perform(get("/verify_user")
      .param("code", "test" + generator.counter.get()))
      .andExpect(status().isFound())
      .andExpect(redirectedUrl(LOGIN_REDIRECT))
      .andReturn();
  MvcResult mvcResult = loginWithAccount("")
      .andExpect(authenticated())
      .andReturn();
  SecurityContext securityContext = (SecurityContext) mvcResult.getRequest().getSession().getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
  Authentication authentication = securityContext.getAuthentication();
  assertThat(authentication.getPrincipal(), instanceOf(UaaPrincipal.class));
  UaaPrincipal principal = (UaaPrincipal) authentication.getPrincipal();
  assertThat(principal.getEmail(), equalTo(userEmail));
  assertThat(principal.getOrigin(), equalTo(OriginKeys.UAA));
}

代码示例来源:origin: cloudfoundry/uaa

assertThat(message.getMessage().getHeader("From"), hasItemInArray("Cloud Foundry <admin@localhost>"));

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

private Address[] getAddressHeader(String name) 
    throws MessagingException {
String s = getHeader(name, ",");
return (s == null) ? null : InternetAddress.parseHeader(s, strict);
}

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

private Address[] getAddressHeader(String name) 
    throws MessagingException {
String s = getHeader(name, ",");
return (s == null) ? null : InternetAddress.parseHeader(s, strict);
}

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

/**
 * 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. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          The ContentType of this part
 * @exception    MessagingException for failures
 * @see             javax.activation.DataHandler
 */
public String getContentType() throws MessagingException {
String s = getHeader("Content-Type", null);
s = MimeUtil.cleanContentType(this, s);
if (s == null)
  return "text/plain";
return s;
}

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

/**
 * 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. <p>
 *
 * This implementation uses the <code>getHeader</code> method
 * to obtain the requisite header field.
 *
 * @return          The ContentType of this part
 * @exception    MessagingException for failures
 * @see             javax.activation.DataHandler
 */
@Override
public String getContentType() throws MessagingException {
String s = getHeader("Content-Type", null);
s = MimeUtil.cleanContentType(this, s);
if (s == null)
  return "text/plain";
return s;
}

代码示例来源:origin: cloudfoundry/uaa

String link = mockMvcTestClient.extractLink(message.getContentString());
assertTrue(message.getContentString().contains(subdomain + "zone"));
assertThat(message.getMessage().getHeader("From"), hasItemInArray(subdomain + "zone <admin@localhost>"));
assertFalse(message.getContentString().contains("Cloud Foundry"));
assertFalse(message.getContentString().contains("Pivotal"));

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

/**
 * Get the In-Reply-To header.
 *
 * @return    the In-Reply-To header
 * @exception    MessagingException for failures
 * @since    JavaMail 1.3.3
 */
public String getInReplyTo() throws MessagingException {
  checkExpunged();
if (bodyLoaded)
  return super.getHeader("In-Reply-To", " ");
  loadEnvelope();
  return envelope.inReplyTo;
}

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

/**
 * Get the In-Reply-To header.
 *
 * @return    the In-Reply-To header
 * @exception    MessagingException for failures
 * @since    JavaMail 1.3.3
 */
public String getInReplyTo() throws MessagingException {
  checkExpunged();
if (bodyLoaded)
  return super.getHeader("In-Reply-To", " ");
  loadEnvelope();
  return envelope.inReplyTo;
}

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

@Deployment
public void testSendEmail() throws Exception {
 String from = "ordershipping@activiti.org";
 boolean male = true;
 String recipientName = "John Doe";
 String recipient = "johndoe@alfresco.com";
 Date now = new Date();
 String orderId = "123456";
 Map<String, Object> vars = new HashMap<String, Object>();
 vars.put("sender", from);
 vars.put("recipient", recipient);
 vars.put("recipientName", recipientName);
 vars.put("male", male);
 vars.put("now", now);
 vars.put("orderId", orderId);
 runtimeService.startProcessInstanceByKey("sendMailExample", vars);
 List<WiserMessage> messages = wiser.getMessages();
 assertEquals(1, messages.size());
 WiserMessage message = messages.get(0);
 MimeMessage mimeMessage = message.getMimeMessage();
 assertEquals("Your order " + orderId + " has been shipped", mimeMessage.getHeader("Subject", null));
 assertEquals(from, mimeMessage.getHeader("From", null));
 assertTrue(mimeMessage.getHeader("To", null).contains(recipient));
}

相关文章

MimeMessage类方法