MimeMessageUtil { public static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs) throws IOException, MessagingException { writeTo(message, headerOs, bodyOs, null); }  static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs); static void writeTo(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList); static void writeToInternal(MimeMessage message, OutputStream headerOs, OutputStream bodyOs, String[] ignoreList); static void writeMessageBodyTo(MimeMessage message, OutputStream bodyOs); static void writeHeadersTo(Enumeration<String> headers, OutputStream headerOs); static InputStream getHeadersInputStream(MimeMessage message, String[] ignoreList); static long getMessageSize(MimeMessage message); static long calculateMessageSize(MimeMessage message);  }
@Test public void testWriteMimeMessageMultipartWithMessageID() throws MessagingException, IOException { String message = "Received: from localhost.localdomain ([127.0.0.1])\r\n" + " by athlon14 (JAMES SMTP Server 2.3-dev) with SMTP ID 694\r\n" + " for <test_int1@athlon14.bf.loc>;\r\n" + " Sat, 18 Feb 2006 19:30:53 +0100 (CET)\r\n" + "Subject: ext2int\r\n" + "X-James-Postage: This is a test mail sent by James Postage\r\n" + "Mime-Version: 1.0\r\n" + "Content-Type: multipart/alternative; boundary=\"XyoYyxCQIfmZ5Sxofid6XQVZt5Z09XtTnqBF4Z45XSA=\"\r\n" + "Date: Sat, 18 Feb 2006 19:30:53 +0100 (CET)\r\n" + "From: test_ext2@another.bf.loc\r\n" + "\r\n" + "\r\n" + "--XyoYyxCQIfmZ5Sxofid6XQVZt5Z09XtTnqBF4Z45XSA=\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n" + "--XyoYyxCQIfmZ5Sxofid6XQVZt5Z09XtTnqBF4Z45XSA=\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n" + "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\n" + "--XyoYyxCQIfmZ5Sxofid6XQVZt5Z09XtTnqBF4Z45XSA=--\r\n"; MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()), new ByteArrayInputStream(message.getBytes())); mimeMessage.getSize(); ByteArrayOutputStream headerOut = new ByteArrayOutputStream(); ByteArrayOutputStream bodyOut = new ByteArrayOutputStream(); MimeMessageUtil.writeTo(mimeMessage, headerOut, bodyOut); }