@Test void wrapShouldNotThrowWhenNoBody() throws Exception { MimeMessage originalMessage = new MimeMessage(Session.getDefaultInstance(new Properties())); originalMessage.addHeader("header1", "value1"); originalMessage.addHeader("header2", "value2"); originalMessage.addHeader("header2", "value3"); MimeMessageWrapper mimeMessageWrapper = MimeMessageWrapper.wrap(originalMessage); assertThat(Collections.list(mimeMessageWrapper.getAllHeaders())) .extracting(javaxHeader -> new MimeMessageBuilder.Header(javaxHeader.getName(), javaxHeader.getValue())) .contains(new MimeMessageBuilder.Header("header1", "value1"), new MimeMessageBuilder.Header("header2", "value2"), new MimeMessageBuilder.Header("header2", "value3")); }
public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException { try { return new MimeMessageWrapper(mimeMessage); } catch (MessagingException e) { 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(""); return result; } }
MimeMessageWrapper extends MimeMessage { public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException { try { return new MimeMessageWrapper(mimeMessage); } catch (MessagingException e) { 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(""); return result; } } }
MimeMessageWrapper extends MimeMessage { public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException { try { return new MimeMessageWrapper(mimeMessage); } catch (MessagingException e) { 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(""); return result; } } private  MimeMessageWrapper(); private  MimeMessageWrapper(MimeMessage mimeMessage); }
MimeMessageWrapper extends MimeMessage { public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException { try { return new MimeMessageWrapper(mimeMessage); } catch (MessagingException e) { 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(""); return result; } } private  MimeMessageWrapper(); private  MimeMessageWrapper(MimeMessage mimeMessage); static MimeMessageWrapper wrap(MimeMessage mimeMessage); }
MimeMessageWrapper extends MimeMessage { public static MimeMessageWrapper wrap(MimeMessage mimeMessage) throws MessagingException { try { return new MimeMessageWrapper(mimeMessage); } catch (MessagingException e) { 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(""); return result; } } private  MimeMessageWrapper(); private  MimeMessageWrapper(MimeMessage mimeMessage); static MimeMessageWrapper wrap(MimeMessage mimeMessage);  }