private void testEmailWithEmbeddedImage(SendEmail sendEmail) throws IOException { Message mimeMessage = sendEmail.getMimeMessage(); Assertions.assertThat(mimeMessage.getMimeType()).isEqualTo("multipart/alternative"); Body mainBody = mimeMessage.getBody(); Assertions.assertThat(mainBody).isInstanceOf(Multipart.class); Multipart multipart = (Multipart) mainBody; Assertions.assertThat(multipart.getCount()).isEqualTo(2); Entity textPlain = multipart.getBodyParts().get(0); Entity secondPart = multipart.getBodyParts().get(1); Assertions.assertThat(textPlain.getMimeType()).isEqualTo("text/plain"); Assertions.assertThat(secondPart.getMimeType()).isEqualTo("multipart/relative"); Multipart multipartRelative = (Multipart) secondPart.getBody(); Assertions.assertThat(multipartRelative.getCount()).isEqualTo(2); Entity htmlPart = multipartRelative.getBodyParts().get(0); Entity imagePart = multipartRelative.getBodyParts().get(1); Assertions.assertThat(htmlPart.getMimeType()).isEqualTo("text/html"); Assertions.assertThat(imagePart.getMimeType()).isEqualTo("image/png"); TextBody htmlTextBody = (TextBody) htmlPart.getBody(); String htmlText = Joiner.on('\n').join(CharStreams.readLines(htmlTextBody.getReader())); Assertions.assertThat(htmlText) .contains("Galaxy S II") .contains("img src=\"cid:[email protected]\""); String contentId = imagePart.getHeader().getFields("content-id").get(0).getBody(); Assertions.assertThat(contentId).isEqualTo("*****@*****.**"); }
protected void setMessage(Message messageToSend) throws ParserException, MimeException { this.message = messageToSend; this.to = Sets.newHashSet(convertAddressListToRistretoAddresses(message.getTo())); this.cc = Sets.newHashSet(convertAddressListToRistretoAddresses(message.getCc())); this.cci = Sets.newHashSet(convertAddressListToRistretoAddresses(message.getBcc())); filterHeaders(message.getHeader()); lookForInvitation(message); this.hasFromField = false; this.mimeData = serializeMimeData().toByteArray(); }
public InputStream getBodyInputStream() { try { return ((SingleBody) message.getBody()).getInputStream(); } catch (IOException e) { return null; } }
/** @see org.apache.james.jdkim.api.Headers#getFields() */ public List<String> getFields() { List<Field> res = message.getHeader().getFields(); return convertFields(res); }
/** * Return Header Object as String representation. Each headerline is seperated by "\r\n" * * @return headers */ public String toString() { return message.toString(); }
/** @see org.apache.james.jdkim.api.Headers#getFields(java.lang.String) */ public List<String> getFields(final String name) { return convertFields(message.getHeader().getFields(name)); }