@Test void createAttachmentBodyPartWithHeader() throws Exception { Attachment attachment = mock(Attachment.class); when(attachment.getContentInputStream()).thenReturn(new ByteArrayInputStream("Lorem Ipsum".getBytes())); when(attachment.getFilename()).thenReturn("image.png"); when(attachment.getMimeType()).thenReturn("image/png"); Map<String, Object> parameters = Collections.singletonMap("headers", Collections.singletonMap("Content-Transfer-Encoding", "quoted-printable")); MimeBodyPart part = this.attachmentMimeBodyPartFactory.create(attachment, parameters); assertEquals("<image.png>", part.getContentID()); assertTrue(part.getContentType().startsWith("image/png")); assertTrue(part.getFileName().matches("image\\.png")); assertArrayEquals(new String[] { "quoted-printable" }, part.getHeader("Content-Transfer-Encoding")); assertEquals("Lorem Ipsum", IOUtils.toString(part.getDataHandler().getInputStream(), "UTF-8")); }
@Override public MimeBodyPart create(Attachment attachment, Map<String, Object> parameters) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource source = createTemporaryAttachmentDataSource(attachment, attachmentPart); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-Type", attachment.getMimeType()); attachmentPart.setHeader("Content-ID", "<" + attachment.getFilename() + ">"); attachmentPart.setFileName(attachment.getFilename()); addHeaders(attachmentPart, parameters); return attachmentPart; }
AttachmentMimeBodyPartFactory extends AbstractMimeBodyPartFactory<Attachment> implements Initializable { @Override public MimeBodyPart create(Attachment attachment, Map<String, Object> parameters) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource source = createTemporaryAttachmentDataSource(attachment, attachmentPart); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-Type", attachment.getMimeType()); attachmentPart.setHeader("Content-ID", "<" + attachment.getFilename() + ">"); attachmentPart.setFileName(attachment.getFilename()); addHeaders(attachmentPart, parameters); return attachmentPart; } }
AttachmentMimeBodyPartFactory extends AbstractMimeBodyPartFactory<Attachment> implements Initializable { @Override public MimeBodyPart create(Attachment attachment, Map<String, Object> parameters) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource source = createTemporaryAttachmentDataSource(attachment, attachmentPart); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-Type", attachment.getMimeType()); attachmentPart.setHeader("Content-ID", "<" + attachment.getFilename() + ">"); attachmentPart.setFileName(attachment.getFilename()); addHeaders(attachmentPart, parameters); return attachmentPart; }  }
AttachmentMimeBodyPartFactory extends AbstractMimeBodyPartFactory<Attachment> implements Initializable { @Override public MimeBodyPart create(Attachment attachment, Map<String, Object> parameters) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource source = createTemporaryAttachmentDataSource(attachment, attachmentPart); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-Type", attachment.getMimeType()); attachmentPart.setHeader("Content-ID", "<" + attachment.getFilename() + ">"); attachmentPart.setFileName(attachment.getFilename()); addHeaders(attachmentPart, parameters); return attachmentPart; }  @Override void initialize(); @Override MimeBodyPart create(Attachment attachment, Map<String, Object> parameters); }
AttachmentMimeBodyPartFactory extends AbstractMimeBodyPartFactory<Attachment> implements Initializable { @Override public MimeBodyPart create(Attachment attachment, Map<String, Object> parameters) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); DataSource source = createTemporaryAttachmentDataSource(attachment, attachmentPart); attachmentPart.setDataHandler(new DataHandler(source)); attachmentPart.setHeader("Content-Type", attachment.getMimeType()); attachmentPart.setHeader("Content-ID", "<" + attachment.getFilename() + ">"); attachmentPart.setFileName(attachment.getFilename()); addHeaders(attachmentPart, parameters); return attachmentPart; }  @Override void initialize(); @Override MimeBodyPart create(Attachment attachment, Map<String, Object> parameters); static final String TMP_ATTACHMENT_LOCATION_FILE_HEADER; }