2

I'm trying to compress a MIME message using java mail APIs and IAIK. I've written the following code:


MimeBodyPart wrappedMessage = new MimeBodyPart(new InternetHeaders(), content);
CompressedContent compressed = new CompressedContent();
compressed.setDataHandler(wrappedMessage.getDataHandler());
compressed.setCompressionAlgorithm((AlgorithmID) CMSAlgorithmID.zlib_compress.clone());

String contentType = compressed.getContentType();
compressed.setHeaders(wrappedMessage);
wrappedMessage.setContent(compressed, contentType);

setLocalCommandMap(wrappedMessage.getDataHandler()); //I'm setting IAIK command map

ByteArrayOutputStream baos = new ByteArrayOutputStream();
wrappedMessage.writeTo(baos);
byte[] ret = baos.toByteArray();

The above piece of code is working fine with java mail api 1.5.2, but fails with the following exception with java mail api 1.4.5:

java.io.IOException: javax.mail.MessagingException: javax.mail.MessagingException: No MimeMessage content
    at iaik.smime.encrypted_content.writeTo(Unknown Source)
    at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865)
    at CompressionTest.main(CompressionTest.java:34)

My iaik cms version is 4.1. Any idea what I need to change in my code to make it compatible with java mail api 1.4.5?

Thanks

Manuel
  • 3,828
  • 6
  • 33
  • 48
Piyush
  • 101
  • 4

0 Answers0