/** * Disposes of the body of this entity. Note that the dispose call does not * get forwarded to the parent entity of this Entity. * * Subclasses that need to free resources should override this method and * invoke super.dispose(). * * @see org.apache.james.mime4j.dom.Disposable#dispose() */ public void dispose() { if (body != null) { body.dispose(); } }
public List<MessageAttachment> retrieveAttachments(InputStream fullContent) throws MimeException, IOException { DefaultMessageBuilder defaultMessageBuilder = new DefaultMessageBuilder(); defaultMessageBuilder.setMimeEntityConfig(MimeConfig.PERMISSIVE); defaultMessageBuilder.setDecodeMonitor(DecodeMonitor.SILENT); Message message = defaultMessageBuilder.parseMessage(fullContent); Body body = message.getBody(); try { if (isAttachment(message, Context.BODY)) { return ImmutableList.of(retrieveAttachment(message)); } if (body instanceof Multipart) { Multipart multipartBody = (Multipart) body; return listAttachments(multipartBody, Context.fromSubType(multipartBody.getSubType())) .collect(Guavate.toImmutableList()); } else { return ImmutableList.of(); } } finally { body.dispose(); } }