/** * Creates attachment body part. Handles regular and inline attachments. * * @param attachment Body part {@link EmailAttachment}. * @return {@link MimeBodyPart} which represents body part attachment. * @throws MessagingException if there is a failure. */ protected MimeBodyPart createAttachmentBodyPart(final EmailAttachment<? extends DataSource> attachment) throws MessagingException { final MimeBodyPart part = new MimeBodyPart(); final String attachmentName = attachment.getEncodedName(); if (attachmentName != null) { part.setFileName(attachmentName); } part.setDataHandler(new DataHandler(attachment.getDataSource())); if (attachment.getContentId() != null) { part.setContentID(StringPool.LEFT_CHEV + attachment.getContentId() + StringPool.RIGHT_CHEV); } if (attachment.isInline()) { part.setDisposition(INLINE); } return part; }
private void checkAttachments(final List<EmailAttachment<? extends DataSource>> sentAttachments, final List<EmailAttachment<? extends DataSource>> receivedAttachments) { checkSize(sentAttachments); checkSize(receivedAttachments); String name = ZERO; byte[] data = BYTES_7_8_9; checkAttachmentInfo(sentAttachments, 0, receivedAttachments, 2, name, data, false, false); name = ONE; data = BYTES_4_5_6; checkAttachmentInfo(sentAttachments, 1, receivedAttachments, 3, name, data, false, false); name = TWO; data = BYTES_1_2_3; checkAttachmentInfo(sentAttachments, 2, receivedAttachments, 4, name, data, false, false); //assertEquals(CID_1, sentAttachments.get(ndx).getContentId()); //assertEquals("<CID1>", receivedAttachments.get(ndx).getContentId()); // These are null because used storeAttachment method instead of embedAttachment method. assertNull(sentAttachments.get(2).getContentId()); assertNull(receivedAttachments.get(4).getContentId()); /**/ name = null; data = BYTES_0_1_0; checkAttachmentInfo(sentAttachments, 3, receivedAttachments, 0, name, data, true, true); name = THREE; data = BYTES_10_11_12; checkAttachmentInfo(sentAttachments, 4, receivedAttachments, 1, name, data, true, true); }
/** * Creates attachment body part. Handles regular and inline attachments. * * @param attachment Body part {@link EmailAttachment}. * @return {@link MimeBodyPart} which represents body part attachment. * @throws MessagingException if there is a failure. */ protected MimeBodyPart createAttachmentBodyPart(final EmailAttachment<? extends DataSource> attachment) throws MessagingException { final MimeBodyPart part = new MimeBodyPart(); final String attachmentName = attachment.getEncodedName(); if (attachmentName != null) { part.setFileName(attachmentName); } part.setDataHandler(new DataHandler(attachment.getDataSource())); if (attachment.getContentId() != null) { part.setContentID(StringPool.LEFT_CHEV + attachment.getContentId() + StringPool.RIGHT_CHEV); } if (attachment.isInline()) { part.setDisposition(INLINE); } return part; }