开发者

Listing attachment without downloading it using javamail api

开发者 https://www.devze.com 2023-03-02 12:09 出处:网络
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 attach

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开发者_如何学JAVA 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消