Multipart encoding for encryption

209 views Asked by At

I am using Mime4J to mime-encode a message. I have a text part, and attachments, which I add to a MultipartImpl object.

My problem is this: all of the examples I can find involve attaching the MultipartImpl object to a MessageImpl object, ready for sending via email. But I do not want to do this. I simply want to encrypt the multipart text itself. I tried using the following:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
MessageWriter messageWriter = new DefaultMessageWriter();
messageWriter.writeMultipart(multipart, byteArrayOutputStream);

but this gives me the following error:

java.lang.IllegalArgumentException: Missing parent entity in multipart
        at org.apache.james.mime4j.message.DefaultMessageWriter.getContentType(DefaultMessageWriter.java:235)
        at org.apache.james.mime4j.message.DefaultMessageWriter.writeMultipart(DefaultMessageWriter.java:139)

as the MessageWriter expects the Multipart to have a parent.

Is there a way to get the multipart to output to text, without having to attach it to a message?

0

There are 0 answers