/** * Retrieve message from retriever and check the body content * * @param retriever Retriever to read from * @param to Account to retrieve */ private void retrieveAndCheckBody(Retriever retriever, String to) throws MessagingException, IOException { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); Message message = messages[0]; assertTrue(message.getContentType().equalsIgnoreCase("application/blubb")); // Check content InputStream contentStream = (InputStream) message.getContent(); byte[] bytes = IOUtils.toByteArray(contentStream); assertArrayEquals(createLargeByteArray(), bytes); // Dump complete mail message. This leads to a FETCH command without section or "len" specified. message.writeTo(new ByteArrayOutputStream()); }
/** * Retrieve message from retriever and check the attachment and text content * * @param retriever Retriever to read from * @param to Account to retrieve */ private void retrieveAndCheck(Retriever retriever, String to) throws MessagingException, IOException { Message[] messages = retriever.getMessages(to); assertEquals(1, messages.length); Message message = messages[0]; assertTrue(message.getContentType().startsWith("multipart/mixed")); MimeMultipart body = (MimeMultipart) message.getContent(); assertTrue(body.getContentType().startsWith("multipart/mixed")); assertEquals(2, body.getCount()); // Message text final BodyPart textPart = body.getBodyPart(0); String text = (String) textPart.getContent(); assertEquals(createLargeString(), text); final BodyPart attachment = body.getBodyPart(1); assertTrue(attachment.getContentType().equalsIgnoreCase("application/blubb; name=file")); InputStream attachmentStream = (InputStream) attachment.getContent(); byte[] bytes = IOUtils.toByteArray(attachmentStream); assertArrayEquals(createLargeByteArray(), bytes); }