Java Code Examples for javax.mail.internet.InternetHeaders#getAllHeaders()
The following examples show how to use
javax.mail.internet.InternetHeaders#getAllHeaders() .
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 |
/** * 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: PyPiInfoUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Parses the PKG-INFO content as RFC 822 headers (per PEPs 241 and 314). (Yes, Python PKG-INFO information is * essentially stored as a file of email headers.) */ @VisibleForTesting static Map<String, List<String>> parsePackageInfo(final InputStream in) throws Exception { checkNotNull(in); LinkedHashMap<String, List<String>> results = new LinkedHashMap<>(); // All package info or metadata file types have their metadata stored in the same manner as email headers InternetHeaders headers = new InternetHeaders(in); Enumeration<Header> headerEnumeration = headers.getAllHeaders(); while (headerEnumeration.hasMoreElements()) { Header header = headerEnumeration.nextElement(); String underscoreName = header.getName().toLowerCase().replace('-', '_'); String name = NAME_SUBSTITUTIONS.getOrDefault(underscoreName, underscoreName); String value = convertHeaderValue(header.getValue()); if (!results.containsKey(name)) { results.put(name, new ArrayList<>()); } results.get(name).add(value); } // Wheel metadata can also be stored in the payload section (description only, so far as I'm aware) if (!results.containsKey(PyPiAttributes.P_DESCRIPTION)) { String text = Strings.nullToEmpty(CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8))).trim(); if (!text.isEmpty()) { List<String> description = new ArrayList<>(); description.add(text.replace("\r\n", "\n").replaceAll("[ ]*\\n[ ]*", "\n") + "\n"); results.put(PyPiAttributes.P_DESCRIPTION, description); } } return results; }
Example 3
Source File: BaseMessageMDN.java From OpenAs2App with BSD 2-Clause "Simplified" License | 5 votes |
public void copyHeaders(InternetHeaders srcHeaders) { Enumeration<Header> headerEn = srcHeaders.getAllHeaders(); while (headerEn.hasMoreElements()) { Header header = headerEn.nextElement(); setHeader(header.getName(), header.getValue()); } }