MimeMessageUtils { public String getMessageHeaders() throws MessagingException { Enumeration<String> heads = message.getAllHeaderLines(); StringBuilder headBuffer = new StringBuilder(1024); while (heads.hasMoreElements()) { headBuffer.append(heads.nextElement()).append("\r\n"); } return headBuffer.toString(); } MimeMessageUtils(MimeMessage message); Optional<String> subjectWithPrefix(String subjectPrefix); Optional<String> subjectWithPrefix(String subjectPrefix, Mail originalMail, String subject); String getMessageHeaders(); List<Header> toHeaderList();  }
@Test public void getMessageHeadersShouldReturnEmptyStringWhenNoHeaders() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); String messageHeaders = new MimeMessageUtils(message).getMessageHeaders(); assertThat(messageHeaders).isEmpty(); }
@Test public void getMessageHeadersShouldHeadersWhenSome() throws Exception { MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties())); message.addHeader("first", "value"); message.addHeader("second", "value2"); String messageHeaders = new MimeMessageUtils(message).getMessageHeaders(); String expectedHeaders = "first: value\r\nsecond: value2\r\n"; assertThat(messageHeaders).isEqualTo(expectedHeaders); }