Get attachment as string from multipart/ALTERNATIVE message [duplicate]

127
May 31, 2019, at 2:00 PM

This question is an exact duplicate of:

  • How do I read a message with an attachment and save the attachment from the content string? 1 answer

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.

Answer 1

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?

READ ALSO
RegEx for replacing the middle letter

RegEx for replacing the middle letter

Invalid regular expression: Invalid group

175
My input is not working in React, onChange looks good too

My input is not working in React, onChange looks good too

My input element doesn't let me type into it, it will show up, with the value i want, but I cannot delete or edit anything in the inputEverything is spelled correctly from what I have seen

127
How to change screens with react-navigation (using a button)

How to change screens with react-navigation (using a button)

I'm new to react native, but I've been researching how to redirect to new activities with buttons for the last few hours with no availMy current solution involves me using react-navigation from multiple files, with App

220
Electronic pre-fill a PDF using php/JS [on hold]

Electronic pre-fill a PDF using php/JS [on hold]

I am being asked to allow a user to upload a PDF into an app and create a "docusign" or "echosign" type of environment where they can prefill fields

158