Java Code Examples for javax.mail.Header#getName()

The following examples show how to use javax.mail.Header#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMetadataUtils.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parses metadata stored in a Debian Control File-like format.
 *
 * @see <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file">Description File</a>
 */
public static Map<String, String> parseDescriptionFile(final InputStream in) {
  checkNotNull(in);
  try {
    LinkedHashMap<String, String> results = new LinkedHashMap<>();
    InternetHeaders headers = new InternetHeaders(in);
    Enumeration headerEnumeration = headers.getAllHeaders();
    while (headerEnumeration.hasMoreElements()) {
      Header header = (Header) headerEnumeration.nextElement();
      String name = header.getName();
      String value = header.getValue()
          .replace("\r\n", "\n")
          .replace("\r", "\n"); // TODO: "should" be ASCII only, otherwise need to know encoding?
      results.put(name, value); // TODO: Supposedly no duplicates, is this true?
    }
    return results;
  } catch (MessagingException e) {
    throw new RException(null, e);
  }
}
 
Example 2
Source File: SMTPHandler.java    From holdmail with Apache License 2.0 6 votes vote down vote up
protected MessageHeaders getHeaders(MimeMessage message) throws MessagingException {

        Map<String, String> headerMap = new HashMap<>();

        // oh wow 2015 and it's untyped and uses Enumeration
        Enumeration allHeaders = message.getAllHeaders();
        while (allHeaders.hasMoreElements()) {
            Header header = (Header) allHeaders.nextElement();
            String headerName = header.getName();
            String headerVal = header.getValue();

            headerMap.put(headerName, headerVal);

        }

        return new MessageHeaders(headerMap);
    }
 
Example 3
Source File: HTTPUtil.java    From OpenAs2App with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static String printHeaders(Enumeration<Header> hdrs, String nameValueSeparator, String valuePairSeparator) {
    String headers = "";
    while (hdrs.hasMoreElements()) {
        Header h = hdrs.nextElement();
        headers = headers + valuePairSeparator + h.getName() + nameValueSeparator + h.getValue();
    }

    return (headers);

}
 
Example 4
Source File: AS2Util.java    From OpenAs2App with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static String printHeaders(Enumeration<Header> hdrs, String nameValueSeparator, String valuePairSeparator) {
    String headers = "";
    while (hdrs.hasMoreElements()) {
        Header h = hdrs.nextElement();
        headers = headers + valuePairSeparator + h.getName() + nameValueSeparator + h.getValue();
    }

    return (headers);

}
 
Example 5
Source File: Services.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
private Response bodyPartRequest(final MimeBodyPart body, final Map<String, String> references) throws Exception {
  @SuppressWarnings("unchecked")
  final Enumeration<Header> en = body.getAllHeaders();

  Header header = en.nextElement();
  final String request =
      header.getName() + (StringUtils.isNotBlank(header.getValue()) ? ":" + header.getValue() : "");

  final Matcher matcher = REQUEST_PATTERN.matcher(request);
  final Matcher matcherRef = BATCH_REQUEST_REF_PATTERN.matcher(request);

  final MultivaluedMap<String, String> headers = new MultivaluedHashMap<String, String>();

  while (en.hasMoreElements()) {
    header = en.nextElement();
    headers.putSingle(header.getName(), header.getValue());
  }

  final Response res;
  final String url;
  final String method;

  if (matcher.find()) {
    url = matcher.group(2);
    method = matcher.group(1);
  } else if (matcherRef.find()) {
    url = references.get(matcherRef.group(2)) + matcherRef.group(3);
    method = matcherRef.group(1);
  } else {
    url = null;
    method = null;
  }

  if (url == null) {
    res = null;
  } else {
    final WebClient client = WebClient.create(url, "odatajclient", "odatajclient", null);
    client.headers(headers);

    if ("DELETE".equals(method)) {
      res = client.delete();
    } else {
      final InputStream is = body.getDataHandler().getInputStream();
      String content = IOUtils.toString(is);
      IOUtils.closeQuietly(is);

      final Matcher refs = REF_PATTERN.matcher(content);

      while (refs.find()) {
        content = content.replace(refs.group(1), references.get(refs.group(1)));
      }

      if ("PATCH".equals(method) || "MERGE".equals(method)) {
        client.header("X-HTTP-METHOD", method);
        res = client.invoke("POST", IOUtils.toInputStream(content));
      } else {
        res = client.invoke(method, IOUtils.toInputStream(content));
      }
    }

    // When updating to CXF 3.0.1, uncomment the following line, see CXF-5865
    // client.close();
  }

  return res;
}