Is there a more efficient way of converting from MapiMessage to java.mail.MimeMessage without having to allocate so many byte arrays and have so many steps? Forgive me if this is a silly question, since I don't know the Aspose libs very well.
public MimeMessage convertEmailBlobAspose(PersonalStorage pst, MessageInfo email) throws ArchivaException {
try {
MapiMessage message = pst.extractMessage(email);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
message.save(bos);
} finally {
StreamUtil.closeWithLogging(bos);
}
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
MailMessage mailMessage = null;
try {
mailMessage = MailMessage.load(bis,MessageFormat.getMsg());
} finally {
StreamUtil.closeWithLogging(bos);
}
bis = null;
bos = new ByteArrayOutputStream();
try {
mailMessage.save(bos,MessageFormat.getEml());
} finally {
StreamUtil.closeWithLogging(bos);
}
try {
bis = new ByteArrayInputStream(bos.toByteArray());
Properties props = System.getProperties();
Session session = Session.getInstance(props, null);
return new MimeMessage(session,bis);
} finally {
StreamUtil.closeWithLogging(bis);
}
} catch (Exception e) {
throw new ArchivaException("failed to convert message:"+e.getMessage(),e,logger);
}
}