Java Code Examples for javax.mail.internet.InternetHeaders#getAllHeaderLines()
The following examples show how to use
javax.mail.internet.InternetHeaders#getAllHeaderLines() .
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: ExchangeSession.java From davmail with GNU General Public License v2.0 | 6 votes |
public Enumeration<?> getMatchingHeaderLinesFromHeaders(String[] headerNames) throws MessagingException { Enumeration<?> result = null; if (mimeMessage == null) { // message not loaded, try to get headers only InputStream headers = getMimeHeaders(); if (headers != null) { InternetHeaders internetHeaders = new InternetHeaders(headers); if (internetHeaders.getHeader("Subject") == null) { // invalid header content return null; } if (headerNames == null) { result = internetHeaders.getAllHeaderLines(); } else { result = internetHeaders.getMatchingHeaderLines(headerNames); } } } return result; }
Example 2
Source File: RPackagesBuilder.java From nexus-repository-r with Eclipse Public License 1.0 | 6 votes |
private void writePackageInfo(final OutputStreamWriter writer, final Map<String, String> packageInfo) throws IOException { InternetHeaders headers = new InternetHeaders(); headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE)); headers.addHeader(P_VERSION, packageInfo.get(P_VERSION)); headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS)); headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS)); headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS)); headers.addHeader(P_LINKINGTO, packageInfo.get(P_LINKINGTO)); headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE)); headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION)); Enumeration<String> headerLines = headers.getAllHeaderLines(); while (headerLines.hasMoreElements()) { String line = headerLines.nextElement(); writer.write(line, 0, line.length()); writer.write('\n'); } writer.write('\n'); }
Example 3
Source File: RPackagesUtils.java From nexus-repository-r with Eclipse Public License 1.0 | 5 votes |
public static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException { CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory(); ByteArrayOutputStream os = new ByteArrayOutputStream(); try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) { try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) { for (Map<String, String> entry : entries) { InternetHeaders headers = new InternetHeaders(); headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE)); headers.addHeader(P_VERSION, entry.get(P_VERSION)); headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS)); headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS)); headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS)); headers.addHeader(P_LINKINGTO, entry.get(P_LINKINGTO)); headers.addHeader(P_LICENSE, entry.get(P_LICENSE)); headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION)); Enumeration<String> headerLines = headers.getAllHeaderLines(); while (headerLines.hasMoreElements()) { String line = headerLines.nextElement(); writer.write(line, 0, line.length()); writer.write('\n'); } writer.write('\n'); } } } catch ( CompressorException e ) { throw new RException(null, e); } return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip")); }
Example 4
Source File: AS2ReceiverHandler.java From OpenAs2App with BSD 2-Clause "Simplified" License | 4 votes |
public void createMDNData(Session session, MessageMDN mdn, String micAlg, String signatureProtocol) throws Exception { // Create the report and sub-body parts MimeMultipart reportParts = new MimeMultipart(); // Create the text part MimeBodyPart textPart = new MimeBodyPart(); String text = mdn.getText() + "\r\n"; textPart.setContent(text, "text/plain"); textPart.setHeader("Content-Type", "text/plain"); reportParts.addBodyPart(textPart); // Create the report part MimeBodyPart reportPart = new MimeBodyPart(); InternetHeaders reportValues = new InternetHeaders(); reportValues.setHeader("Reporting-UA", mdn.getAttribute(AS2MessageMDN.MDNA_REPORTING_UA)); reportValues.setHeader("Original-Recipient", mdn.getAttribute(AS2MessageMDN.MDNA_ORIG_RECIPIENT)); reportValues.setHeader("Final-Recipient", mdn.getAttribute(AS2MessageMDN.MDNA_FINAL_RECIPIENT)); reportValues.setHeader("Original-Message-ID", mdn.getAttribute(AS2MessageMDN.MDNA_ORIG_MESSAGEID)); reportValues.setHeader("Disposition", mdn.getAttribute(AS2MessageMDN.MDNA_DISPOSITION)); reportValues.setHeader("Received-Content-MIC", mdn.getAttribute(AS2MessageMDN.MDNA_MIC)); Enumeration<String> reportEn = reportValues.getAllHeaderLines(); StringBuffer reportData = new StringBuffer(); while (reportEn.hasMoreElements()) { reportData.append(reportEn.nextElement()).append("\r\n"); } reportData.append("\r\n"); String reportText = reportData.toString(); reportPart.setContent(reportText, AS2Standards.DISPOSITION_TYPE); reportPart.setHeader("Content-Type", AS2Standards.DISPOSITION_TYPE); reportParts.addBodyPart(reportPart); // Convert report parts to MimeBodyPart MimeBodyPart report = new MimeBodyPart(); reportParts.setSubType(AS2Standards.REPORT_SUBTYPE); report.setContent(reportParts); String contentType = reportParts.getContentType(); if ("true".equalsIgnoreCase(Properties.getProperty("remove_multipart_content_type_header_folding", "false"))) { contentType = contentType.replaceAll("\r\n[ \t]*", " "); } report.setHeader("Content-Type", contentType); // Sign the data if needed if (signatureProtocol != null) { CertificateFactory certFx = session.getCertificateFactory(); try { // The receiver of the original message is the sender of the MDN.... X509Certificate senderCert = certFx.getCertificate(mdn, Partnership.PTYPE_RECEIVER); PrivateKey senderKey = certFx.getPrivateKey(mdn, senderCert); Partnership p = mdn.getPartnership(); String contentTxfrEncoding = p.getAttribute(Partnership.PA_CONTENT_TRANSFER_ENCODING); boolean isRemoveCmsAlgorithmProtectionAttr = "true".equalsIgnoreCase(p.getAttribute(Partnership.PA_REMOVE_PROTECTION_ATTRIB)); if (contentTxfrEncoding == null) { contentTxfrEncoding = Session.DEFAULT_CONTENT_TRANSFER_ENCODING; } // sign the data using CryptoHelper MimeBodyPart signedReport = AS2Util.getCryptoHelper().sign(report, senderCert, senderKey, micAlg, contentTxfrEncoding, false, isRemoveCmsAlgorithmProtectionAttr); mdn.setData(signedReport); } catch (CertificateNotFoundException cnfe) { cnfe.terminate(); mdn.setData(report); } catch (KeyNotFoundException knfe) { knfe.terminate(); mdn.setData(report); } } else { mdn.setData(report); } // Update the MDN headers with content information MimeBodyPart data = mdn.getData(); String headerContentType = data.getContentType(); if ("true".equalsIgnoreCase(Properties.getProperty("remove_http_header_folding", "true"))) { headerContentType = headerContentType.replaceAll("\r\n[ \t]*", " "); } mdn.setHeader("Content-Type", headerContentType); // int size = getSize(data); // mdn.setHeader("Content-Length", Integer.toString(size)); }
Example 5
Source File: InternetHeadersInputStream.java From james-project with Apache License 2.0 | 4 votes |
public InternetHeadersInputStream(InternetHeaders headers) { this(headers.getAllHeaderLines()); }