/** * 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, allowutf8); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement());
/** * 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); while (hdrLines.hasMoreElements()) los.writeln(hdrLines.nextElement());
los = (LineOutputStream) os; } else { los = new LineOutputStream(os);
los = (LineOutputStream) os; } else { los = new LineOutputStream(os, allowutf8);
LineOutputStream los = new LineOutputStream(os);
LineOutputStream los = new LineOutputStream(os);
LineOutputStream los = new LineOutputStream(bos);
LineOutputStream los = new LineOutputStream(bos);
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; } }
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; } }
/** * 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); } }
/** * 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); } }
/** * 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(); }
/** * 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(); }
/** * 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(); }
/** * Output the body part as an RFC 822 format stream. * * @exception MessagingException * @exception IOException if an error occurs writing to the * stream or if an error is generated * by the javax.activation layer. * @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 Enumeration hdrLines = getAllHeaderLines(); while (hdrLines.hasMoreElements()) los.writeln((String)hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); // Finally, the content, already encoded. getDataHandler().writeTo(os); os.flush(); }
static void writeTo(MimePart part, OutputStream os, String[] ignoreList) 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 hdrLines = part.getNonMatchingHeaderLines(ignoreList); while (hdrLines.hasMoreElements()) los.writeln((String)hdrLines.nextElement()); // The CRLF separator between header and content los.writeln(); // Finally, the content. Encode if required. // XXX: May need to account for ESMTP ? os = MimeUtility.encode(os, part.getEncoding()); part.getDataHandler().writeTo(os); os.flush(); // Needed to complete encoding } }
/** * 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 + "--"); }