Index: src/test/java/org/apache/james/mime4j/message/MessageTest.java
===================================================================
--- src/test/java/org/apache/james/mime4j/message/MessageTest.java	(revision 703203)
+++ src/test/java/org/apache/james/mime4j/message/MessageTest.java	(working copy)
@@ -26,11 +26,13 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.List;
 
 import junit.framework.TestCase;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.ExampleMail;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.util.MessageUtils;
@@ -166,13 +168,13 @@
         assertTrue("header added", lines.contains(testheader));
     }
 
-    public void testDisposeGetsPropagatedToBody() throws Exception {
-        DummyBody body1 = new DummyBody();
+    public void testDisposableBodiesGetDisposed() throws Exception {
+        DisposableBody body1 = new DisposableBody();
         BodyPart part1 = new BodyPart();
         part1.setHeader(headerEmpty);
         part1.setBody(body1);
 
-        DummyBody body2 = new DummyBody();
+        DisposableBody body2 = new DisposableBody();
         BodyPart part2 = new BodyPart();
         part2.setHeader(headerEmpty);
         part2.setBody(body2);
@@ -194,19 +196,6 @@
         assertTrue(body2.disposed);
     }
 
-    public void testDisposedMessageThrowsException()
-            throws Exception {
-        byte[] inputByte = getRawMessageAsByteArray();
-        Message m = new Message(new ByteArrayInputStream(inputByte));
-        m.dispose();
-
-        try {
-            m.writeTo(new ByteArrayOutputStream(), MessageUtils.LENIENT);
-            fail();
-        } catch (IllegalStateException expected) {
-        }
-    }
-
     private byte[] getRawMessageAsByteArray() {
         StringBuffer header = new StringBuffer();
         StringBuffer body = new StringBuffer();
@@ -226,7 +215,7 @@
         return complete.toString().getBytes();
     }
 
-    private static final class DummyBody extends AbstractBody {
+    private static final class DisposableBody extends AbstractBody implements Disposable {
 
         public boolean disposed = false;
 
@@ -241,4 +230,105 @@
 
     }
 
+    static class SimpleEntityVisitor extends AbstractEntityVisitor {
+
+        private final List visitedMessages;
+        private final List visitedMultiparts;
+        private final List visitedBodyParts;
+        private final List visitedBodies;
+        
+        public SimpleEntityVisitor() {
+            super();
+            this.visitedMessages = new ArrayList();
+            this.visitedMultiparts = new ArrayList();
+            this.visitedBodyParts = new ArrayList();
+            this.visitedBodies = new ArrayList();
+        }
+        
+        public void beginMessage(Message message) {
+            this.visitedMessages.add(message.getClass().getName());
+        }
+        
+        public void beginMultipart(Multipart multipart) {
+            this.visitedMultiparts.add(multipart.getClass().getName());
+        }
+        
+        public void beginBodyPart(BodyPart bodyPart) {
+            this.visitedBodyParts.add(bodyPart.getClass().getName());
+        }
+        
+        public void visitBody(Body body) {
+            this.visitedBodies.add(body.getClass().getName());
+        }
+
+        public List getVisitedMessages() {
+            return this.visitedMessages;
+        }
+        
+        public List getVisitedMultiparts() {
+            return this.visitedMultiparts;
+        }
+        
+        public List getVisitedBodyParts() {
+            return this.visitedBodyParts;
+        }
+        
+        public List getVisitedBodies() {
+            return this.visitedBodies;
+        }
+        
+    }
+    
+    public void testSimpleMailVisitor() throws Exception {
+        ByteArrayInputStream in = new ByteArrayInputStream(ExampleMail.RFC822_SIMPLE_BYTES);
+        Message message = new Message(in);
+
+        SimpleEntityVisitor visitor = new SimpleEntityVisitor();
+        message.accept(visitor);
+
+        List visitedMessages = visitor.getVisitedMessages();
+        assertEquals(1, visitedMessages.size());
+        assertEquals("org.apache.james.mime4j.message.Message", visitedMessages.get(0));
+
+        List visitedMultiparts = visitor.getVisitedMultiparts();
+        assertEquals(0, visitedMultiparts.size());
+
+        List visitedBodyParts = visitor.getVisitedBodyParts();
+        assertEquals(0, visitedBodyParts.size());
+
+        List visitedBodies = visitor.getVisitedBodies();
+        assertEquals(1, visitedBodies.size());
+        assertEquals("org.apache.james.mime4j.message.TempFileTextBody", visitedBodies.get(0));
+    }
+    
+    public void testMultipartMailVisitor() throws Exception {
+        ByteArrayInputStream in = new ByteArrayInputStream(ExampleMail.MULTIPART_WITH_BINARY_ATTACHMENTS_BYTES);
+        Message message = new Message(in);
+
+        SimpleEntityVisitor visitor = new SimpleEntityVisitor();
+        message.accept(visitor);
+
+        List visitedMessages = visitor.getVisitedMessages();
+        assertEquals(1, visitedMessages.size());
+        assertEquals("org.apache.james.mime4j.message.Message", visitedMessages.get(0));
+
+        List visitedMultiparts = visitor.getVisitedMultiparts();
+        assertEquals(1, visitedMultiparts.size());
+        assertEquals("org.apache.james.mime4j.message.Multipart", visitedMultiparts.get(0));
+
+        List visitedBodyParts = visitor.getVisitedBodyParts();
+        assertEquals(4, visitedBodyParts.size());
+        assertEquals("org.apache.james.mime4j.message.BodyPart", visitedBodyParts.get(0));
+        assertEquals("org.apache.james.mime4j.message.BodyPart", visitedBodyParts.get(1));
+        assertEquals("org.apache.james.mime4j.message.BodyPart", visitedBodyParts.get(2));
+        assertEquals("org.apache.james.mime4j.message.BodyPart", visitedBodyParts.get(3));
+
+        List visitedBodies = visitor.getVisitedBodies();
+        assertEquals(4, visitedBodies.size());
+        assertEquals("org.apache.james.mime4j.message.TempFileTextBody", visitedBodies.get(0));
+        assertEquals("org.apache.james.mime4j.message.TempFileBinaryBody", visitedBodies.get(1));
+        assertEquals("org.apache.james.mime4j.message.TempFileBinaryBody", visitedBodies.get(2));
+        assertEquals("org.apache.james.mime4j.message.TempFileTextBody", visitedBodies.get(3));
+    }
+    
 }
Index: src/main/java/org/apache/james/mime4j/message/DisposingEntityVisitor.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/DisposingEntityVisitor.java	(revision 0)
+++ src/main/java/org/apache/james/mime4j/message/DisposingEntityVisitor.java	(revision 0)
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+/**
+ * Visitor implementation that disposes of {@link Disposable} body objects.
+ * 
+ * @version $Id$
+ */
+public class DisposingEntityVisitor extends AbstractEntityVisitor {
+
+    public static final DisposingEntityVisitor INSTANCE = new DisposingEntityVisitor();
+
+    private DisposingEntityVisitor() {
+    }
+
+    public void visitBody(Body body) {
+        if (body instanceof Disposable) {
+            ((Disposable) body).dispose();
+        }
+    }
+
+}

Property changes on: src/main/java/org/apache/james/mime4j/message/DisposingEntityVisitor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/main/java/org/apache/james/mime4j/message/Entity.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/Entity.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/Entity.java	(working copy)
@@ -37,10 +37,10 @@
  * @version $Id: Entity.java,v 1.3 2004/10/02 12:41:11 ntherning Exp $
  */
 public abstract class Entity implements Disposable {
+
     private Header header = null;
     private Body body = null;
     private Entity parent = null;
-    private boolean disposed = false;
 
     /**
      * Gets the parent entity of this entity.
@@ -59,9 +59,6 @@
      *        this will be the root entity.
      */
     public void setParent(Entity parent) {
-        if (disposed)
-            throw new IllegalStateException("Entity has been disposed");
-
         this.parent = parent;
     }
     
@@ -80,9 +77,6 @@
      * @param header the header.
      */
     public void setHeader(Header header) {
-        if (disposed)
-            throw new IllegalStateException("Entity has been disposed");
-
         this.header = header;
     }
     
@@ -101,9 +95,6 @@
      * @param body the body.
      */
     public void setBody(Body body) {
-        if (disposed)
-            throw new IllegalStateException("Entity has been disposed");
-
         this.body = body;
         body.setParent(this);
     }
@@ -183,9 +174,6 @@
      * @throws IOException 
      */
     public void writeTo(OutputStream out, int mode) throws IOException, MimeException {
-        if (disposed)
-            throw new IllegalStateException("Entity has been disposed");
-
         getHeader().writeTo(out, mode);
         
         out.flush();
@@ -209,38 +197,23 @@
     }
 
     /**
-     * Disposes the body of this entity. Note that the dispose call does not get
-     * forwarded to the parent entity of this Entity.
+     * Accepts a visitor for {@link Message}, {@link Multipart}, {@link BodyPart}
+     * and {@link Body} objects contained in this entity. 
      * 
-     * Subclasses that need to free resources should override this method and
-     * invoke super.dispose().
+     * @param visitor visitor to accept.
+     */
+    public abstract void accept(EntityVisitor visitor);
+
+    /**
+     * Disposes this entity by recursively disposing all of its
+     * {@link Body}s that implement the {@link Disposable} interface.
      * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * Only needs to be called explicitly if this entity does not have 
+     * a parent entity. Otherwise disposing the parent entity also takes
+     * care of disposing this entity object.
      */
     public void dispose() {
-        if (disposed)
-            return;
-
-        try {
-            if (body != null)
-                body.dispose();
-        } finally {
-            disposed = true;
-
-            header = null;
-            body = null;
-            parent = null;
-        }
+        accept(DisposingEntityVisitor.INSTANCE);
     }
 
-    /**
-     * Ensures that the <code>dispose</code> method of this entity is called
-     * when there are no more references to it.
-     *
-     * Leave them out ATM (https://issues.apache.org/jira/browse/MIME4J-72?focusedCommentId=12636007#action_12636007)
-    protected void finalize() throws Throwable {
-        dispose();
-    }
-     */
-
 }
Index: src/main/java/org/apache/james/mime4j/message/AbstractEntityVisitor.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/AbstractEntityVisitor.java	(revision 0)
+++ src/main/java/org/apache/james/mime4j/message/AbstractEntityVisitor.java	(revision 0)
@@ -0,0 +1,81 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Abstract implementation of the {@link EntityVisitor} interface
+ * that traverses down the hierarchy of a {@link Message}.
+ */
+public abstract class AbstractEntityVisitor implements EntityVisitor {
+
+    public void visitMessage(Message message) {
+        beginMessage(message);
+        
+        Body body = message.getBody();
+        if (body != null)
+            body.accept(this);
+
+        endMessage(message);
+    }
+
+    public void visitMultipart(Multipart multipart) {
+        beginMultipart(multipart);
+
+        List bodyParts = multipart.getBodyParts();
+        for (Iterator iterator = bodyParts.iterator(); iterator.hasNext();) {
+            BodyPart bodyPart = (BodyPart) iterator.next();
+            bodyPart.accept(this);
+        }
+
+        endMultipart(multipart);
+    }
+
+    public void visitBodyPart(BodyPart bodyPart) {
+        beginBodyPart(bodyPart);
+        
+        Body body = bodyPart.getBody();
+        if (body != null)
+            body.accept(this);
+
+        endBodyPart(bodyPart);
+    }
+
+    public void beginMessage(Message message) {
+    }
+
+    public void endMessage(Message message) {
+    }
+
+    public void beginMultipart(Multipart multipart) {
+    }
+
+    public void endMultipart(Multipart multipart) {
+    }
+
+    public void beginBodyPart(BodyPart bodyPart) {
+    }
+
+    public void endBodyPart(BodyPart bodyPart) {
+    }
+    
+}

Property changes on: src/main/java/org/apache/james/mime4j/message/AbstractEntityVisitor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/main/java/org/apache/james/mime4j/message/Multipart.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/Multipart.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/Multipart.java	(working copy)
@@ -45,13 +45,12 @@
  * 
  * @version $Id: Multipart.java,v 1.3 2004/10/02 12:41:11 ntherning Exp $
  */
-public class Multipart implements Body {
+public class Multipart implements Body, Disposable {
     private String preamble = "";
     private String epilogue = "";
     private List bodyParts = new LinkedList();
     private Entity parent = null;
     private String subType;
-    private boolean disposed = false;
 
     /**
      * Creates a new empty <code>Multipart</code> instance.
@@ -79,9 +78,6 @@
      * @param subType the sub-type.
      */
     public void setSubType(String subType) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         this.subType = subType;
     }
     
@@ -96,9 +92,6 @@
      * @see org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity)
      */
     public void setParent(Entity parent) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         this.parent = parent;
         for (Iterator it = bodyParts.iterator(); it.hasNext();) {
             ((BodyPart) it.next()).setParent(parent);
@@ -120,9 +113,6 @@
      * @param epilogue the epilogue.
      */
     public void setEpilogue(String epilogue) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         this.epilogue = epilogue;
     }
     
@@ -141,9 +131,6 @@
      * @param bodyParts the new list of <code>BodyPart</code> objects.
      */
     public void setBodyParts(List bodyParts) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         this.bodyParts = bodyParts;
         for (Iterator it = bodyParts.iterator(); it.hasNext();) {
             ((BodyPart) it.next()).setParent(parent);
@@ -156,9 +143,6 @@
      * @param bodyPart the body part.
      */
     public void addBodyPart(BodyPart bodyPart) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         bodyParts.add(bodyPart);
         bodyPart.setParent(parent);
     }
@@ -178,9 +162,6 @@
      * @param preamble the preamble.
      */
     public void setPreamble(String preamble) {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         this.preamble = preamble;
     }
 
@@ -194,9 +175,6 @@
      * @throws MimeException if case of a MIME protocol violation
      */
     public void writeTo(final OutputStream out, int mode) throws IOException, MimeException {
-        if (disposed)
-            throw new IllegalStateException("Multipart has been disposed");
-
         Entity e = getParent();
         
         ContentTypeField cField = (ContentTypeField) e.getHeader().getField(
@@ -245,37 +223,25 @@
     }
 
     /**
-     * Disposes the BodyParts of this Multipart. Note that the dispose call does
-     * not get forwarded to the parent entity of this Multipart.
+     * Accepts a visitor for {@link Message}, {@link Multipart}, {@link BodyPart}
+     * and {@link Body} objects contained in this multipart. 
      * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * @param visitor visitor to accept.
      */
-    public void dispose() {
-        if (disposed)
-            return;
-
-        try {
-            for (Iterator it = bodyParts.iterator(); it.hasNext();) {
-                ((BodyPart) it.next()).dispose();
-            }
-        } finally {
-            disposed = true;
-
-            preamble = null;
-            epilogue = null;
-            bodyParts = null;
-            parent = null;
-            subType = null;
-        }
+    public void accept(final EntityVisitor visitor) {
+        visitor.visitMultipart(this);
     }
 
     /**
-     * Ensures that the <code>dispose</code> method of this multipart is
-     * called when there are no more references to it.
-     *
-     * Leave them out ATM (https://issues.apache.org/jira/browse/MIME4J-72?focusedCommentId=12636007#action_12636007)
-    protected void finalize() throws Throwable {
-        dispose();
-    }
+     * Disposes this multipart by recursively disposing all of its
+     * {@link Body}s that implement the {@link Disposable} interface.
+     * 
+     * Only needs to be called explicitly if this multipart does not have 
+     * a parent entity. Otherwise disposing the parent entity also takes
+     * care of disposing this multipart object.
      */
+    public void dispose() {
+        accept(DisposingEntityVisitor.INSTANCE);
+    }
+    
 }
Index: src/main/java/org/apache/james/mime4j/message/AbstractBody.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/AbstractBody.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/AbstractBody.java	(working copy)
@@ -28,8 +28,8 @@
  * @version $Id: AbstractBody.java,v 1.2 2004/10/02 12:41:11 ntherning Exp $
  */
 public abstract class AbstractBody implements Body {
+
     private Entity parent = null;
-    protected boolean disposed = false;
     
     /**
      * @see org.apache.james.mime4j.message.Body#getParent()
@@ -42,39 +42,14 @@
      * @see org.apache.james.mime4j.message.Body#setParent(org.apache.james.mime4j.message.Entity)
      */
     public void setParent(Entity parent) {
-        if (disposed)
-            throw new IllegalStateException("AbstractBody has been disposed");
-
         this.parent = parent;
     }
 
     /**
-     * Subclasses should override this method if they have allocated resources
-     * that need to be freed explicitly (e.g. cannot be simply reclaimed by the
-     * garbage collector). Subclasses that override this method should invoke
-     * super.dispose().
-     * 
-     * The default implementation marks this AbstractBody as disposed.
-     * 
-     * @see org.apache.james.mime4j.message.Disposable#dispose()
+     * @see org.apache.james.mime4j.message.Body#accept(EntityVisitor)
      */
-    public void dispose() {
-        if (disposed)
-            return;
-
-        disposed = true;
-
-        parent = null;
+    public void accept(final EntityVisitor visitor) {
+        visitor.visitBody(this);
     }
 
-    /**
-     * Ensures that the <code>dispose</code> method of this abstract body is
-     * called when there are no more references to it.
-     *
-     * Leave them out ATM (https://issues.apache.org/jira/browse/MIME4J-72?focusedCommentId=12636007#action_12636007)
-    protected void finalize() throws Throwable {
-        dispose();
-    }
-     */
-
 }
Index: src/main/java/org/apache/james/mime4j/message/Message.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/Message.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/Message.java	(working copy)
@@ -82,5 +82,15 @@
     public UnstructuredField getSubject() {
         return (UnstructuredField) getHeader().getField(Field.SUBJECT);
     }
+
+    /**
+     * Accepts a visitor for {@link Message}, {@link Multipart}, {@link BodyPart}
+     * and {@link Body} objects contained in this MIME message. 
+     * 
+     * @param visitor visitor to accept.
+     */
+    public void accept(EntityVisitor visitor) {
+        visitor.visitMessage(this);
+    }
     
 }
Index: src/main/java/org/apache/james/mime4j/message/BodyPart.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/BodyPart.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/BodyPart.java	(working copy)
@@ -29,4 +29,14 @@
  */
 public class BodyPart extends Entity {
 
+    /**
+     * Accepts a visitor for {@link Message}, {@link Multipart}, {@link BodyPart}
+     * and {@link Body} objects contained in this body part.
+     * 
+     * @param visitor visitor to accept.
+     */
+    public void accept(EntityVisitor visitor) {
+        visitor.visitBodyPart(this);
+    }
+
 }
Index: src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/TempFileTextBody.java	(working copy)
@@ -41,7 +41,7 @@
  * 
  * @version $Id: TempFileTextBody.java,v 1.3 2004/10/25 07:26:46 ntherning Exp $
  */
-class TempFileTextBody extends AbstractBody implements TextBody {
+class TempFileTextBody extends AbstractBody implements TextBody, Disposable {
     private static Log log = LogFactory.getLog(TempFileTextBody.class);
     
     private String mimeCharset = null;
@@ -104,9 +104,6 @@
      * @see org.apache.james.mime4j.message.Body#writeTo(java.io.OutputStream, int)
      */
     public void writeTo(OutputStream out, int mode) throws IOException {
-        if (disposed)
-            throw new IllegalStateException("TempFileTextBody has been disposed");
-
         final InputStream inputStream = tempFile.getInputStream();
         CodecUtil.copy(inputStream, out);
     }
@@ -117,13 +114,9 @@
      * @see org.apache.james.mime4j.message.Disposable#dispose()
      */
     public void dispose() {
-        try {
+        if (tempFile != null) {
             tempFile.delete();
-        } finally {
-            mimeCharset = null;
             tempFile = null;
-
-            super.dispose();
         }
     }
 }
Index: src/main/java/org/apache/james/mime4j/message/TempFileBinaryBody.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/TempFileBinaryBody.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/TempFileBinaryBody.java	(working copy)
@@ -35,7 +35,7 @@
  * 
  * @version $Id: TempFileBinaryBody.java,v 1.2 2004/10/02 12:41:11 ntherning Exp $
  */
-class TempFileBinaryBody extends AbstractBody implements BinaryBody {
+class TempFileBinaryBody extends AbstractBody implements BinaryBody, Disposable {
     
     private TempFile tempFile = null;
 
@@ -66,9 +66,6 @@
      * @see org.apache.james.mime4j.message.Body#writeTo(java.io.OutputStream, int)
      */
     public void writeTo(OutputStream out, int mode) throws IOException {
-        if (disposed)
-            throw new IllegalStateException("TempFileBinaryBody has been disposed");
-
         final InputStream inputStream = getInputStream();
         CodecUtil.copy(inputStream,out);
     }
@@ -79,12 +76,9 @@
      * @see org.apache.james.mime4j.message.Disposable#dispose()
      */
     public void dispose() {
-        try {
+        if (tempFile != null) {
             tempFile.delete();
-        } finally {
             tempFile = null;
-
-            super.dispose();
         }
     }
 }
Index: src/main/java/org/apache/james/mime4j/message/EntityVisitor.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/EntityVisitor.java	(revision 0)
+++ src/main/java/org/apache/james/mime4j/message/EntityVisitor.java	(revision 0)
@@ -0,0 +1,59 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mime4j.message;
+
+/**
+ * Visitor interface for {@link Message}, {@link Multipart}, {@link BodyPart}
+ * and {@link Body} objects contained in a MIME body.
+ * 
+ * @version $Id$
+ */
+public interface EntityVisitor {
+
+    /**
+     * Visits a {@link Message}.
+     * 
+     * @param message visited message.
+     */
+    void visitMessage(Message message);
+
+    /**
+     * Visits a {@link Multipart}.
+     * 
+     * @param multipart visited multipart.
+     */
+    void visitMultipart(Multipart multipart);
+
+    /**
+     * Visits a {@link BodyPart}.
+     * 
+     * @param bodyPart visited body part.
+     */
+    void visitBodyPart(BodyPart bodyPart);
+
+    /**
+     * Visits a {@link Body} that is neither a {@link Message} nor a
+     * {@link Multipart}.
+     * 
+     * @param body visited body.
+     */
+    void visitBody(Body body);
+
+}

Property changes on: src/main/java/org/apache/james/mime4j/message/EntityVisitor.java
___________________________________________________________________
Name: svn:eol-style
   + native

Index: src/main/java/org/apache/james/mime4j/message/Body.java
===================================================================
--- src/main/java/org/apache/james/mime4j/message/Body.java	(revision 703203)
+++ src/main/java/org/apache/james/mime4j/message/Body.java	(working copy)
@@ -31,7 +31,7 @@
  * 
  * @version $Id: Body.java,v 1.4 2004/10/04 15:36:43 ntherning Exp $
  */
-public interface Body extends Disposable {
+public interface Body {
 
     /**
      * Gets the parent of this body.
@@ -48,6 +48,14 @@
     void setParent(Entity parent);
     
     /**
+     * Accepts a visitor for {@link Message}, {@link Multipart}, {@link BodyPart}
+     * and {@link Body} objects contained in this MIME body.
+     * 
+     * @param visitor visitor to accept.
+     */
+    void accept(EntityVisitor visitor);
+    
+    /**
      * Writes this body to the given stream in MIME message format.
      * 
      * @param out the stream to write to.
