MimeMessageWrapper extends MimeMessage implements Disposable { public synchronized InputStream getMessageInputStream() throws MessagingException { if (!messageParsed && !isModified() && source != null) { try { return source.getInputStream(); } catch (IOException e) { throw new MessagingException("Unable to get inputstream", e); } } else { try { if (!bodyModified && source != null) { InputStream in = source.getInputStream(); new MailHeaders(in); return new SequenceInputStream(new InternetHeadersInputStream(getAllHeaderLines()), in); } else { ByteArrayOutputStream out = new ByteArrayOutputStream(); writeTo(out); return new ByteArrayInputStream(out.toByteArray()); } } catch (IOException e) { throw new MessagingException("Unable to get inputstream", e); } } } private  MimeMessageWrapper(Session session);  MimeMessageWrapper(Session session, MimeMessageSource source);  MimeMessageWrapper(MimeMessageSource source);  MimeMessageWrapper(MimeMessage original); synchronized String getSourceId(); synchronized void loadMessage(); synchronized boolean isModified(); synchronized boolean isBodyModified(); synchronized boolean isHeaderModified(); @Override void writeTo(OutputStream os); @Override void writeTo(OutputStream os, String[] ignoreList); void writeTo(OutputStream headerOs, OutputStream bodyOs); void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList); synchronized void writeTo(OutputStream headerOs, OutputStream bodyOs, String[] ignoreList, boolean preLoad); @Override synchronized int getSize(); @Override int getLineCount(); long getMessageSize(); @Override String[] getHeader(String name); @Override String getHeader(String name, String delimiter); @Override Enumeration<Header> getAllHeaders(); @Override Enumeration<Header> getMatchingHeaders(String[] names); @Override Enumeration<Header> getNonMatchingHeaders(String[] names); @Override Enumeration<String> getAllHeaderLines(); @Override Enumeration<String> getMatchingHeaderLines(String[] names); @Override Enumeration<String> getNonMatchingHeaderLines(String[] names); @Override void setHeader(String name, String value); @Override void addHeader(String name, String value); @Override void removeHeader(String name); @Override void addHeaderLine(String line); @Override synchronized void setDataHandler(DataHandler arg0); @Override void dispose(); @Override synchronized InputStream getRawInputStream(); synchronized InputStream getMessageInputStream(); static final String USE_MEMORY_COPY; }
@Test public void testMessageStreamWithUpatedContent() throws MessagingException, IOException { String newContent = "This is the new message content!"; mw.setText(newContent); assertThat(mw.getContent()).isEqualTo(newContent); mw.saveChanges(); BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream())); boolean contentUpdated = reader.lines() .anyMatch(line -> line.equals(newContent)); reader.close(); assertThat(contentUpdated).isTrue(); }