
Property changes on: C:\Lab\VOID\projects\james-2.3
___________________________________________________________________
Name: svn:ignore
   + 
build
dist
target


Index: C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/core/MailImplTest.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/core/MailImplTest.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/core/MailImplTest.java	(working copy)
@@ -65,7 +65,7 @@
         String sender = "sender@localhost";
         MailAddress senderMailAddress = new MailAddress(sender);
         MockMimeMessage mimeMessage = new MockMimeMessage();
-        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
+        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage, true);
 
         helperTestInitialState(mail); 
         helperTestMessageSize(mail, 0);
Index: C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/pop3server/POP3ServerTest.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/pop3server/POP3ServerTest.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/pop3server/POP3ServerTest.java	(working copy)
@@ -235,7 +235,7 @@
                                  "Subject: test\r\n\r\n"+
                                  "Body Text\r\n").getBytes())));
         MailImpl m = new MailImpl("name", new MailAddress("from@test.com"),
-                recipients, mw);
+                recipients, mw, true);
         mailRep.store(m);
         MimeMessage mw2 = new MimeMessageCopyOnWriteProxy(
                 new MimeMessageInputStreamSource(
@@ -243,7 +243,7 @@
                         new SharedByteArrayInputStream(
                                 ("").getBytes())));
         MailImpl mailimpl2 = new MailImpl("name2", new MailAddress("from@test.com"),
-                        recipients, mw2);
+                        recipients, mw2, true);
         mailRep.store(mailimpl2);
         m.dispose();
         mailimpl2.dispose();
Index: C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/smtpserver/SMTPServerTest.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/smtpserver/SMTPServerTest.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/smtpserver/SMTPServerTest.java	(working copy)
@@ -928,7 +928,7 @@
         String sender = "test@localhost";
         String recipient = "test@localhost";
         MimeMessage mm = new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
-        MailImpl mail = new MailImpl("name",new MailAddress(sender),Arrays.asList(new MailAddress[] {new MailAddress(recipient)}),mm);
+        MailImpl mail = new MailImpl("name",new MailAddress(sender),Arrays.asList(new MailAddress[] {new MailAddress(recipient)}),mm, true);
         
         rd.service(mail);
         
@@ -972,7 +972,7 @@
         String sender = "test@localhost";
         String recipient = "test@localhost";
         MimeMessage mm = new MimeMessage(Session.getDefaultInstance(new Properties()),new ByteArrayInputStream(sources.getBytes()));
-        MailImpl mail = new MailImpl("name",new MailAddress(sender),Arrays.asList(new MailAddress[] {new MailAddress(recipient)}),mm);
+        MailImpl mail = new MailImpl("name",new MailAddress(sender),Arrays.asList(new MailAddress[] {new MailAddress(recipient)}),mm,true);
         
         rd.service(mail);
         
Index: C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/transport/LinearProcessorTest.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/transport/LinearProcessorTest.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/test/org/apache/james/transport/LinearProcessorTest.java	(working copy)
@@ -16,6 +16,7 @@
  ***********************************************************************/
 package org.apache.james.transport;
 
+import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.logger.ConsoleLogger;
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.james.core.MailImpl;
@@ -97,18 +98,6 @@
         }
     }
 
-    public LinearProcessorTest(String arg0) throws Exception {
-        super(arg0);
-
-        MimeMessageInputStreamSource mmis = null;
-        try {
-            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content+sep+body).getBytes()));
-        } catch (MessagingException e) {
-        }
-        mw = new MimeMessageCopyOnWriteProxy(mmis);
-        setUp();
-  }
-
     private class DummyMatcherConfig implements MatcherConfig {
         private String condition;
 
@@ -217,15 +206,22 @@
 
     public void setUp() throws Exception {
         super.setUp();
+        MimeMessageInputStreamSource mmis = null;
+        try {
+            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream((content+sep+body).getBytes()));
+        } catch (MessagingException e) {
+        }
+        mw = new MimeMessageCopyOnWriteProxy(mmis);
+        
         t = new LinearProcessor();
         Logger l = new ConsoleLogger();
         t.enableLogging(l);
         t.initialize();
-        
     }
     
     public void tearDown() throws Exception {
         t.dispose();
+        ContainerUtil.dispose(mw);
         super.tearDown();
     }
     
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/James.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/James.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/James.java	(working copy)
@@ -713,7 +713,7 @@
             "replyTo-" + mail.getName(),
             new MailAddress(mail.getRecipients().iterator().next().toString()),
             recipients,
-            reply);
+            reply, true);
     }
 
     /**
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MimeMessageCopyOnWriteProxy.java	(working copy)
@@ -111,13 +111,13 @@
     }
 
     /**
-     * Private constructor providing an external reference counter.
+     * constructor providing an external reference counter.
      * 
      * @param original
      * @param refCount
      * @throws MessagingException
      */
-    private MimeMessageCopyOnWriteProxy(MimeMessage original,
+    public MimeMessageCopyOnWriteProxy(MimeMessage original,
             boolean writeable)
             throws MessagingException {
         super(Session.getDefaultInstance(System.getProperties(), null));
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MailImpl.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MailImpl.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/core/MailImpl.java	(working copy)
@@ -137,10 +137,12 @@
     /**
      * @param mail
      * @param newName
+     * @param message the new message
+     * @param writable true when the passed message can be changed 
      * @throws MessagingException
      */
-    public MailImpl(Mail mail, String newName) throws MessagingException {
-        this(newName, mail.getSender(), mail.getRecipients(), mail.getMessage());
+    public MailImpl(Mail mail, String newName, MimeMessage message, boolean writable) throws MessagingException {
+        this(newName, mail.getSender(), mail.getRecipients(), message, writable);
         setRemoteHost(mail.getRemoteHost());
         setRemoteAddr(mail.getRemoteAddr());
         setLastUpdated(mail.getLastUpdated());
@@ -165,6 +167,15 @@
     }
 
     /**
+     * @param mail
+     * @param newName
+     * @throws MessagingException
+     */
+    public MailImpl(Mail originalMail, String string) throws MessagingException {
+        this(originalMail, string, originalMail.getMessage(), false);
+		}
+
+    /**
      * A constructor that creates a MailImpl with the specified name,
      * sender, recipients, and message data.
      *
@@ -190,8 +201,21 @@
      * @param message the MimeMessage associated with this MailImpl
      */
     public MailImpl(String name, MailAddress sender, Collection recipients, MimeMessage message) throws MessagingException {
+        this(name, sender, recipients, message, false);
+    }
+
+    /**
+     * A constructor that creates a MailImpl with the specified name,
+     * sender, recipients, and MimeMessage.
+     *
+     * @param name the name of the MailImpl
+     * @param sender the sender for this MailImpl
+     * @param recipients the collection of recipients of this MailImpl
+     * @param message the MimeMessage associated with this MailImpl
+     */
+    public MailImpl(String name, MailAddress sender, Collection recipients, MimeMessage message, boolean writable) throws MessagingException {
         this(name, sender, recipients);
-        this.setMessage(new MimeMessageCopyOnWriteProxy(message));
+        this.setMessage(new MimeMessageCopyOnWriteProxy(message, writable));
     }
 
     /**
@@ -222,8 +246,9 @@
         this.name = message.toString();
         this.sender = sender;
         this.recipients = recipients;
-        this.setMessage(message);
+        this.setMessage(new MimeMessageCopyOnWriteProxy(message, true));
     }
+
     /**
      * Gets the MailAddress corresponding to the existing "Return-Path" of
      * <I>message</I>.
@@ -384,12 +409,18 @@
      * @param message the new MimeMessage associated with this MailImpl
      */
     public void setMessage(MimeMessage message) {
+        // we switched back the source because this changed the previous
+        // behaviour and introduced possible NPEs later.
+        // callers of this method must ensure that the old message is correctly
+        // disposed.
+        //
+        // OLD COMMENT AND CODE:
         // If a setMessage is called on a Mail that already have a message
         // (discouraged) we have to make sure that the message we remove is
         // correctly unreferenced and disposed, otherwise it will keep locks
-        if (this.message != null) {
-            ContainerUtil.dispose(this.message);
-        }
+        // if (this.message != null) {
+        //     ContainerUtil.dispose(this.message);
+        // }
         this.message = message;
     }
     /**
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/fetchmail/MessageProcessor.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/fetchmail/MessageProcessor.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/fetchmail/MessageProcessor.java	(working copy)
@@ -619,7 +619,7 @@
         Collection recipients = new ArrayList(1);
         recipients.add(recipient);
         MailImpl mail =
-            new MailImpl(getServer().getId(), getSender(), recipients, message);
+            new MailImpl(getServer().getId(), getSender(), recipients, message, true);
         // Ensure the mail is created with non-null remote host name and address,
         // otherwise the Mailet chain may go splat!
         if (getRemoteAddress() == null || getRemoteHostName() == null)
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/DSNBounce.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/DSNBounce.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/DSNBounce.java	(working copy)
@@ -146,7 +146,8 @@
 
 
         // duplicates the Mail object, to be able to modify the new mail keeping the original untouched
-        MailImpl newMail = new MailImpl(originalMail,newName(originalMail));
+        MailImpl newMail = new MailImpl(originalMail,newName(originalMail),new MimeMessage(Session.getDefaultInstance(System.getProperties(),
+            null)), true);
         try {
             // We don't need to use the original Remote Address and Host,
             // and doing so would likely cause a loop with spam detecting
@@ -188,10 +189,8 @@
                     + ", errorMessage: " + newMail.getErrorMessage());
             }
     
-            // create the bounce message
-            MimeMessage newMessage =
-                new MimeMessage(Session.getDefaultInstance(System.getProperties(),
-                                                           null));
+            // get the empty bounce message
+            MimeMessage newMessage = newMail.getMessage();
     
             MimeMultipartReport multipart = new MimeMultipartReport ();
             multipart.setReportType ("delivery-status");
@@ -215,7 +214,8 @@
             // stuffing all together
             newMessage.setContent(multipart);
             newMessage.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
-            newMail.setMessage(newMessage);
+            // we already have it by reference
+            // newMail.setMessage(newMessage);
     
             //Set additional headers
             setRecipients(newMail, getRecipients(originalMail), originalMail);
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java	(working copy)
@@ -17,6 +17,7 @@
 
 package org.apache.james.transport.mailets.smime;
 
+import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.security.KeyHolder;
 import org.apache.james.security.SMIMEAttributeNames;
 import org.apache.mailet.GenericMailet;
@@ -461,6 +462,8 @@
             }
             
             mail.setMessage(newMessage);
+            // make sure we dispose the previous message
+            ContainerUtil.dispose(originalMessage);
             
             // marks this mail as server-signed
             mail.setAttribute(SMIMEAttributeNames.SMIME_SIGNING_MAILET, this.getClass().getName());
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEDecrypt.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEDecrypt.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMEDecrypt.java	(working copy)
@@ -139,17 +139,19 @@
 
             // I start the message stripping.
             try {
-                MimeMessage newmex = new MimeMessage(message);
+                // We don't need to clone the original message
+                // MimeMessage newmex = new MimeMessage(message);
                 Object obj = strippedMessage.getContent();
                 if (obj instanceof Multipart) {
                     log("The message is multipart, content type "+((Multipart)obj).getContentType());
-                    newmex.setContent((Multipart)obj);
+                    message.setContent((Multipart)obj);
                 } else {
-                    newmex.setContent(obj, strippedMessage.getContentType());
-                    newmex.setDisposition(null);
+                    message.setContent(obj, strippedMessage.getContentType());
+                    message.setDisposition(null);
                 }
-                newmex.saveChanges();
-                mail.setMessage(newmex);
+                message.saveChanges();
+                // we change the message as we have its reference.
+                // mail.setMessage(newmex);
             } catch (IOException e) { 
                 log("Error during the strip of the encrypted message");
                 throw new MessagingException("Error during the stripping of the encrypted message",e);
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMECheckSignature.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMECheckSignature.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/smime/SMIMECheckSignature.java	(working copy)
@@ -215,7 +215,9 @@
                     message.setContent(obj, strippedMessage.getContentType());
                 }
                 message.saveChanges();
-                mail.setMessage(message);
+                // We didn't change the message reference so we should not call 
+                // set for it, again.
+                // mail.setMessage(message);
             } catch (Exception e) {
                 throw new MessagingException(
                         "Error during the extraction of the signed content from the message.",
Index: C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
===================================================================
--- C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/AbstractRedirect.java	(revision 434375)
+++ C:/Lab/VOID/projects/james-2.3/src/java/org/apache/james/transport/mailets/AbstractRedirect.java	(working copy)
@@ -973,7 +973,13 @@
         boolean keepMessageId = false;
 
         // duplicates the Mail object, to be able to modify the new mail keeping the original untouched
-        MailImpl newMail = new MailImpl(originalMail,newName(originalMail));
+        MailImpl newMail;
+        if (getInLineType(originalMail) != UNALTERED) {
+            newMail = new MailImpl(originalMail,newName(originalMail),new MimeMessage(Session.getDefaultInstance(System.getProperties(),
+            null)), true);
+        } else {
+            newMail = new MailImpl(originalMail,newName(originalMail));
+        }
         try {
             // We don't need to use the original Remote Address and Host,
             // and doing so would likely cause a loop with spam detecting
@@ -1002,24 +1008,24 @@
                 if (isDebug) {
                     log("Alter message");
                 }
-                newMail.setMessage(new MimeMessage(Session.getDefaultInstance(System.getProperties(),
-                                                                   null)));
     
                 // handle the new message if altered
                 buildAlteredMessage(newMail, originalMail);
     
             } else {
+                // This is handled by the copy on write proxy
+                // OLD COMMENT:
                 // if we need the original, create a copy of this message to redirect
-                if (getPassThrough(originalMail)) {
-                    newMail.setMessage(new MimeMessage(originalMail.getMessage()) {
-                        protected void updateHeaders() throws MessagingException {
-                            if (getMessageID() == null) super.updateHeaders();
-                            else {
-                                modified = false;
-                            }
-                        }
-                    });
-                }
+                //if (getPassThrough(originalMail)) {
+                //    newMail.setMessage(new MimeMessage(originalMail.getMessage()) {
+                //        protected void updateHeaders() throws MessagingException {
+                //            if (getMessageID() == null) super.updateHeaders();
+                //            else {
+                //                modified = false;
+                //            }
+                //        }
+                //    });
+                //}
                 if (isDebug) {
                     log("Message resent unaltered.");
                 }
