0

I have a routine where I have to download an attachment from an e-mail that is multipart/ALTERNATIVE. The attachment come as string and I'm having trouble trying to save it correctly to my hard drive.

I'm able to download the e-mail content, but unable to open it, saying the archive is corrupted and it looks like there are parts missing.

When I print contentType and Encoding I get the following results:

content type of email: multipart/ALTERNATIVEboundary=000000000000b1955e0589a4192e

Content type of the part of message: TEXT/PLAIN; charset=UTF-8

Encode: QUOTED-PRINTABLE

Here's part of the e-mail I'm trying to get the attachment:

begin 600 INTFOCOA.ZIP
M4$L#!!0````(`-I[MTX@BC)`.UI$`(Y71``5````4$%$4D%/,#%?1D]#3RY4
M6%0N0U-"`%"`KW\Y[::&9%]=.4>H(KX):(05"[CW`%*7_+:QH
--------------------end
for (Message message : messages) {          
            Multipart multiPart = (Multipart) message.getContent();
            MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(0);        
            String destFilePath = "C:\\Users\\fribeiro\\Desktop\\arquivo_santander\\testname";
            FileOutputStream output = new FileOutputStream(destFilePath);           
            InputStream input = part.getInputStream();
            byte[] buffer = new byte[4096];
            int byteRead;
            while ((byteRead = input.read(buffer)) != -1) {
                output.write(buffer, 0, byteRead);
            }
            output.close();

        }

I'm trying to get the INTFOCOA.ZIP file. thanks in advance.

avariant
  • 2,234
  • 5
  • 25
  • 33

1 Answers1

0

The content of that part is uuencoding if a zip file.

You need to apply a uudecode algorithm on it to get the zip file.
E.g. see Does Java has any standard mechanism for uudecoding?

Andreas
  • 154,647
  • 11
  • 152
  • 247