// check if we can use optimized operations
if (tryCast && m instanceof MimeMessageWrapper) {
in = ((MimeMessageWrapper) m).getMessageInputStream();
} else {
try {
in = new CombinedInputStream(new InputStream[] { new InternetHeadersInputStream(message.getAllHeaderLines()), message.getRawInputStream() });
} catch (MessagingException e) {
// its possible that MimeMessage.getRawInputStream throws an exception when try to access the method on a self constructed MimeMessage.
// so try to read it in memory
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {