Example usage for javax.mail BodyPart getParent

List of usage examples for javax.mail BodyPart getParent

Introduction

In this page you can find the example usage for javax.mail BodyPart getParent.

Prototype

public Multipart getParent() 

Source Link

Document

Return the containing Multipart object, or null if not known.

Usage

From source file:org.mxhero.engine.plugin.attachmentlink.alcommand.internal.domain.Message.java

public void removeAll(Part part, BodyPart notDelete) throws MessagingException, IOException {
    if (isAttach(part)) {
        if (part != notDelete) {
            BodyPart multi = (BodyPart) part;
            Multipart parent = multi.getParent();
            parent.removeBodyPart(multi);
        }//from w w w.  ja va 2  s . c o m
    } else if (part.isMimeType(MULTIPART_TYPE)) {
        Multipart mp = (Multipart) part.getContent();
        List<BodyPart> toRemove = new ArrayList<BodyPart>();
        for (int i = 0; i < mp.getCount(); i++) {
            BodyPart bodyPart = mp.getBodyPart(i);
            if (removePart(bodyPart, notDelete)) {
                toRemove.add(bodyPart);
            } else {
                removeAll(bodyPart, notDelete);
            }
        }
        for (BodyPart bp : toRemove)
            mp.removeBodyPart(bp);
    }
}