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

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

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

Mail.getMaybeSender介绍

[英]Returns the sender of the message, as specified by the SMTP "MAIL FROM" command, or internally defined. 'null' or MailAddress#nullSender() are handled with MaybeSender#nullSender().
[中]返回SMTP“MAIL FROM”命令指定的或内部定义的邮件发件人null'或MailAddress#nullSender()由MaybeSender#nullSender()处理。

代码示例

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

/**
 * Returns if this message has a sender.
 *
 * {@link MaybeSender#nullSender()} will be considered as no sender.
 *
 * @since Mailet API v3.2.0
 */
default boolean hasSender() {
  return !getMaybeSender().isNullSender();
}

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

/**
 * Returns if this message has a sender.
 *
 * {@link MaybeSender#nullSender()} will be considered as no sender.
 *
 * @since Mailet API v3.2.0
 */
default boolean hasSender() {
  return !getMaybeSender().isNullSender();
}

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

private boolean senderIsMailingList(Mail mail) {
  return mail.getMaybeSender()
    .asOptional()
    .map(MailAddress::getLocalPart)
    .map(localPart ->  localPart.startsWith("owner-")
      || localPart.endsWith("-request")
      || localPart.equalsIgnoreCase("MAILER-DAEMON")
      || localPart.equalsIgnoreCase("LISTSERV")
      || localPart.equalsIgnoreCase("majordomo"))
    .orElse(false);
}

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

public Optional<MailAddress> getReplyTo(Mail originalMail) {
    if (replyTo.isPresent()) {
      if (replyTo.get().equals(SpecialAddress.UNALTERED)) {
        return Optional.empty();
      }
      return originalMail.getMaybeSender().asOptional();
    }
    return Optional.empty();
  }
}

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

private Optional<DLPConfigurationItem.Id> findFirstMatchingRule(Mail mail) {
  return mail.getMaybeSender()
      .asOptional()
      .flatMap(sender -> matchingRule(sender, mail));
}

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

private boolean isSenderLocal(Mail mail) {
  return mail.getMaybeSender().asOptional()
    .map(MailAddress::getDomain)
    .map(domain -> getMailetContext().isLocalServer(domain))
    .orElse(false);
}

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

private List<MailAddress> allOrSender(Mail mail, InternetAddress[] addresses) throws AddressException {
  if (addresses != null) {
    return MailAddressUtils.from(addresses);
  } else {
    return mail.getMaybeSender().asList();
  }
}

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

/**
 * Returns the from.
 * 
 * @return String
 */
public String getEnvelopeFrom() {
  return getMail().getMaybeSender().asString("");
}

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

@Override
public void service(Mail mail) throws MessagingException {
  String domain = mail.getMaybeSender()
    .asOptional()
    .map(MailAddress::getDomain)
    .map(Domain::asString)
    .orElse("");
  MailRepositoryUrl repositoryUrl = MailRepositoryUrl.from(urlPrefix + domain);
  store(mail, repositoryUrl);
  if (!passThrough) {
    mail.setState(Mail.GHOST);
  }
}

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

@Override
  public void service(Mail mail) {
    LOGGER.info("Hello, World!");
    LOGGER.info("You have mail from {}", mail.getMaybeSender().asOptional().map(MailAddress::getLocalPart));
  }
}

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

private List<MailAddress> getSenderAsList(Mail originalMail) {
  MaybeSender reversePath = originalMail.getMaybeSender();
  if (getInitParameters().isDebug()) {
    LOGGER.debug("Processing a bounce request for a message with a reverse path.  The bounce will be sent to {}", reversePath.asString());
  }
  return reversePath.asList();
}

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

public VacationReply build(MimeMessageBodyGenerator mimeMessageBodyGenerator) throws MessagingException {
  Preconditions.checkState(mailRecipient != null, "Original recipient address should not be null");
  Preconditions.checkState(originalMail.hasSender(), "Original sender address should not be null");
  return new VacationReply(mailRecipient, OptionalUtils.toList(originalMail.getMaybeSender().asOptional()), generateMimeMessage(mimeMessageBodyGenerator));
}

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

public VacationReply build() throws MessagingException {
  Preconditions.checkState(eitherReasonOrMime());
  ActionUtils.detectAndHandleLocalLooping(originalMail, context, "vacation");
  MimeMessage reply = (MimeMessage) originalMail.getMessage().reply(false);
  reply.setSubject(generateNotificationSubject());
  reply.setContent(generateNotificationContent());
  return new VacationReply(retrieveOriginalSender(), ImmutableList.of(originalMail.getMaybeSender().get()), reply);
}

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

public SMTPMessageSender sendMessage(Mail mail) throws MessagingException, IOException {
  String from = mail.getMaybeSender().asString();
  doHelo();
  doSetSender(from);
  mail.getRecipients().stream()
    .map(MailAddress::asString)
    .forEach(Throwing.consumer(this::doAddRcpt));
  doData(asString(mail.getMessage()));
  return this;
}

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

private List<MailAddress> customizeHeadersAndDeliver(Mail mail) throws MessagingException {
  MimeMessage message = mail.getMessage();
  // Set Return-Path and remove all other Return-Path headers from the message
  // This only works because there is a placeholder inserted by MimeMessageWrapper
  message.setHeader(RFC2822Headers.RETURN_PATH, mail.getMaybeSender().asPrettyString());
  List<MailAddress> errors = deliver(mail, message);
  return errors;
}

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

private void doService(Mail mail) throws MessagingException {
  if (mail.hasSender()) {
    MailAddress sender = mail.getMaybeSender().get();
    String username = retrieveUser(sender);
    mailboxAppender.append(mail.getMessage(), username, folder);
    LOGGER.error("Local delivery with ToSenderFolder mailet for mail {} with sender {} in folder {}", mail.getName(), sender, folder);
  }
}

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

@Override
public void storeMail(MailAddress recipient, Mail mail) throws MessagingException {
  String username = computeUsername(recipient);
  String locatedFolder = locateFolder(username, mail);
  ComposedMessageId composedMessageId = mailboxAppender.append(mail.getMessage(), username, locatedFolder);
  metric.increment();
  LOGGER.info("Local delivered mail {} successfully from {} to {} in folder {} with composedMessageId {}", mail.getName(),
    mail.getMaybeSender().asString(), recipient.asPrettyString(), locatedFolder, composedMessageId);
}

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

public CompletableFuture<Void> manageVacation(MailAddress recipient, Mail processedMail, ZonedDateTime processingDate) {
  AccountId accountId = AccountId.fromString(recipient.toString());
  return CompletableFutureUtil.combine(
      vacationRepository.retrieveVacation(accountId),
      notificationRegistry.isRegistered(
        AccountId.fromString(recipient.toString()),
        RecipientId.fromMailAddress(processedMail.getMaybeSender().get())),
      (vacation, alreadySent) ->
        sendNotificationIfRequired(recipient, processedMail, processingDate, vacation, alreadySent))
    .thenCompose(Function.identity());
}

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

public static MailQueueItemDTO from(ManageableMailQueue.MailQueueItemView mailQueueItemView) {
  return builder()
      .name(mailQueueItemView.getMail().getName())
      .sender(mailQueueItemView.getMail().getMaybeSender().asOptional())
      .recipients(mailQueueItemView.getMail().getRecipients())
      .nextDelivery(mailQueueItemView.getNextDelivery())
      .build();
}

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

@Test
default void storeRegularMailShouldNotFailWhenNullSender() throws Exception {
  MailRepository testee = retrieveRepository();
  Mail mail = FakeMail.builder()
    .sender(MailAddress.nullSender())
    .recipient(MailAddressFixture.RECIPIENT1)
    .name(MAIL_1.asString())
    .mimeMessage(generateMailContent("String body"))
    .build();
  testee.store(mail);
  assertThat(testee.retrieve(MAIL_1).getMaybeSender()).isEqualTo(MaybeSender.nullSender());
}

相关文章