org.apache.mailet.Mail.getPerRecipientSpecificHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(150)

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

Mail.getPerRecipientSpecificHeaders介绍

[英]Get the currently stored association between recipients and specific headers
[中]获取当前存储的收件人和特定标题之间的关联

代码示例

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

private Map<String, List<String>> saveHeaders(Mail mail, MailAddress recipient) throws MessagingException {
  ImmutableMap.Builder<String, List<String>> backup = ImmutableMap.builder();
  Collection<String> headersToSave = mail.getPerRecipientSpecificHeaders().getHeaderNamesForRecipient(recipient);
  for (String headerName: headersToSave) {
    List<String> values = ImmutableList.copyOf(
          Optional.ofNullable(mail.getMessage().getHeader(headerName))
            .orElse(NO_HEADERS));
    backup.put(headerName, values);
  }
  return backup.build();
}

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

public boolean isMarkedAsSpam(Mail mail, MailAddress recipient) {
  return mail.getPerRecipientSpecificHeaders().getHeadersForRecipient(recipient)
    .stream()
    .filter(header -> header.getName().equals(SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME))
    .anyMatch(header -> header.getValue().toLowerCase(Locale.US).startsWith(YES));
}

代码示例来源:origin: org.apache.james/james-server-webadmin-mailrepository

private static Optional<ImmutableMap<String, HeadersDto>> fetchPerRecipientsHeaders(Set<AdditionalField> additionalFields, Mail mail) {
  if (!additionalFields.contains(AdditionalField.PER_RECIPIENTS_HEADERS)) {
    return Optional.empty();
  }
  Multimap<MailAddress, PerRecipientHeaders.Header> headersByRecipient = mail
      .getPerRecipientSpecificHeaders()
      .getHeadersByRecipient();
  return Optional.of(headersByRecipient
    .keySet()
    .stream()
    .collect(Guavate.toImmutableMap(MailAddress::asString, (address) -> fetchPerRecipientHeader(headersByRecipient, address))));
}

代码示例来源:origin: org.apache.james/james-server-queue-jms

protected Map<String, Object> getJMSProperties(Mail mail, long nextDelivery) throws MessagingException {
  Map<String, Object> props = new HashMap<>();
  props.put(JAMES_NEXT_DELIVERY, nextDelivery);
  props.put(JAMES_MAIL_ERROR_MESSAGE, mail.getErrorMessage());
  props.put(JAMES_MAIL_LAST_UPDATED, mail.getLastUpdated().getTime());
  props.put(JAMES_MAIL_MESSAGE_SIZE, mail.getMessageSize());
  props.put(JAMES_MAIL_NAME, mail.getName());
  // won't serialize the empty headers so it is mandatory
  // to handle nulls when reconstructing mail from message
  if (!mail.getPerRecipientSpecificHeaders().getHeadersByRecipient().isEmpty()) {
    props.put(JAMES_MAIL_PER_RECIPIENT_HEADERS, SerializationUtil.serialize(mail.getPerRecipientSpecificHeaders()));
  }
  String recipientsAsString = joiner.join(mail.getRecipients());
  props.put(JAMES_MAIL_RECIPIENTS, recipientsAsString);
  props.put(JAMES_MAIL_REMOTEADDR, mail.getRemoteAddr());
  props.put(JAMES_MAIL_REMOTEHOST, mail.getRemoteHost());
  String sender = mail.getMaybeSender().asString("");
  org.apache.james.util.streams.Iterators.toStream(mail.getAttributeNames())
      .forEach(attrName -> props.put(attrName, SerializationUtil.serialize(mail.getAttribute(attrName))));
  props.put(JAMES_MAIL_ATTRIBUTE_NAMES, joiner.join(mail.getAttributeNames()));
  props.put(JAMES_MAIL_SENDER, sender);
  props.put(JAMES_MAIL_STATE, mail.getState());
  return props;
}

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

private void addSpecificHeadersForRecipient(Mail mail, MimeMessage message, MailAddress recipient) throws MessagingException {
    for (Header header: mail.getPerRecipientSpecificHeaders().getHeadersForRecipient(recipient)) {
      message.addHeader(header.getName(), header.getValue());
    }
  }
}

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

@Test
public void serviceShouldWriteSpamAttributeOnMail() throws Exception {
  FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder()
    .mailetName("SpamAssassin")
    .setProperty(SpamAssassin.SPAMD_HOST, "localhost")
    .setProperty(SpamAssassin.SPAMD_PORT, String.valueOf(spamd.getPort()))
    .build();
  mailet.init(mailetConfiguration);
  Mail mail = FakeMail.builder()
    .recipient("user1@exemple.com")
    .mimeMessage(MimeMessageBuilder.mimeMessageBuilder()
      .addToRecipient("user1@exemple.com")
      .addFrom("sender@exemple.com")
      .setSubject("testing")
      .setText("Please!")
      .build())
    .build();
  mailet.service(mail);
  assertThat(
    mail.getPerRecipientSpecificHeaders()
      .getHeadersByRecipient()
      .get(new MailAddress("user1@exemple.com"))
      .stream()
      .map(PerRecipientHeaders.Header::getName)
      .collect(Guavate.toImmutableList()))
    .contains(SpamAssassinResult.FLAG_MAIL_ATTRIBUTE_NAME, SpamAssassinResult.STATUS_MAIL_ATTRIBUTE_NAME);
}

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

assertThat(mail.getPerRecipientSpecificHeaders())
  .isEqualTo(new PerRecipientHeaders()
    .addHeaderForRecipient(

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

assertThat(mail.getPerRecipientSpecificHeaders())
  .isEqualTo(new PerRecipientHeaders()
    .addHeaderForRecipient(

代码示例来源:origin: org.apache.james/james-server-mailrepository-api

default void checkMailEquality(Mail actual, Mail expected) {
  assertSoftly(Throwing.consumer(softly -> {
    softly.assertThat(actual.getMessage().getContent()).isEqualTo(expected.getMessage().getContent());
    softly.assertThat(actual.getMessageSize()).isEqualTo(expected.getMessageSize());
    softly.assertThat(actual.getName()).isEqualTo(expected.getName());
    softly.assertThat(actual.getState()).isEqualTo(expected.getState());
    softly.assertThat(actual.getAttribute(TEST_ATTRIBUTE)).isEqualTo(expected.getAttribute(TEST_ATTRIBUTE));
    softly.assertThat(actual.getErrorMessage()).isEqualTo(expected.getErrorMessage());
    softly.assertThat(actual.getRemoteHost()).isEqualTo(expected.getRemoteHost());
    softly.assertThat(actual.getRemoteAddr()).isEqualTo(expected.getRemoteAddr());
    softly.assertThat(actual.getLastUpdated()).isEqualTo(expected.getLastUpdated());
    softly.assertThat(actual.getPerRecipientSpecificHeaders()).isEqualTo(expected.getPerRecipientSpecificHeaders());
  }));
}

相关文章