Compression failing with Java Mail API 1.4.5

2015-04-07T19:09:06

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

Copyright License:
Author:「Piyush」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/29490143/compression-failing-with-java-mail-api-1-4-5

About “Compression failing with Java Mail API 1.4.5” questions

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); CompressedCont...
I'm developing a IMAP client on a custom Android device. So i decided to use the Java Mail library. I needed to update from the 1.4.1 version of Java Mail to 1.4.5 because i had memory problem in ...
I am trying to build Java Mail 1.4.5 with Maven-3.0.4 using default settings of maven. It is getting failed to build due to following errors - [ERROR] COMPILATION ERROR : [INFO] -------------...
I’m trying to use windows compression API in both managed and unmanaged code – compress with a c++ service and decompress with c# console app. I tried to use windows compression API written in c+...
Facing this error while accessing gmail from apache camel [org.apache.camel.component.mail.MailConsumer] (Camel (camel-1) thread #1 - imaps://imap.gmail.com:993) Consumer Consumer[imaps://imap.gm...
I am connecting Office 365 mailbox using java mail API with IMAP protocol. We have continuous stream of messages to mailbox and reading those through java mail API. Once messages are read, those w...
I have written below a program to send an mail through java mail api which send the mail now my query is to handle the exceptional scenarios also lets say if mail is not sent then i have to da
I am trying to connect to Mercury mail server with a java application and I am using JavaMail api. The connection is not successful and I’m getting this error in the log: EHLO x.x.x.x 554 Invalid
I made a CLASSPATH environment variable binding jaf and javamail : name of user variable (windows): CLASSPATH value of this variable: set CLASSPATH=%CLASSPATH%;C:\Java EE\Java SMTP\javamail-1.4.5...
I am using javamail (1.5.5) to fetch mails from exchange 2010 server. It fails to fetch few messages (java.lang.OutOfMemoryError: Java heap space). But it is working fine when using java mail api 1...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.