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
}
if (parts.size() == 0) {
// have to read the property every time because parse won't
// read it if the message was *not* constructed from a stream.
// default to false
allowEmpty = PropUtil.getBooleanSystemProperty(
"mail.mime.multipart.allowempty", false);
if (allowEmpty) {
// write out a single empty body part
los.writeln(boundary); // put out boundary
los.writeln(); // put out empty line
} else {
throw new MessagingException("Empty multipart: " + contentType);
}
} else {
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 + "--");
}