use of jakarta.mail.internet.ParameterList in project simple-java-mail by bbottema.
the class MimeMessageParserTest method getBodyPartFromDatasource.
private static BodyPart getBodyPartFromDatasource(final AttachmentResource attachmentResource, final String dispositionType) throws MessagingException {
final BodyPart attachmentPart = new MimeBodyPart();
// setting headers isn't working nicely using the javax mail API, so let's do that manually
final String resourceName = "htgfiytityf.txt";
final String fileName = "proper-name.txt";
attachmentPart.setDataHandler(new DataHandler(new NamedDataSource(fileName, attachmentResource.getDataSource())));
attachmentPart.setFileName(fileName);
final String contentType = attachmentResource.getDataSource().getContentType();
ParameterList pl = new ParameterList();
pl.set("filename", fileName);
pl.set("name", fileName);
attachmentPart.setHeader("Content-Type", contentType + pl);
attachmentPart.setHeader("Content-ID", format("<%s>", resourceName));
attachmentPart.setDisposition(dispositionType);
return attachmentPart;
}
use of jakarta.mail.internet.ParameterList in project simple-java-mail by bbottema.
the class MimeMessageHelper method getBodyPartFromDatasource.
/**
* Helper method which generates a {@link BodyPart} from an {@link AttachmentResource} (from its {@link DataSource}) and a disposition type
* ({@link Part#INLINE} or {@link Part#ATTACHMENT}). With this the attachment data can be converted into objects that fit in the email structure.
* <p>
* For every attachment and embedded image a header needs to be set.
*
* @param attachmentResource An object that describes the attachment and contains the actual content data.
* @param dispositionType The type of attachment, {@link Part#INLINE} or {@link Part#ATTACHMENT} .
*
* @return An object with the attachment data read for placement in the email structure.
* @throws MessagingException All BodyPart setters.
*/
private static BodyPart getBodyPartFromDatasource(final AttachmentResource attachmentResource, final String dispositionType) throws MessagingException {
final BodyPart attachmentPart = new MimeBodyPart();
// setting headers isn't working nicely using the javax mail API, so let's do that manually
final String resourceName = determineResourceName(attachmentResource, true);
final String fileName = determineResourceName(attachmentResource, false);
attachmentPart.setDataHandler(new DataHandler(new NamedDataSource(fileName, attachmentResource.getDataSource())));
attachmentPart.setFileName(fileName);
final String contentType = attachmentResource.getDataSource().getContentType();
ParameterList pl = new ParameterList();
pl.set("filename", fileName);
pl.set("name", fileName);
attachmentPart.setHeader("Content-Type", contentType + pl);
attachmentPart.setHeader("Content-ID", format("<%s>", resourceName));
attachmentPart.setDisposition(dispositionType);
return attachmentPart;
}
Aggregations