@Test public void createWhenHTMLContentAndHeader() throws Exception { MimeBodyPart bodyPart = this.htmlMimeBodyPartFactory.create("<p>some html</p>", Collections.singletonMap("headers", Collections.singletonMap("key", "value"))); assertEquals("<p>some html</p>", bodyPart.getContent()); assertArrayEquals(new String[]{ "value" }, bodyPart.getHeader("key")); }
@Override public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException { MimeBodyPart resultBodyPart; List<Attachment> allAttachments = (List<Attachment>) parameters.get("attachments"); Pair<List<Attachment>, List<Attachment>> attachmentPairs = separateAttachments(content, allAttachments); List<Attachment> embeddedImageAttachments = attachmentPairs.getLeft(); List<Attachment> normalAttachments = attachmentPairs.getRight(); MimeBodyPart htmlBodyPart; if (!embeddedImageAttachments.isEmpty()) { htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(createHTMLMultipart(content, embeddedImageAttachments)); } else { htmlBodyPart = createHTMLBodyPart(content, false); } String alternativeText = (String) parameters.get("alternate"); if (alternativeText != null) { resultBodyPart = createAlternativePart(htmlBodyPart, this.defaultPartFactory.create(alternativeText, Collections.<String, Object>emptyMap())); } else { resultBodyPart = htmlBodyPart; } if (!normalAttachments.isEmpty()) { MimeMultipart multipart = new MimeMultipart("mixed"); multipart.addBodyPart(resultBodyPart); handleAttachments(multipart, normalAttachments); resultBodyPart = new MimeBodyPart(); resultBodyPart.setContent(multipart); } addHeaders(resultBodyPart, parameters); return resultBodyPart; }
HTMLMimeBodyPartFactory extends AbstractMimeBodyPartFactory<String> { @Override public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException { MimeBodyPart resultBodyPart; List<Attachment> allAttachments = (List<Attachment>) parameters.get("attachments"); Pair<List<Attachment>, List<Attachment>> attachmentPairs = separateAttachments(content, allAttachments); List<Attachment> embeddedImageAttachments = attachmentPairs.getLeft(); List<Attachment> normalAttachments = attachmentPairs.getRight(); MimeBodyPart htmlBodyPart; if (!embeddedImageAttachments.isEmpty()) { htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(createHTMLMultipart(content, embeddedImageAttachments)); } else { htmlBodyPart = createHTMLBodyPart(content, false); } String alternativeText = (String) parameters.get("alternate"); if (alternativeText != null) { resultBodyPart = createAlternativePart(htmlBodyPart, this.defaultPartFactory.create(alternativeText, Collections.<String, Object>emptyMap())); } else { resultBodyPart = htmlBodyPart; } if (!normalAttachments.isEmpty()) { MimeMultipart multipart = new MimeMultipart("mixed"); multipart.addBodyPart(resultBodyPart); handleAttachments(multipart, normalAttachments); resultBodyPart = new MimeBodyPart(); resultBodyPart.setContent(multipart); } addHeaders(resultBodyPart, parameters); return resultBodyPart; } }
HTMLMimeBodyPartFactory extends AbstractMimeBodyPartFactory<String> { @Override public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException { MimeBodyPart resultBodyPart; List<Attachment> allAttachments = (List<Attachment>) parameters.get("attachments"); Pair<List<Attachment>, List<Attachment>> attachmentPairs = separateAttachments(content, allAttachments); List<Attachment> embeddedImageAttachments = attachmentPairs.getLeft(); List<Attachment> normalAttachments = attachmentPairs.getRight(); MimeBodyPart htmlBodyPart; if (!embeddedImageAttachments.isEmpty()) { htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(createHTMLMultipart(content, embeddedImageAttachments)); } else { htmlBodyPart = createHTMLBodyPart(content, false); } String alternativeText = (String) parameters.get("alternate"); if (alternativeText != null) { resultBodyPart = createAlternativePart(htmlBodyPart, this.defaultPartFactory.create(alternativeText, Collections.<String, Object>emptyMap())); } else { resultBodyPart = htmlBodyPart; } if (!normalAttachments.isEmpty()) { MimeMultipart multipart = new MimeMultipart("mixed"); multipart.addBodyPart(resultBodyPart); handleAttachments(multipart, normalAttachments); resultBodyPart = new MimeBodyPart(); resultBodyPart.setContent(multipart); } addHeaders(resultBodyPart, parameters); return resultBodyPart; }  }
HTMLMimeBodyPartFactory extends AbstractMimeBodyPartFactory<String> { @Override public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException { MimeBodyPart resultBodyPart; List<Attachment> allAttachments = (List<Attachment>) parameters.get("attachments"); Pair<List<Attachment>, List<Attachment>> attachmentPairs = separateAttachments(content, allAttachments); List<Attachment> embeddedImageAttachments = attachmentPairs.getLeft(); List<Attachment> normalAttachments = attachmentPairs.getRight(); MimeBodyPart htmlBodyPart; if (!embeddedImageAttachments.isEmpty()) { htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(createHTMLMultipart(content, embeddedImageAttachments)); } else { htmlBodyPart = createHTMLBodyPart(content, false); } String alternativeText = (String) parameters.get("alternate"); if (alternativeText != null) { resultBodyPart = createAlternativePart(htmlBodyPart, this.defaultPartFactory.create(alternativeText, Collections.<String, Object>emptyMap())); } else { resultBodyPart = htmlBodyPart; } if (!normalAttachments.isEmpty()) { MimeMultipart multipart = new MimeMultipart("mixed"); multipart.addBodyPart(resultBodyPart); handleAttachments(multipart, normalAttachments); resultBodyPart = new MimeBodyPart(); resultBodyPart.setContent(multipart); } addHeaders(resultBodyPart, parameters); return resultBodyPart; }  @Override MimeBodyPart create(String content, Map<String, Object> parameters); }
HTMLMimeBodyPartFactory extends AbstractMimeBodyPartFactory<String> { @Override public MimeBodyPart create(String content, Map<String, Object> parameters) throws MessagingException { MimeBodyPart resultBodyPart; List<Attachment> allAttachments = (List<Attachment>) parameters.get("attachments"); Pair<List<Attachment>, List<Attachment>> attachmentPairs = separateAttachments(content, allAttachments); List<Attachment> embeddedImageAttachments = attachmentPairs.getLeft(); List<Attachment> normalAttachments = attachmentPairs.getRight(); MimeBodyPart htmlBodyPart; if (!embeddedImageAttachments.isEmpty()) { htmlBodyPart = new MimeBodyPart(); htmlBodyPart.setContent(createHTMLMultipart(content, embeddedImageAttachments)); } else { htmlBodyPart = createHTMLBodyPart(content, false); } String alternativeText = (String) parameters.get("alternate"); if (alternativeText != null) { resultBodyPart = createAlternativePart(htmlBodyPart, this.defaultPartFactory.create(alternativeText, Collections.<String, Object>emptyMap())); } else { resultBodyPart = htmlBodyPart; } if (!normalAttachments.isEmpty()) { MimeMultipart multipart = new MimeMultipart("mixed"); multipart.addBodyPart(resultBodyPart); handleAttachments(multipart, normalAttachments); resultBodyPart = new MimeBodyPart(); resultBodyPart.setContent(multipart); } addHeaders(resultBodyPart, parameters); return resultBodyPart; }  @Override MimeBodyPart create(String content, Map<String, Object> parameters);  }