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

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

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

Mail.getAttribute介绍

[英]Returns the value of the named Mail instance attribute, or null if the attribute does not exist.
[中]返回命名邮件实例属性的值,如果该属性不存在,则返回null。

代码示例

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

private String locateFolder(String username, Mail mail) {
  if (mail.getAttribute(DELIVERY_PATH_PREFIX + username) instanceof String) {
    return (String) mail.getAttribute(DELIVERY_PATH_PREFIX + username);
  }
  return folder;
}

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

private static Optional<ImmutableMap<String, String>> fetchAttributes(Set<AdditionalField> additionalFields, Mail mail) {
  if (!additionalFields.contains(AdditionalField.ATTRIBUTES)) {
    return Optional.empty();
  }
  return Optional.of(Iterators.toStream(mail.getAttributeNames())
    .collect(Guavate.toImmutableMap(Function.identity(), attributeName -> mail.getAttribute(attributeName).toString())));
}

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

private String getDeliveryError(Mail originalMail) {
  String deliveryError = (String) originalMail.getAttribute("delivery-error");
  if (deliveryError != null) {
    return deliveryError;
  }
  return "unknown";
}

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

public static MailProjection from(Mail mail) {
  return new MailProjection(mail.getName(), mail.getRecipients(),
    Iterators.toStream(mail.getAttributeNames())
      .map(name -> Pair.of(name, mail.getAttribute(name)))
      .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue)));
}

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

/**
 * Returns the raw attribute value corresponding to an attribute name.
 *
 * Returns an empty optional upon missing attribute
 */
public static Optional<?> getAttributeValueFromMail(Mail mail, AttributeName name) {
  return mail
      .getAttribute(name)
      .map(AttributeUtils::getAttributeValue);
}

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

private Optional<ZonedDateTime> getNextDelivery(Mail mail) {
  Long next = (Long) mail.getAttribute(NEXT_DELIVERY);
  if (next == null) {
    return Optional.empty();
  }
  return Optional.of(Instant.ofEpochMilli(next).atZone(ZoneId.systemDefault()));
}

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

public Collection<MailAddress> match(Mail mail) {
    String relayingAllowed = (String) mail
        .getAttribute(SMTP_AUTH_NETWORK_NAME);
    if (relayingAllowed != null && relayingAllowed.equals("true")) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

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

public Collection<MailAddress> match(Mail mail) {
    String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
    if (authUser != null) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

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

public Collection<MailAddress> match(Mail mail) {
    String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
    if (authUser != null && users.contains(authUser)) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

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

@Test
void setAttributeShouldReturnValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  assertThat(mail.getAttribute(KEY)).isEqualTo(VALUE);
}

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

@Test
void getAttributeShouldReturnNullWhenNoAssociatedValue() {
  Mail mail = newMail();
  assertThat(mail.getAttribute(KEY)).isNull();
}

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

@Test
void setAttributeShouldReturnLatestValue() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  mail.setAttribute(KEY, NEW_VALUE);
  assertThat(mail.getAttribute(KEY)).isEqualTo(NEW_VALUE);
}

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

@Test
void getAttributeShouldNotReturnedNotStoreRemovedItems() {
  Mail mail = newMail();
  mail.removeAttribute(KEY);
  assertThat(mail.getAttribute(KEY)).isNull();
}

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

@Test
public void sendShouldPositionJMAPRelatedMetadata() throws Exception {
  FakeMail mail = FakeMail.builder()
    .name(NAME)
    .build();
  mailSpool.send(mail, new MailMetadata(MESSAGE_ID, USERNAME));
  MailQueueItem actual = myQueue.deQueue();
  assertThat(actual.getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE))
    .isEqualTo(USERNAME);
  assertThat(actual.getMail().getAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE))
    .isEqualTo(MESSAGE_ID.serialize());
}

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

@Test
void getAttributeShouldNotReturnDeletedElements() {
  Mail mail = newMail();
  mail.setAttribute(KEY, VALUE);
  mail.removeAttribute(KEY);
  assertThat(mail.getAttribute(KEY)).isNull();
}

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

@Test
public void vacationShouldNotSendNotificationToMailingLists() throws Exception {
  prepareTestUsingScript("org/apache/james/transport/mailets/delivery/vacationReason.script");
  Mail mail = createMail();
  mail.getMessage().addHeader("List-Id", "0123456789");
  testee.service(mail);
  assertThat(mail.getAttribute(MailStore.DELIVERY_PATH_PREFIX + LOCAL_PART)).isEqualTo(expressMailboxNameWithSlash(INBOX.getName()));
  assertThat(fakeMailContext.getSentMails()).isEmpty();
}

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

@Test
public void testNonSpam() throws Exception {
  SMTPSession session = setupMockedSMTPSession(setupMockedMail(setupMockedMimeMessage("test")));
  SpamAssassinHandler handler = new SpamAssassinHandler(new NoopMetricFactory());
  handler.setSpamdHost(SPAMD_HOST);
  handler.setSpamdPort(spamd.getPort());
  handler.setSpamdRejectionHits(200.0);
  HookResult response = handler.onMessage(session, mockedMail);
  assertThat(HookReturnCode.declined()).describedAs("Email was not rejected").isEqualTo(response.getResult());
  assertThat("NO").describedAs("email was not spam").isEqualTo(mockedMail.getAttribute(SpamAssassinResult.FLAG_MAIL_ATTRIBUTE_NAME));
  assertThat(mockedMail.getAttribute(STATUS_MAIL_ATTRIBUTE_NAME)).withFailMessage("spam hits").isNotNull();
}

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

@Test
public void serviceShouldSetMailPriorityWhenNone() throws Exception {
  MailetConfig mockedMailetConfig = FakeMailetConfig.builder()
    .mailetContext(FakeMailContext.defaultContext())
    .setProperty("priority", "7")
    .build();
  mailet.init(mockedMailetConfig);
  Mail mail = FakeMail.builder().build();
  mailet.service(mail);
  assertThat(mail.getAttribute(MailPrioritySupport.MAIL_PRIORITY)).isEqualTo(7);
}

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

@Test
void shouldBeRemovable() {
  SoftAssertions.assertSoftly(
    softly -> {
      softly.assertThat(mail.removeAttribute(ATTRIBUTE_NAME_1)).contains(ATTRIBUTE_1);
      softly.assertThat(mail.getAttribute(ATTRIBUTE_NAME_1)).isEmpty();
    }
  );
}

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

@Test
  void shouldBeReplacable() {
    SoftAssertions.assertSoftly(
      softly -> {
        softly.assertThat(mail.setAttribute(ATTRIBUTE_1_BIS)).contains(ATTRIBUTE_1);
        softly.assertThat(mail.getAttribute(ATTRIBUTE_NAME_1)).contains(ATTRIBUTE_1_BIS);
      }
    );
  }
}

相关文章