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

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

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

Mail.getAttributeNames介绍

[英]Returns an Iterator over the names of all attributes which are set in this Mail instance.

The #getAttribute method can be called to retrieve an attribute's value given its name.
[中]返回在此邮件实例中设置的所有属性的名称的迭代器。
可以调用#getAttribute方法来检索给定名称的属性值。

代码示例

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

/**
 * Writes the mail attributes to the <code>jamesattr:*</code> property.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void setAttributes(Node node, Mail mail) throws RepositoryException, IOException {
  Iterator<String> iterator = mail.getAttributeNames();
  while (iterator.hasNext()) {
    String name = (String) iterator.next();
    Object value = mail.getAttribute(name);
    name = "jamesattr:" + Text.escapeIllegalJcrChars(name);
    if (value instanceof String || value == null) {
      node.setProperty(name, (String) value);
    } else {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutputStream output = new ObjectOutputStream(buffer);
      output.writeObject(value);
      output.close();
      node.setProperty(name, new ByteArrayInputStream(buffer.toByteArray()));
    }
  }
}

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

/**
 * Writes the mail attributes to the <code>jamesattr:*</code> property.
 * 
 * @param node
 *            mail node
 * @param mail
 *            mail message
 * @throws RepositoryException
 *             if a repository error occurs
 * @throws IOException
 *             if an IO error occurs
 */
private void setAttributes(Node node, Mail mail) throws RepositoryException, IOException {
  Iterator<String> iterator = mail.getAttributeNames();
  while (iterator.hasNext()) {
    String name = iterator.next();
    Object value = mail.getAttribute(name);
    name = "jamesattr:" + Text.escapeIllegalJcrChars(name);
    if (value instanceof String || value == null) {
      node.setProperty(name, (String) value);
    } else {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutputStream output = new ObjectOutputStream(buffer);
      output.writeObject(value);
      output.close();
      node.setProperty(name, new ByteArrayInputStream(buffer.toByteArray()));
    }
  }
}

代码示例来源: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[8], m.getErrorMessage());
Map<String, String> attrs = new HashMap<>();
Iterator<String> attrNames = m.getAttributeNames();
while (attrNames.hasNext()) {
  String attrName = attrNames.next();

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

@Test
void getAttributeNamesShouldReturnEmptyByDefault() {
  Mail mail = newMail();
  assertThat(mail.getAttributeNames()).isEmpty();
}

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

@Test
  void getAttributeNamesShouldReturnAttributeNames() {
    Mail mail = newMail();
    mail.setAttribute(KEY, VALUE);
    assertThat(mail.getAttributeNames()).containsOnly(KEY);
  }
}

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

LOGGER.info("Mail named: " + mail.getName());
for (Iterator<String> it = mail.getAttributeNames(); it.hasNext();) {
  String attributeName = it.next();
  LOGGER.info("Attribute " + attributeName);

相关文章