Search in sources :

Example 1 with LineOutputStream

use of com.sun.mail.util.LineOutputStream in project zm-mailbox by Zimbra.

the class ZMimeMultipart method writeTo.

// JavaMail makes it impossible to set MimeMultipart.allowEmpty if you don't use their parser, and that
// means an empty multipart always throws an exception on MimeMultipart.writeTo regardless of what
// "mail.mime.multipart.allowempty" is set to.  So we have to copy the whole method from the superclass
// just so we can strip that conditional out.
@Override
public synchronized void writeTo(OutputStream os) throws IOException, MessagingException {
    if (ZPARSER) {
        parse();
        String boundary = "--" + getBoundary();
        LineOutputStream los = new LineOutputStream(os);
        // if there's a preamble, write it out
        String preamble = getPreamble();
        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
        }
        if (parts.size() == 0) {
            // write out a single empty body part
            // put out boundary
            los.writeln(boundary);
            // put out empty line
            los.writeln();
        } else {
            for (int i = 0; i < parts.size(); i++) {
                // put out boundary
                los.writeln(boundary);
                ((MimeBodyPart) parts.elementAt(i)).writeTo(os);
                // put out empty line
                los.writeln();
            }
        }
        // put out last boundary
        los.writeln(boundary + "--");
    } else {
        super.writeTo(os);
    }
}
Also used : LineOutputStream(com.sun.mail.util.LineOutputStream) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Aggregations

LineOutputStream (com.sun.mail.util.LineOutputStream)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1