MarinerPageContext context)
throws PackagingException {
MarinerRequestContext requestContext = context.getRequestContext();
ApplicationContext ac =
ContextInternals.getApplicationContext(requestContext);
PackageResources pr = ac.getPackageResources();
// Final stage is setting up the message's content, content type,
// ensuring that the message has only those headers required and
// writing the message to the response output stream
OutputStream outputStream = null;
try {
// Construct the outer-most message
Message message = new MimeMessage(Session.getInstance(
System.getProperties(), null));
String messageContentType;
message.setContent(pkg);
message.saveChanges();
// Remove all erroneous headers from the parts
for (int i = 0;
i < pkg.getCount();
i++) {
BodyPart part = pkg.getBodyPart(i);
// @todo ideally identified from the device repository
part.removeHeader("Content-Transfer-Encoding");
}
// Store the content type for later use
messageContentType = message.getContentType();
// Remove the erroneous headers from the message
// @todo ideally identified from the device repository
message.removeHeader("Message-ID");
message.removeHeader("Mime-Version");
message.removeHeader("Content-Type");
// Before anything is written to the output stream make sure that
// the response content type is set.
//
// The message content type will always be of the form:
// 'multipart/mixed;
// <whitespace>boundary="<text>"'
//
// The first, fixed, part must be replaced by the required
// contentType but the boundary part must be preserved.
messageContentType = pr.getContentType() +
messageContentType.substring(messageContentType.indexOf(';'));
context.getEnvironmentContext().setContentType(messageContentType);
// Now write the message to the output stream
try {