use of org.apache.james.mime4j.storage.StorageBodyFactory in project sling by apache.
the class MessageStoreImplAttachmentsTest method createTextBody.
/*
* taken from http://svn.apache.org/repos/asf/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
*/
private static BodyPart createTextBody(String text, String subtype, boolean isAttachment) {
TextBody body = new StorageBodyFactory().textBody(text, MailArchiveServerConstants.DEFAULT_ENCODER.charset().name());
BodyPart bodyPart = new BodyPart();
if (isAttachment) {
bodyPart.setContentDisposition("attachment", "file" + Math.random());
}
bodyPart.setText(body, subtype);
return bodyPart;
}
use of org.apache.james.mime4j.storage.StorageBodyFactory in project sling by apache.
the class MessageStoreImplAttachmentsTest method createRandomBinaryAttachment.
/*
* taken from http://svn.apache.org/repos/asf/james/mime4j/trunk/examples/src/main/java/org/apache/james/mime4j/samples/transform/TransformMessage.java
*/
private static BodyPart createRandomBinaryAttachment(int numberOfBytes) throws IOException {
byte[] data = new byte[numberOfBytes];
new Random().nextBytes(data);
Body body = new StorageBodyFactory().binaryBody(new ByteArrayInputStream(data));
BodyPart bodyPart = new BodyPart();
bodyPart.setContentDisposition("attachment", "file" + Math.random());
bodyPart.setBody(body, "application/octet-stream");
return bodyPart;
}
Aggregations