javax.mail.Message.getAllHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(178)

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

Message.getAllHeaders介绍

暂无

代码示例

代码示例来源:origin: oblac/jodd

headers(msg.getAllHeaders());

代码示例来源:origin: google/mail-importer

@Override
public Enumeration getAllHeaders() throws RuntimeMessagingException {
 try {
  return delegate.getAllHeaders();
 } catch (MessagingException e) {
  throw new RuntimeMessagingException(e);
 }
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_mail

private String getRequestHeaders(Message message) throws MessagingException {
  StringBuilder sb = new StringBuilder();
  @SuppressWarnings("unchecked") // getAllHeaders() is not yet genericised
  Enumeration<Header> headers = message.getAllHeaders(); // throws ME
  writeHeaders(headers, sb);
  return sb.toString();
}

代码示例来源:origin: com.mgmtp.jfunk/jfunk-core

private static ListMultimap<String, String> createHeaders(final Message message) throws MessagingException {
  ListMultimap<String, String> headers = ArrayListMultimap.create();
  for (@SuppressWarnings("unchecked")
  Enumeration<Header> headersEnum = message.getAllHeaders(); headersEnum.hasMoreElements();) {
    Header header = headersEnum.nextElement();
    headers.put(header.getName(), header.getValue());
  }
  return headers;
}

代码示例来源:origin: spring-projects/spring-ws

@Override
public Iterator<String> getRequestHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = requestMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new IOException(ex.getMessage());
  }
}

代码示例来源:origin: org.springframework.ws/spring-ws-support

@Override
public Iterator<String> getRequestHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = requestMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new IOException(ex.getMessage());
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Iterator<String> getResponseHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = responseMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new MailTransportException(ex);
  }
}

代码示例来源:origin: org.springframework.ws/spring-ws-support

@Override
public Iterator<String> getResponseHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = responseMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new MailTransportException(ex);
  }
}

代码示例来源:origin: spring-projects/spring-ws

@Override
public Iterator<String> getResponseHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = responseMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new MailTransportException(ex);
  }
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Iterator<String> getRequestHeaderNames() throws IOException {
  try {
    List<String> headers = new ArrayList<String>();
    Enumeration<?> enumeration = requestMessage.getAllHeaders();
    while (enumeration.hasMoreElements()) {
      Header header = (Header) enumeration.nextElement();
      headers.add(header.getName());
    }
    return headers.iterator();
  }
  catch (MessagingException ex) {
    throw new IOException(ex.getMessage());
  }
}

代码示例来源:origin: org.apache.camel/camel-mail

public String generateMessageHash(Message message) {
    LOG.trace("generateMessageHash for msg: {}", message);

    String uid = null;

    // create an UID based on message headers on the message, that ought to be unique
    StringBuilder buffer = new StringBuilder();
    try {
      Enumeration<?> it = message.getAllHeaders();
      while (it.hasMoreElements()) {
        Header header = (Header) it.nextElement();
        buffer.append(header.getName()).append("=").append(header.getValue()).append("\n");
      }
      if (buffer.length() > 0) {
        LOG.trace("Generating UID from the following:\n {}", buffer);
        uid = UUID.nameUUIDFromBytes(buffer.toString().getBytes()).toString();
      }
    } catch (MessagingException e) {
      LOG.warn("Cannot read headers from mail message. This exception will be ignored.", e);
    }

    return uid;
  }
}

代码示例来源:origin: OpenNMS/opennms

@SuppressWarnings("unchecked")
private static String createLog(final Message msg) {
  final StringBuilder bldr = new StringBuilder();
  Enumeration<Header> allHeaders;
  try {
    allHeaders = msg.getAllHeaders();
  } catch (MessagingException e) {
    return null;
  }
  while (allHeaders.hasMoreElements()) {
    Header header = allHeaders.nextElement();
    String name = header.getName();
    String value = header.getValue();
    bldr.append(name);
    bldr.append(":");
    bldr.append(value);
    bldr.append("\n");
  }
  return StringUtils.truncate(bldr.toString(), LOG_FIELD_WIDTH);
}

代码示例来源:origin: org.evolvis.bsi/kolab-ws

@SuppressWarnings("unchecked")
public static Enumeration<Header>
IMAPMessage_getAllHeaders(Message message)
throws MessagingException
{
  if (!Profiler.INSTANCE.isActive()) // only needed for better performance
    return message.getAllHeaders();
  return (Enumeration<Header>)profileInvokeMExcep(message,
    "getAllHeaders");
}

代码示例来源:origin: org.apache.james/apache-jsieve-util

/**
 * Method getHeaderNames answers a List of all of the headers in the
 * receiver. No duplicates are allowed.
 *
 * @return <code>List</code>, not null possible empty, possible
 *         unmodifiable
 * @throws SieveMailException
 */
@SuppressWarnings("unchecked")
public List<String> getHeaderNames() throws SieveMailException {
  List<String> results = Collections.EMPTY_LIST;
  if (mail != null) {
    try {
      results = new ArrayList<String>();
      for (final Enumeration en = mail.getAllHeaders(); en
          .hasMoreElements(); ) {
        final Header header = (Header) en.nextElement();
        final String name = header.getName();
        if (!results.contains(name)) {
          results.add(name);
        }
      }
    } catch (MessagingException e) {
      throw new SieveMailException(e);
    }
  }
  return results;
}

代码示例来源:origin: org.apache.axis2.transport/axis2-transport-mail

private Map getTransportHeaders(Message message, PollTableEntry entry) {
  //use a comaprator to ignore the case for headers.
  Comparator comparator = new Comparator(){
    public int compare(Object o1, Object o2) {
      String string1 = (String) o1;
      String string2 = (String) o2;
      return string1.compareToIgnoreCase(string2);
    }
  };
  Map trpHeaders = new TreeMap(comparator);
  try {
    Enumeration e = message.getAllHeaders();
    while (e.hasMoreElements()) {
      Header h = (Header) e.nextElement();
      if (entry.retainHeader(h.getName())) {
        trpHeaders.put(h.getName(), h.getValue());
      }
    }
  } catch (MessagingException ignore) {}
  return trpHeaders;
}

代码示例来源:origin: org.apache.axis2/axis2-transport-mail

private Map getTransportHeaders(Message message, PollTableEntry entry) {
  //use a comaprator to ignore the case for headers.
  Comparator comparator = new Comparator(){
    public int compare(Object o1, Object o2) {
      String string1 = (String) o1;
      String string2 = (String) o2;
      return string1.compareToIgnoreCase(string2);
    }
  };
  Map trpHeaders = new TreeMap(comparator);
  try {
    Enumeration e = message.getAllHeaders();
    while (e.hasMoreElements()) {
      Header h = (Header) e.nextElement();
      if (entry.retainHeader(h.getName())) {
        trpHeaders.put(h.getName(), h.getValue());
      }
    }
  } catch (MessagingException ignore) {}
  return trpHeaders;
}

代码示例来源:origin: apache/axis2-java

private Map getTransportHeaders(Message message, PollTableEntry entry) {
  //use a comaprator to ignore the case for headers.
  Comparator comparator = new Comparator(){
    public int compare(Object o1, Object o2) {
      String string1 = (String) o1;
      String string2 = (String) o2;
      return string1.compareToIgnoreCase(string2);
    }
  };
  Map trpHeaders = new TreeMap(comparator);
  try {
    Enumeration e = message.getAllHeaders();
    while (e.hasMoreElements()) {
      Header h = (Header) e.nextElement();
      if (entry.retainHeader(h.getName())) {
        trpHeaders.put(h.getName(), h.getValue());
      }
    }
  } catch (MessagingException ignore) {}
  return trpHeaders;
}

代码示例来源:origin: org.apache.james/apache-jsieve-util

/**
 * Parses the value from the given message into addresses.
 *
 * @param headerName header name, to be matched case insensitively
 * @param message    <code>Message</code>, not null
 * @return <code>Address</code> array, not null possibly empty
 * @throws SieveMailException
 */
public Address[] parseAddresses(final String headerName,
                final Message message) throws SieveMailException {
  try {
    final SieveAddressBuilder builder = new SieveAddressBuilder();
    for (Enumeration en = message.getAllHeaders(); en.hasMoreElements(); ) {
      final Header header = (Header) en.nextElement();
      final String name = header.getName();
      if (name.trim().equalsIgnoreCase(headerName)) {
        builder.addAddresses(header.getValue());
      }
    }
    final Address[] results = builder.getAddresses();
    return results;
  } catch (MessagingException ex) {
    throw new SieveMailException(ex);
  } catch (ParseException ex) {
    throw new SieveMailException(ex);
  }
}

代码示例来源:origin: org.mnode.mstor/mstor

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public final void appendMessages(Message[] messages) throws MessagingException {
  try {
    Date received = new Date();
    for (Message message : messages) {
      T md = getMessage(message.getMessageNumber());
      md.setReceived(received);
      md.setFlags(message.getFlags());
      md.setHeaders(message.getAllHeaders());
      allocateUid(md);
    }
    delegate.appendMessages(messages);
    save();
  }
  catch (DelegateException de) {
    throw new MessagingException("Error saving changes", de);
  }
}

代码示例来源:origin: com.gitlab.jhonsapp/simple-email

public EmailMessage convertMessage(Message m) throws MailException {
  emailMessage = new EmailMessage();
  try {
    emailMessage.setFromAddresses(MailUtility.getInternetAddressses(m.getFrom()));
    emailMessage.getToAddresses().addAll(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.TO)));
    emailMessage.setCcAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.CC)));
    emailMessage.setBccAddresses(MailUtility.getInternetAddressses(m.getRecipients(RecipientType.BCC)));
    emailMessage.setSubject(m.getSubject());
    emailMessage.setMessageId(m.getHeader("Message-ID")[0]);
    emailMessage.getHeaders().addAll(MailUtility.getHeaders(m.getAllHeaders()));
    if (m.getContentType().toLowerCase().contains("multipart/")) {
      addMultiPart((MimeMultipart) m.getContent());
    }
    else if (m.isMimeType("text/plain")) {
      emailMessage.setTextBody((String) m.getContent());
    }
  }
  catch (IOException e) {
    throw new MailException(e);
  }
  catch (MessagingException e) {
    throw new MailException(e);
  }
  return emailMessage;
}

相关文章