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

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

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

Mail.getRemoteHost介绍

[英]Returns the host name of the remote server that sent this message.
[中]返回发送此消息的远程服务器的主机名。

代码示例

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

private MimeBodyPart createDSN(Mail originalMail) throws MessagingException {
  StringBuffer buffer = new StringBuffer();
  appendReportingMTA(buffer);
  buffer.append("Received-From-MTA: dns; " + originalMail.getRemoteHost())
    .append(LINE_BREAK);
  for (MailAddress rec : originalMail.getRecipients()) {
    appendRecipient(buffer, rec, getDeliveryError(originalMail), originalMail.getLastUpdated());
  }
  MimeBodyPart bodyPart = new MimeBodyPart();
  bodyPart.setContent(buffer.toString(), "text/plain");
  bodyPart.setHeader("Content-Type", "message/delivery-status");
  bodyPart.setDescription("Delivery Status Notification");
  bodyPart.setFileName("status.dat");
  return bodyPart;
}

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

map.put(names[5], m.getLastUpdated().getTime());
map.put(names[6], m.getRemoteAddr());
map.put(names[7], m.getRemoteHost());
map.put(names[8], m.getErrorMessage());
Map<String, String> attrs = new HashMap<>();

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

.addContext(MDCBuilder.ACTION, "MATCHER")
.addContext(MDCBuilder.IP, mail.getRemoteAddr())
.addContext(MDCBuilder.HOST, mail.getRemoteHost())
.addContext("matcher", matcher.getMatcherInfo())
.addContext("state", mail.getState())

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

.addContext(MDCBuilder.PROTOCOL, "MAILET")
.addContext(MDCBuilder.ACTION, "MAILET")
.addContext(MDCBuilder.HOST, mail.getRemoteHost())
.addContext("state", mail.getState())
.addContext("mailet", mailet.getClass().getSimpleName())

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

LOGGER.info("Last updated: " + mail.getLastUpdated());
LOGGER.info("Remote Address: " + mail.getRemoteAddr());
LOGGER.info("Remote Host: " + mail.getRemoteHost());
LOGGER.info("State: " + mail.getState());
LOGGER.info("Sender host: " + mail.getMaybeSender().asOptional().map(mailAddress -> mailAddress.getDomain().name()));

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

相关文章