예제 #1
0
 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("*****@*****.**");
 }
예제 #2
0
 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();
 }
예제 #3
0
 public InputStream getBodyInputStream() {
   try {
     return ((SingleBody) message.getBody()).getInputStream();
   } catch (IOException e) {
     return null;
   }
 }
예제 #4
0
 /** @see org.apache.james.jdkim.api.Headers#getFields() */
 public List<String> getFields() {
   List<Field> res = message.getHeader().getFields();
   return convertFields(res);
 }
예제 #5
0
 /**
  * Return Header Object as String representation. Each headerline is seperated by "\r\n"
  *
  * @return headers
  */
 public String toString() {
   return message.toString();
 }
예제 #6
0
 /** @see org.apache.james.jdkim.api.Headers#getFields(java.lang.String) */
 public List<String> getFields(final String name) {
   return convertFields(message.getHeader().getFields(name));
 }