/** * Output the body part as an RFC 822 format stream. * * @exception IOException if an error occurs writing to the * stream or if an error is generated * by the javax.activation layer. * @exception MessagingException for other failures * @see javax.activation.DataHandler#writeTo */ public void writeTo(OutputStream os) throws IOException, MessagingException { // see if we already have a LOS LineOutputStream los = null; if (os instanceof LineOutputStream) { los = (LineOutputStream) os; } else { los = new LineOutputStream(os); } // First, write out the header @SuppressWarnings("unchecked") Enumeration<String> hdrLines = getAllHeaderLines(); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); // Finally, the content, already encoded. getDataHandler().writeTo(os); os.flush(); }
LineOutputStream los = new LineOutputStream(os); los.write(pb); los.writeln(); if (allowEmpty) { los.writeln(boundary); // put out boundary los.writeln(); // put out empty line } else { throw new MessagingException("Empty multipart: " + contentType); los.writeln(boundary); // put out boundary ((MimeBodyPart)parts.elementAt(i)).writeTo(os); los.writeln(); // put out empty line los.writeln(boundary + "--");
LineOutputStream los = new LineOutputStream(bos); = super.getAllHeaderLines(); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln(); } catch (IOException ioex) { los.close(); } catch (IOException cex) { }
/** * Output the body part as an RFC 822 format stream. * * @exception IOException if an error occurs writing to the * stream or if an error is generated * by the javax.activation layer. * @exception MessagingException for other failures * @see javax.activation.DataHandler#writeTo */ @Override public void writeTo(OutputStream os) throws IOException, MessagingException { // see if we already have a LOS LineOutputStream los = null; if (os instanceof LineOutputStream) { los = (LineOutputStream) os; } else { los = new LineOutputStream(os); } // First, write out the header Enumeration<String> hdrLines = getAllHeaderLines(); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); // Finally, the content, already encoded. getDataHandler().writeTo(os); os.flush(); }
LineOutputStream los = new LineOutputStream(os); los.write(pb); los.writeln(); if (allowEmpty) { los.writeln(boundary); // put out boundary los.writeln(); // put out empty line } else { throw new MessagingException("Empty multipart: " + contentType); los.writeln(boundary); // put out boundary ((MimeBodyPart)parts.elementAt(i)).writeTo(os); los.writeln(); // put out empty line los.writeln(boundary + "--");
LineOutputStream los = new LineOutputStream(bos); = super.getAllHeaderLines(); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln(); } catch (IOException ioex) { los.close(); } catch (IOException cex) { }
public static MdnBuilder newInstance(MimeMessage mimeMessage) throws MessagingException, IOException { MdnBuilder mdnBuilder = new MdnBuilder(); mdnBuilder.addHeader(MdnHeader.REPORTING_UA, ISSUER); String recipient = String.format("rfc822; %s", mimeMessage.getHeader(As2Header.AS2_TO)[0]); mdnBuilder.addHeader(MdnHeader.ORIGINAL_RECIPIENT, recipient); mdnBuilder.addHeader(MdnHeader.FINAL_RECIPIENT, recipient); mdnBuilder.textLineOutputStream.writeln("= Received headers"); mdnBuilder.textLineOutputStream.writeln(); for (String header : Collections.list((Enumeration<String>) mimeMessage.getAllHeaderLines())) mdnBuilder.textLineOutputStream.writeln(header); mdnBuilder.textLineOutputStream.writeln(); return mdnBuilder; }
LineOutputStream los = new LineOutputStream(os, allowutf8); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln();
/** * Iterates through all the parts and outputs each MIME part * separated by a boundary. */ public synchronized void writeTo(OutputStream os) throws IOException, MessagingException { parse(); String boundary = "--" + (new ContentType(contentType)).getParameter("boundary"); LineOutputStream los = new LineOutputStream(os); // if there's a preamble, write it out if (preamble != null) { byte[] pb = ASCIIUtility.getBytes(preamble); los.write(pb); // make sure it ends with a newline if (pb.length > 0 && !(pb[pb.length-1] == '\r' || pb[pb.length-1] == '\n')) { los.writeln(); } // XXX - could force a blank line before start boundary } for (int i = 0; i < parts.size(); i++) { los.writeln(boundary); // put out boundary ((MimeBodyPart)parts.elementAt(i)).writeTo(os); los.writeln(); // put out empty line } // put out last boundary los.writeln(boundary + "--"); }
/** * Extracts headers of body MIME part. Creates headers as done by Bouncycastle. * * @return Headers */ public byte[] getBodyHeader() throws IOException, OxalisAs2Exception { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LineOutputStream los = new LineOutputStream(outputStream); Enumeration hdrLines = ((MimeBodyPart) mimeMultipart.getBodyPart(0)).getNonMatchingHeaderLines(new String[]{}); while (hdrLines.hasMoreElements()) los.writeln((String) hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); los.close(); return outputStream.toByteArray(); } catch (MessagingException e) { throw new OxalisAs2Exception("Unable to fetch body headers.", e); } }
public static MdnBuilder newInstance(MimeMessage mimeMessage) throws MessagingException, IOException { MdnBuilder mdnBuilder = new MdnBuilder(); mdnBuilder.addHeader(MdnHeader.REPORTING_UA, ISSUER); String recipient = String.format("rfc822; %s", mimeMessage.getHeader(As2Header.AS2_TO)[0]); mdnBuilder.addHeader(MdnHeader.ORIGINAL_RECIPIENT, recipient); mdnBuilder.addHeader(MdnHeader.FINAL_RECIPIENT, recipient); mdnBuilder.textLineOutputStream.writeln("= Received headers"); mdnBuilder.textLineOutputStream.writeln(); for (String header : Collections.list((Enumeration<String>) mimeMessage.getAllHeaderLines())) mdnBuilder.textLineOutputStream.writeln(header); mdnBuilder.textLineOutputStream.writeln(); return mdnBuilder; }
LineOutputStream los = new LineOutputStream(os); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln();
LineOutputStream los = new LineOutputStream(os); los.write(pb); los.writeln(); if (allowEmpty) { los.writeln(boundary); // put out boundary los.writeln(); // put out empty line } else { throw new MessagingException("Empty multipart: " + contentType); los.writeln(boundary); // put out boundary ((MimeBodyPart)parts.elementAt(i)).writeTo(os); los.writeln(); // put out empty line los.writeln(boundary + "--");
/** * Extracts headers of body MIME part. Creates headers as done by Bouncycastle. * * @return Headers */ public byte[] getBodyHeader() throws IOException, OxalisAs2Exception { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LineOutputStream los = new LineOutputStream(outputStream); Enumeration hdrLines = ((MimeBodyPart) mimeMultipart.getBodyPart(0)).getNonMatchingHeaderLines(new String[]{}); while (hdrLines.hasMoreElements()) los.writeln((String) hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); los.close(); return outputStream.toByteArray(); } catch (MessagingException e) { throw new OxalisAs2Exception("Unable to fetch body headers.", e); } }
los = (LineOutputStream) os; } else { los = new LineOutputStream(os); = part.getNonMatchingHeaderLines(ignoreList); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln();
LineOutputStream los = new LineOutputStream(os); los.write(pb); los.writeln(); if (allowEmpty) { los.writeln(boundary); // put out boundary los.writeln(); // put out empty line } else { throw new MessagingException("Empty multipart: " + contentType); los.writeln(boundary); // put out boundary ((MimeBodyPart)parts.elementAt(i)).writeTo(os); los.writeln(); // put out empty line los.writeln(boundary + "--");
public MimeBodyPart build() throws MessagingException, IOException { // Initiate multipart MimeMultipart mimeMultipart = new MimeMultipart(); mimeMultipart.setSubType("report; Report-Type=disposition-notification"); // Insert text part MimeBodyPart textPart = new MimeBodyPart(); textLineOutputStream.close(); textPart.setContent(textOutputStream.toString("UTF-8"), "text/plain"); // textPart.setHeader("Content-Type", "text/plain"); mimeMultipart.addBodyPart(textPart); // Extract headers ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LineOutputStream lineOutputStream = new LineOutputStream(outputStream); for (String header : Collections.list((Enumeration<String>) headers.getAllHeaderLines())) lineOutputStream.writeln(header); lineOutputStream.close(); // Insert header part MimeBodyPart headerPart = new MimeBodyPart(); headerPart.setContent(outputStream.toString(), "message/disposition-notification"); mimeMultipart.addBodyPart(headerPart); MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeBodyPart.setContent(mimeMultipart, mimeMultipart.getContentType()); return mimeBodyPart; } }
los = (LineOutputStream) os; } else { los = new LineOutputStream(os, allowutf8); = part.getNonMatchingHeaderLines(ignoreList); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement()); los.writeln();