We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

[Apose Email] Java to get attach zip file with attachment.getContentStream()

Hi there,

I am trying to extract a zip file attachment from an email with Java.

The project is using Aspose email.

I would like to know if I use attachment.getContentStream() to get the inputStream, would I be able to treat the inputStream as a Java File Type and convert it a Zipfile type and extract the content from the zip file.

This is a sample of what I am trying to do.

[http://www.massapi.com/source/commons-compress-1.1-src/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java.html ](http://www.massapi.com/source/commons-compress-1.1-src/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java.html)

Lib Version: aspose-email-1.1.0-jdk15.jar.

thanks for the help

Vincent

Hi Vincent,


Thanks for writing to Aspose.Email support team.

We are analyzing the requirement and request you to please spare us little time. We will soon share our findings by writing back here on the forum.

Your cooperation is highly appreciated in this regard.

Hi Vincent,


Please accept my apologies for not getting back to you soon.

Aspose.Email saves attachments to messages by reading these as array of bytes from the disc and if you extract the content stream, it returns you the proper stream of the attachment, be it of any type. In this case, I have tested the issue with the following sample code and it printed out the names of the inner files in the zip archive properly. I am sorry but I haven’t worked with Apache commons to explore it further, but In my opinion it should work properly in this regard. Please let us know if we can be of any additional help in this regard.

Java Code:

//Message having some zip
file as
<o:p></o:p>

MailMessage msg = MailMessage.load("Test Zip Attachment .msg");

//Get the only attachment from the message file

Attachment att = (Attachment) msg.getAttachments().get(0);

//Define ZipArchiveInputStream

ZipArchiveInputStream zin = null;

try {

zin = new ZipArchiveInputStream(att.getContentStream());

ZipArchiveEntry zae = zin.getNextZipEntry();

System.out.println(zae.getName());

zae = zin.getNextZipEntry();

System.out.println(zae.getName());

zae = zin.getNextZipEntry();

System.out.println(zae.getName());

} finally {

if (zin != null) {

zin.close();

}

}