简体   繁体   中英

Javamail Getting one extra file On downloading attachments

I'm getting one extra file of type File on downloading attachments. I'm using MimeBodyPart.saveFile() here is my download attachment code

for (MimeBodyPart mbp : msgToDownload.getAttachmentList()) {
     updateProgress(msgToDownload.getAttachmentList().indexOf(mbp),
     msgToDownload.getAttachmentList().size());
     mbp.saveFile(DOWNLOAD_LOCATION + mbp.getFileName());
 }

here msgToDownload is a Class that take Message msg as parameter with some other parameters. And getAttachmentList() is a list of type MimeBodyPart defined as List<MimeBodyPart>
This is how I'm adding attachments to list

    sb.setLength(0);
        msgToRender.clearAttachments();
        Message msg = msgToRender.getMsgRef();
        try {
//            String messageType = msg.getContentType();

            sb.append(getText(msg));

            if (hasAttachments(msg)) {
                Multipart mp = (Multipart) msg.getContent();
                for (int i = mp.getCount() - 1; i >= 0; i--) {
                    BodyPart bp = mp.getBodyPart(i);

                    MimeBodyPart mbp = (MimeBodyPart) bp;
                    msgToRender.addAttachment(mbp);
                }
            }
    }catch(Exception e){
    }

Extra file contain attributes of text part of the Mail. Content of extra file

-001a114fd0aa0b377d0546bb84a0 Content-Type: text/plain; charset=UTF-8 please find the attachments... --001a114fd0aa0b377d0546bb84a0 Content-Type: text/html; charset=UTF-8 please find the attachments... --001a114fd0aa0b377d0546bb84a0--

First, you should learn about the isMimeType method.

The problem is most likely that you're not handling multipart/alternative messages. See the sample code in the JavaMail FAQ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM