if (property != null) {
MM7CompatMode = JavaUtils.isTrueExplicitly(property);
}
try {
OMMultipartWriter mpw = new OMMultipartWriter(outputStream, format);
OutputStream rootPartOutputStream = mpw.writeRootPart();
OMElement element = msgCtxt.getEnvelope();
if (preserve) {
element.serialize(rootPartOutputStream, format);
} else {
element.serializeAndConsume(rootPartOutputStream, format);
}
rootPartOutputStream.close();
OMMultipartWriter attachmentsWriter;
OutputStream innerOutputStream;
if (!MM7CompatMode) {
attachmentsWriter = mpw;
innerOutputStream = null;
} else {
String innerBoundary;
String partCID;
Object innerBoundaryProperty = msgCtxt
.getProperty(Constants.Configuration.MM7_INNER_BOUNDARY);
if (innerBoundaryProperty != null) {
innerBoundary = (String) innerBoundaryProperty;
} else {
innerBoundary = "innerBoundary"
+ UIDGenerator.generateMimeBoundary();
}
Object partCIDProperty = msgCtxt
.getProperty(Constants.Configuration.MM7_PART_CID);
if (partCIDProperty != null) {
partCID = (String) partCIDProperty;
} else {
partCID = "innerCID"
+ UIDGenerator.generateContentId();
}
OMOutputFormat innerFormat = new OMOutputFormat(format);
innerFormat.setMimeBoundary(innerBoundary);
innerOutputStream = mpw.writePart("multipart/related; boundary=\"" + innerBoundary + "\"", partCID);
attachmentsWriter = new OMMultipartWriter(innerOutputStream, innerFormat);
}
Attachments attachments = msgCtxt.getAttachmentMap();
for (String contentID : attachments.getAllContentIDs()) {
attachmentsWriter.writePart(attachments.getDataHandler(contentID), contentID);
}
if (MM7CompatMode) {
attachmentsWriter.complete();
innerOutputStream.close();
}
mpw.complete();
} catch (IOException ex) {