org.apache.mailet.Mail类的使用及代码示例

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

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

Mail介绍

[英]Wraps a MimeMessage with additional routing and processing information.

This includes

  • a unique name
  • envelope properties such the SMTP-specified sender ("MAIL FROM") and recipients ("RCPT TO")
  • the IP address and hostname of the sending server
  • the processing state, which also represents the processor in the mailet container which is currently processing the message
  • the time at which the Mail was last updated
  • additional processing attributes (see below)

The Mail interface also defines constants for special processor names, such as "root" and "error".

Mail Attributes

While processing a Mail instance, a Mailet can associate additional information with it by using mail attributes. These attributes can then be queried by the same mailet or other mailets later on.

Some containers may also use attributes to provide envelope information.

Every attribute consists of a name and a value. Attribute names should follow the same convention as package names. The Mailet API specification reserves names matching org.apache.james.* and org.apache.mailet.*.

Attribute values can be arbitrary objects, but since Mail is Serializable, the attribute value must be Serializable as well.

The list of attributes which are currently associated with a Mail instance can be retrieved using the #getAttributeNamesmethod, and given its name, the value of an attribute can be retrieved using the #getAttribute method. It is also possible to remove #removeAttribute attribute or #removeAllAttributes() attributes of a Mail instance.
[中]用额外的路由和处理信息包装mimessage。
这包括
*唯一的名字
*信封属性,例如SMTP指定的发件人(“邮件发件人”)和收件人(“收件人”)
*发送服务器的IP地址和主机名
*处理状态,它还表示邮件容器中当前正在处理消息的处理器
*上次更新邮件的时间
*其他处理属性(见下文)
邮件接口还为特殊处理器名称定义常量,例如“root”和“error”。
邮件属性
在处理邮件实例时,邮件集可以使用邮件属性将其他信息与之关联。这些属性随后可以由同一邮件集或其他邮件集查询。
一些容器还可以使用属性来提供信封信息。
每个属性都由一个名称和一个值组成。属性名称应遵循与包名称相同的约定。Mailet API规范保留与组织匹配的名称。阿帕奇。詹姆斯。和组织。阿帕奇。mailet.
属性值可以是任意对象,但由于邮件是可序列化的,因此属性值也必须是可序列化的。
当前与邮件实例关联的属性列表可以使用#GetAttributeNameMethod进行检索,给定其名称,可以使用#getAttribute方法检索属性值。还可以删除邮件实例的#removeAttribute属性或#removeAllAttributes()属性。

代码示例

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

public Collection<MailAddress> match(Mail mail) throws MessagingException {
    MimeMessage mm = mail.getMessage();
    String subject = mm.getSubject();
    if (subject != null && subject.startsWith(getCondition())) {
      return mail.getRecipients();
    }
    return null;
  }
}

代码示例来源: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

@Override
  public void service(Mail mail) throws MessagingException {
    mail.setAttribute(MailPrioritySupport.MAIL_PRIORITY, priority);
  }
}

代码示例来源: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) {
    if (senders.contains(mail.getSender())) {
      return mail.getRecipients();
    } else {
      return null;
    }
  }
}

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

@Override
public void service(Mail mail) {
  if (!(Mail.ERROR.equals(mail.getState()))) {
    // Don't complain if we fall off the end of the
    // error processor. That is currently the
    // normal situation for James, and the message
    // will show up in the error store.
    LOGGER.warn("Message {} reached the end of this processor, and is automatically deleted. " +
      "This may indicate a configuration error.", mail.getName());
  }
  // Set the mail to ghost state
  mail.setState(Mail.GHOST);
}

代码示例来源: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());
  }));
}

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

/**
 * @param mail
 * @param newName
 * @throws MessagingException
 */
public MailImpl(Mail mail, String newName) throws MessagingException {
  this(newName, mail.getSender(), mail.getRecipients(), mail.getMessage());
  setRemoteHost(mail.getRemoteHost());
  setRemoteAddr(mail.getRemoteAddr());
  setLastUpdated(mail.getLastUpdated());
  try {
    if (mail instanceof MailImpl) {
      setAttributesRaw((HashMap) cloneSerializableObject(((MailImpl) mail).getAttributesRaw()));
    } else {
      HashMap attribs = new HashMap();
      for (Iterator i = mail.getAttributeNames(); i.hasNext(); ) {
        String hashKey = (String) i.next();
        attribs.put(hashKey,cloneSerializableObject(mail.getAttribute(hashKey)));
      }
      setAttributesRaw(attribs);
    }
  } catch (IOException e) {
    // should never happen for in memory streams
    setAttributesRaw(new HashMap());
  } catch (ClassNotFoundException e) {
    // should never happen as we just serialized it
    setAttributesRaw(new HashMap());
  }
}

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

/**
 * Writes the mail message to the given mail node.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws MessagingException
 *             if a messaging error occurs
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void setMail(Node node, Mail mail) throws MessagingException, RepositoryException, IOException {
  setState(node, mail.getState());
  setLastUpdated(node, mail.getLastUpdated());
  setError(node, mail.getErrorMessage());
  setRemoteHost(node, mail.getRemoteHost());
  setRemoteAddr(node, mail.getRemoteAddr());
  setSender(node, mail.getMaybeSender());
  setRecipients(node, mail.getRecipients());
  setMessage(node, mail.getMessage());
  setAttributes(node, mail);
}

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

public static MailDto fromMail(Mail mail, Set<AdditionalField> additionalFields) throws MessagingException, InaccessibleFieldException {
  Optional<MessageContent> messageContent = fetchMessage(additionalFields, mail);
  return new MailDto(mail.getName(),
    mail.getMaybeSender().asOptional().map(MailAddress::asString),
    mail.getRecipients().stream().map(MailAddress::asString).collect(Guavate.toImmutableList()),
    Optional.ofNullable(mail.getErrorMessage()),
    Optional.ofNullable(mail.getState()),
    Optional.ofNullable(mail.getRemoteHost()),
    Optional.ofNullable(mail.getRemoteAddr()),
    Optional.ofNullable(mail.getLastUpdated()),
    fetchAttributes(additionalFields, mail),
    fetchPerRecipientsHeaders(additionalFields, mail),
    fetchHeaders(additionalFields, mail),
    fetchTextBody(additionalFields, messageContent),
    fetchHtmlBody(additionalFields, messageContent),
    fetchMessageSize(additionalFields, mail));
}

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

/**
 * Writes the mail message to the given mail node.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws MessagingException
 *             if a messaging error occurs
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void setMail(Node node, Mail mail) throws MessagingException, RepositoryException, IOException {
  setState(node, mail.getState());
  setLastUpdated(node, mail.getLastUpdated());
  setError(node, mail.getErrorMessage());
  setRemoteHost(node, mail.getRemoteHost());
  setRemoteAddr(node, mail.getRemoteAddr());
  setSender(node, mail.getSender());
  setRecipients(node, mail.getRecipients());
  setMessage(node, mail.getMessage());
  setAttributes(node, mail);
}

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

@Override
public void service(Mail mail) throws MessagingException {
  String remoteAddr = mail.getRemoteAddr();
  String helo = mail.getRemoteHost();
  if (!remoteAddr.equals("127.0.0.1")) {
    String sender = mail.getMaybeSender().asString("");
    SPFResult result = spf.checkSPF(remoteAddr, sender, helo);
    mail.setAttribute(EXPLANATION_ATTRIBUTE, result.getExplanation());
    mail.setAttribute(RESULT_ATTRIBUTE, result.getResult());
    LOGGER.debug("ip:{} from:{} helo:{} = {}", remoteAddr, sender, helo, result.getResult());
    if (addHeader) {
      try {
        MimeMessage msg = mail.getMessage();
        msg.addHeader(result.getHeaderName(), result.getHeaderText());
        msg.saveChanges();
      } catch (MessagingException e) {
        // Ignore not be able to add headers
      }
    }
  }
}

代码示例来源: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

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: 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

@Override
  public MimeMessageModifier getMimeMessageModifier(Mail newMail, Mail originalMail) throws MessagingException {
    return new MimeMessageModifier(originalMail.getMessage());
  }
}

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

private Stream<Pair<String, byte[]>> toJson(Map.Entry<String, Calendar> entry, Map<String, byte[]> rawCalendars, Mail mail, String sender) {
  return mail.getRecipients()
    .stream()
    .flatMap(recipient -> toICAL(entry, rawCalendars, recipient, sender))
    .flatMap(ical -> toJson(ical, mail.getName()))
    .map(json -> Pair.of(UUID.randomUUID().toString(), json.getBytes(StandardCharsets.UTF_8)));
}

代码示例来源: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-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-mailets

private void serviceSingleServer(Mail mail, String originalName, Map.Entry<Domain, Collection<MailAddress>> entry) {
  if (configuration.isDebug()) {
    LOGGER.debug("Sending mail to {} on host {}", entry.getValue(), entry.getKey());
  }
  mail.setRecipients(entry.getValue());
  mail.setName(originalName + NAME_JUNCTION + entry.getKey().name());
  try {
    queue.enQueue(mail);
  } catch (MailQueueException e) {
    LOGGER.error("Unable to queue mail {} for recipients {}", mail.getName(), mail.getRecipients(), e);
  }
}

相关文章