class MimeMessageWrapper extends MimeMessage {

    public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException {
        try {
            return new MimeMessageWrapper(mimeMessage);
        } catch (MessagingException e) {
            // Copying a mime message fails when the body is empty
            // Copying manually the headers is the best alternative...

            MimeMessageWrapper result = new MimeMessageWrapper();
            ThrowingConsumer<Header> consumer = header -> result.addHeader(header.getName(), header.getValue());
            Collections.list(mimeMessage.getAllHeaders())
                .forEach(Throwing.consumer(consumer).sneakyThrow());
            result.setText(""); // Avoid future body reads to fail
            return result;
        }
    }

    private  MimeMessageWrapper();
    private  MimeMessageWrapper(MimeMessage mimeMessage);

}