try {
// if this is a proper message, it implements the MessageAware interface. We need this to
// get the associated session.
if (datasource instanceof MessageAware) {
MessageContext context = ((MessageAware)datasource).getMessageContext();
// construct a mime message instance from the stream, associating it with the
// data source session.
return new MimeMessage(context.getSession(), datasource.getInputStream());
}
} catch (MessagingException e) {
// we need to transform any exceptions into an IOException.
throw new IOException("Exception writing MimeMultipart: " + e.toString());
}