压缩失败,使用Java Mail API 1.4.5

时间:2015-04-07 11:09:07

标签: java api email iaik-jce

我正在尝试使用java邮件API和IAIK压缩MIME邮件。我写了以下代码:


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();

上面的代码在java mail api 1.5.2上运行正常,但在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)

我的iaik cms版本是4.1。 知道我需要在代码中更改哪些内容以使其与java mail api 1.4.5兼容?

由于

0 个答案:

没有答案