@Test void createAttachmentBodyPartWhenWriteError() { Attachment attachment = mock(Attachment.class); when(attachment.getFilename()).thenReturn("image.png"); when(attachment.getContentInputStream()).thenThrow(new RuntimeException("error")); Throwable exception = assertThrows(MessagingException.class, () -> this.attachmentMimeBodyPartFactory.create(attachment, Collections.emptyMap())); assertEquals("Failed to save attachment [image.png] to the file system", exception.getMessage()); }
@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; }