/** * Returns a <code>List</code> that contains a <code>Part</code> * for each descendent of a given <code>Part</code>. * @param part * @throws MessagingException * @throws IOException * @see Part */ private List<Part> getAllSubparts(Part part) throws MessagingException, IOException { List<Part> parts = new ArrayList<Part>(); addSubhierarchy(parts, part, 0); return parts; }
private void addSubhierarchy(List<Part> parts, Part part, int depth) throws MessagingException, IOException { if (part.isMimeType("message/rfc822")) { // nested message Part subpart = (Part)part.getContent(); addSubhierarchy(parts, subpart, depth); } else if (part.isMimeType("multipart/*")) { Multipart subparts = (Multipart)part.getContent(); for (int i=0; i<subparts.getCount(); i++) { Part subpart = subparts.getBodyPart(i); addSubhierarchy(parts, subpart, depth); } } else parts.add(part); }