MimeMessageHelper { public static MimeMessage parse(InputStream inputStream) throws MessagingException { return new MimeMessage(SESSION, inputStream); }  static MimeMessage parse(InputStream inputStream); static MimeMessage parse(InputStream inputStream, InternetHeaders headers); static MimeMessage parse(InputStream inputStream, Stream<String> headers); static MimeBodyPart createMimeBodyPart(InputStream inputStream, String mimeType); static Digest calculateMic(MimeBodyPart bodyPart, SMimeDigestMethod digestMethod); static byte[] toBytes(MimeMessage mimeMessage);  }
@Test public void parseLegalMimeMessageWithHeaders() throws Exception { InputStream resourceAsStream = getClass().getResourceAsStream(OPENAS2_MDN_TXT); assertNotNull(resourceAsStream, OPENAS2_MDN_TXT + " not found in classpath"); MimeMessage mimeMessage = MimeMessageHelper.parse(resourceAsStream); Object content = mimeMessage.getContent(); assertNotNull(content); String contentType = mimeMessage.getContentType(); assertEquals(new MimeType(contentType).getBaseType(), new MimeType("multipart/signed").getBaseType()); MimeMultipart mimeMultipartSigned = (MimeMultipart) content; assertEquals(mimeMultipartSigned.getCount(), 2); BodyPart firstBody = mimeMultipartSigned.getBodyPart(0); assertEquals(new MimeType(firstBody.getContentType()).getBaseType(), new MimeType("multipart/report").getBaseType()); BodyPart secondBody = mimeMultipartSigned.getBodyPart(1); assertEquals(new MimeType(secondBody.getContentType()).getBaseType(), new MimeType("application/pkcs7-signature").getBaseType()); MimeMultipart innerMultiPart = (MimeMultipart) firstBody.getContent(); assertNotNull(innerMultiPart); assertEquals(innerMultiPart.getCount(), 2); assertEquals(new MimeType(innerMultiPart.getBodyPart(0).getContentType()).getBaseType(), new MimeType("text/plain").getBaseType()); assertEquals(new MimeType(innerMultiPart.getBodyPart(1).getContentType()).getBaseType(), new MimeType("message/disposition-notification").getBaseType()); }
@Test public void parseMimeMessageStreamWithoutContentTypeEmbedded() throws Exception { InputStream resourceAsStream = getClass().getResourceAsStream(OPENAS2_MDN_NO_HEADERS_TXT); assertNotNull(resourceAsStream, OPENAS2_MDN_NO_HEADERS_TXT + " not found in classpath"); MimeMessage mimeMessage = MimeMessageHelper.parse(resourceAsStream); Object content = mimeMessage.getContent(); assertNotNull(content); assertTrue(content instanceof String); assertEquals(mimeMessage.getContentType(), "text/plain"); }
@Test public void parseMimeMessageExperiment() throws IOException, MessagingException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("mime-message.txt"); assertNotNull(inputStream, "mime-message.txt not found in class path"); MimeMessage mimeMessage = MimeMessageHelper.parse(inputStream); Object content = mimeMessage.getContent(); assertTrue(content instanceof MimeMultipart); ByteArrayOutputStream os = new ByteArrayOutputStream(); mimeMessage.writeTo(os); String s = new String(os.toByteArray()); assertFalse(s.contains("--null")); }