简体   繁体   中英

Listing attachment without downloading it using javamail api

I am developing a java mail client using javamail api. I need to fetch the list of attachment without fetching it. First i will display the list of attachments and than on click of a particular attachment, i will fetch the data. Currently i am able to fetch the name of all attachments but it is taking too long time since i think my code is also fetching the attachment data. My code is as below

private void getAttachmentList(Part part, List list) throws Exception{
    Object content = part.getContent();
    if(content instanceof Multipart){
        Multipart multiPart = (Multipart)content;
        int no_of_part = multiPart.getCount();

        for(int i=0; i<no_of_part; i++){
            getAttachmentList(multiPart.getBodyPart(i), list);
        }
    }else{
        String disposition = part.getDisposition();

        if (disposition != null && disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
            String fileName = part.getFileName();
            if(fileName != null){
                list.add(fileName);
            }
        } 

    }
}

I have tested this code with my gmail account and it is taking lots of time if my mail is having huge attachments. Any help is appreciated. Thanks in advance

Do this app use POP, or IMAP?

If it uses POP, modify it to use IMAP. The latter may conceivably be quicker as it only downloads headers.

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