Author: bago
Date: Sat Dec 30 18:51:49 2006
New Revision: 491368

URL: http://svn.apache.org/viewvc?view=rev&rev=491368
Log:
Changed DataCmdHandler to be push based.
Added a TODO file for in-progress stuff.

Added:
    james/server/sandbox/handlerapi-experiment/TODO
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java
   (with props)
Modified:
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/HandlersPackage.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
    
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java

Added: james/server/sandbox/handlerapi-experiment/TODO
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/TODO?view=auto&rev=491368
==============================================================================
--- james/server/sandbox/handlerapi-experiment/TODO (added)
+++ james/server/sandbox/handlerapi-experiment/TODO Sat Dec 30 18:51:49 2006
@@ -0,0 +1,3 @@
+- Enable From/Sender and Date checks on message received
+- Find a way to handle the old JunkHandlerScore stuff
+- Check DataCmdHandler for correct clean-up on every exceptions

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/core/MimeMessageInputStreamSource.java?view=diff&rev=491368&r1=491367&r2=491368
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/core/MimeMessageInputStreamSource.java
 Sat Dec 30 18:51:49 2006
@@ -26,6 +26,7 @@
 
 import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -57,6 +58,21 @@
      */
     String sourceId;
 
+    public MimeMessageInputStreamSource(String key) throws MessagingException {
+        try {
+            file = File.createTempFile(key, ".m64");
+            sourceId = file.getCanonicalPath();
+        } catch (IOException e) {
+            throw new MessagingException("Unable to get canonical file path: " 
+ e.getMessage(), e);
+        } finally {
+            // if sourceId is null while file is not null then we had
+            // an IOxception and we have to clean the file.
+            if (sourceId == null && file != null) {
+                file.delete();
+            }
+        }
+    }
+    
     /**
      * Construct a new MimeMessageInputStreamSource from an
      * <code>InputStream</code> that contains the bytes of a
@@ -72,17 +88,16 @@
             throws MessagingException {
         //We want to immediately read this into a temporary file
         //Create a temp file and channel the input stream into it
+        this(key);
         OutputStream fout = null;
         try {
-            file = File.createTempFile(key, ".m64");
-            fout = new BufferedOutputStream(new FileOutputStream(file));
+            fout = new BufferedOutputStream(getWritableOutputStream());
             int b = -1;
             while ((b = in.read()) != -1) {
                 fout.write(b);
             }
             fout.flush();
 
-            sourceId = file.getCanonicalPath();
         } catch (IOException ioe) {
             throw new MessagingException("Unable to retrieve the data: " + 
ioe.getMessage(), ioe);
         } finally {
@@ -101,13 +116,15 @@
             } catch (IOException ioe) {
                 // Ignored - logging unavailable to log this non-fatal error.
             }
-            
-            // if sourceId is null while file is not null then we had
-            // an IOxception and we have to clean the file.
-            if (sourceId == null && file != null) {
-                file.delete();
-            }
         }
+    }
+
+    /**
+     * @return
+     * @throws FileNotFoundException
+     */
+    public OutputStream getWritableOutputStream() throws FileNotFoundException 
{
+        return new FileOutputStream(file);
     }
 
     /**

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/HandlersPackage.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/HandlersPackage.java?view=diff&rev=491368&r1=491367&r2=491368
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/HandlersPackage.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/HandlersPackage.java
 Sat Dec 30 18:51:49 2006
@@ -23,6 +23,11 @@
 
 import java.util.List;
 
+/**
+ * Provides a mean to bundle a set of handlers (defined by their classnames) 
within
+ * a single object.
+ * This is used for the default set of CoreCommands.
+ */
 public interface HandlersPackage {
     
     /**

Added: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java?view=auto&rev=491368
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java
 (added)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java
 Sat Dec 30 18:51:49 2006
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/** 
+  * Wraps an underlying input stream, limiting the allowable size
+  * of incoming data. The size limit is configured in the conf file,
+  * and when the limit is reached, a MessageSizeException is thrown.
+  */
+public class SizeLimitedOutputStream extends FilterOutputStream {
+    /**
+     * Maximum number of bytes to read.
+     */
+    private long maxmessagesize = 0;
+    /**
+     * Running total of bytes written to the wrapped stream.
+     */
+    private long byteswritten = 0;
+
+    /**
+     * Constructor for the stream. Wraps an underlying stream.
+     * @param in InputStream to use as basis for new Stream.
+     * @param maxmessagesize Message size limit, in Kilobytes
+     */
+    public SizeLimitedOutputStream(OutputStream out, long maxmessagesize) {
+        super(out);
+        this.maxmessagesize = maxmessagesize;
+    }
+
+    /**
+     * @see java.io.FilterOutputStream#write(byte[], int, int)
+     */
+    public void write(byte[] b, int off, int len) throws IOException {
+        byteswritten+=len;
+        if (maxmessagesize > 0 && byteswritten > maxmessagesize) {
+            throw new MessageSizeException();
+        }
+        out.write(b, off, len);
+    }
+
+    /**
+     * @see java.io.FilterOutputStream#write(int)
+     */
+    public void write(int b) throws IOException {
+        byteswritten++;
+        if (maxmessagesize > 0 && byteswritten > maxmessagesize) {
+            throw new MessageSizeException();
+        }
+        out.write(b);
+    }
+
+}

Propchange: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SizeLimitedOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java?view=diff&rev=491368&r1=491367&r2=491368
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
 Sat Dec 30 18:51:49 2006
@@ -26,18 +26,17 @@
 import org.apache.james.Constants;
 import org.apache.james.core.MailHeaders;
 import org.apache.james.core.MailImpl;
-import org.apache.james.fetchmail.ReaderInputStream;
+import org.apache.james.core.MimeMessageCopyOnWriteProxy;
+import org.apache.james.core.MimeMessageInputStreamSource;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.ExtensibleHandler;
 import org.apache.james.smtpserver.LineHandler;
 import org.apache.james.smtpserver.MessageSizeException;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.smtpserver.SizeLimitedInputStream;
+import org.apache.james.smtpserver.SizeLimitedOutputStream;
 import org.apache.james.smtpserver.WiringException;
 import org.apache.james.smtpserver.hook.MessageHook;
-import org.apache.james.util.CharTerminatedInputStream;
-import org.apache.james.util.DotStuffingInputStream;
 import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.Mail;
@@ -47,14 +46,9 @@
 
 import javax.mail.MessagingException;
 
-import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.SequenceInputStream;
-import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
@@ -123,155 +117,132 @@
      * @param argument the argument passed in with the command by the SMTP 
client
      */
     private SMTPResponse doDATA(SMTPSession session, String argument) {
-        PipedInputStream messageIn = new PipedInputStream();
-        Thread t = new Thread() {
-            private PipedInputStream in;
-            private SMTPSession session;
-
-            public void run() {
-                handleStream(session, in);
+        long maxMessageSize = 
session.getConfigurationData().getMaxMessageSize();
+        if (maxMessageSize > 0) {
+            if (getLogger().isDebugEnabled()) {
+                StringBuffer logBuffer = new StringBuffer(128).append(
+                        "Using SizeLimitedInputStream ").append(
+                        " with max message size: ").append(maxMessageSize);
+                getLogger().debug(logBuffer.toString());
             }
+        }
 
-            public Thread setParam(SMTPSession session, PipedInputStream in) {
-                this.in = in;
-                this.session = session;
-                return this;
-            }
-        }.setParam(session, messageIn);
-        
-        t.start();
-        
-        OutputStream out;
         try {
-            out = new PipedOutputStream(messageIn);
+            MimeMessageInputStreamSource mmiss = new 
MimeMessageInputStreamSource(session.getConfigurationData().getMailServer().getId());
+            OutputStream out = mmiss.getWritableOutputStream();
+
+            // Prepend output headers with out Received
+            MailHeaders mh = createNewReceivedMailHeaders(session);
+            for (Enumeration en = mh.getAllHeaderLines(); 
en.hasMoreElements(); ) {
+                out.write(en.nextElement().toString().getBytes());
+                out.write("\r\n".getBytes());
+            }
+            
+            if (maxMessageSize > 0) {
+                out = new SizeLimitedOutputStream(out, maxMessageSize);
+            }
+            
+            // out = new PipedOutputStream(messageIn);
             session.pushLineHandler(new LineHandler() {
 
                 private OutputStream out;
-                private Thread worker;
+                private MimeMessageInputStreamSource mmiss;
 
                 public void onLine(SMTPSession session, byte[] line) {
                     try {
-                        out.write(line);
-                        out.flush();
                         // 46 is "."
+                        // Stream terminated
                         if (line.length == 3 && line[0] == 46) {
+                            out.flush();
+                            out.close();
+                            
+                            List recipientCollection = (List) 
session.getState().get(SMTPSession.RCPT_LIST);
+                            MailImpl mail =
+                                new 
MailImpl(session.getConfigurationData().getMailServer().getId(),
+                                             (MailAddress) 
session.getState().get(SMTPSession.SENDER),
+                                             recipientCollection);
+                            MimeMessageCopyOnWriteProxy 
mimeMessageCopyOnWriteProxy = null;
                             try {
-                                worker.join();
-                            } catch (InterruptedException e) {
+                                mimeMessageCopyOnWriteProxy = new 
MimeMessageCopyOnWriteProxy(mmiss);
+                                mail.setMessage(mimeMessageCopyOnWriteProxy);
+                                
+                                mailPostProcessor(session, mail);
+                                
+                                processExtensions(session);
+                                
+                                session.popLineHandler();
+                                
+                            } catch (MessagingException e) {
                                 // TODO Auto-generated catch block
                                 e.printStackTrace();
+                            } finally {
+                                
ContainerUtil.dispose(mimeMessageCopyOnWriteProxy);
+                                ContainerUtil.dispose(mmiss);
                             }
+                            
+                        // DotStuffing.
+                        } else if (line[0] == 46 && line[1] == 46) {
+                            out.write(line,1,line.length-1);
+                        // Standard write
+                        } else {
+                            out.write(line);
                         }
-                        
-                        // Handle MessageHandlers
-                        processExtensions(session);
-                        
+                        out.flush();
                     } catch (IOException e) {
-                        // TODO Define what we have to do here!
-                        e.printStackTrace();
+                        SMTPResponse response;
+                        if (e != null && e instanceof MessageSizeException) {
+                            // Add an item to the state to suppress
+                            // logging of extra lines of data
+                            // that are sent after the size limit has
+                            // been hit.
+                            session.getState().put(SMTPSession.MESG_FAILED, 
Boolean.TRUE);
+                            // then let the client know that the size
+                            // limit has been hit.
+                            response = new 
SMTPResponse(SMTPRetCode.QUOTA_EXCEEDED,DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                            DSNStatus.SYSTEM_MSG_TOO_BIG) + " 
Error processing message: " + e.getMessage());
+                          
+                            StringBuffer errorBuffer = new 
StringBuffer(256).append(
+                                    "Rejected message from ").append(
+                                    
session.getState().get(SMTPSession.SENDER).toString())
+                                    .append(" from host 
").append(session.getRemoteHost())
+                                    .append(" 
(").append(session.getRemoteIPAddress())
+                                    .append(") exceeding system maximum 
message size of ")
+                                    .append(
+                                            session.getConfigurationData()
+                                                    .getMaxMessageSize());
+                            getLogger().error(errorBuffer.toString());
+                        } else {
+                            response = new 
SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
+                                            DSNStatus.UNDEFINED_STATUS) + " 
Error processing message: " + e.getMessage());
+                            
+                            getLogger().error(
+                                    "Unknown error occurred while processing 
DATA.", e);
+                        }
+                        session.popLineHandler();
+                        session.writeSMTPResponse(response);
+                        return;
                     }
                 }
 
-                public LineHandler setParam(OutputStream out, Thread t) {
+                public LineHandler setParam(MimeMessageInputStreamSource 
mmiss, OutputStream out) throws MessagingException, FileNotFoundException {
+                    this.mmiss = mmiss;
                     this.out = out;
-                    this.worker = t;
                     return this;
                 };
             
-            }.setParam(out,t));
+            }.setParam(mmiss, out));
+            
         } catch (IOException e1) {
             // TODO Define what to do.
             e1.printStackTrace();
+        } catch (MessagingException e1) {
+            e1.printStackTrace();
         }
         
         return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending 
with <CRLF>.<CRLF>");
     }
     
 
-    public void handleStream(SMTPSession session, InputStream stream) {
-        SMTPResponse response = null;
-        InputStream msgIn = new CharTerminatedInputStream(stream, 
SMTPTerminator);
-        try {
-            // 2006/12/24 - We can remove this now that every single line is 
pushed and
-            // reset the watchdog already in the handler.
-            // This means we don't use resetLength anymore and we can remove
-            // watchdog from the SMTPSession interface
-            // msgIn = new BytesReadResetInputStream(msgIn, 
session.getWatchdog(),
-            //         session.getConfigurationData().getResetLength());
-
-            // if the message size limit has been set, we'll
-            // wrap msgIn with a SizeLimitedInputStream
-            long maxMessageSize = session.getConfigurationData()
-                    .getMaxMessageSize();
-            if (maxMessageSize > 0) {
-                if (getLogger().isDebugEnabled()) {
-                    StringBuffer logBuffer = new StringBuffer(128).append(
-                            "Using SizeLimitedInputStream ").append(
-                            " with max message size: ").append(maxMessageSize);
-                    getLogger().debug(logBuffer.toString());
-                }
-                msgIn = new SizeLimitedInputStream(msgIn, maxMessageSize);
-            }
-            // Removes the dot stuffing
-            msgIn = new DotStuffingInputStream(msgIn);
-            // Parse out the message headers
-            MailHeaders headers = new MailHeaders(msgIn);
-            headers = processMailHeaders(session, headers);
-            processMail(session, headers, msgIn);
-            headers = null;
-        } catch (MessagingException me) {
-            // Grab any exception attached to this one.
-            Exception e = me.getNextException();
-            // If there was an attached exception, and it's a
-            // MessageSizeException
-            if (e != null && e instanceof MessageSizeException) {
-                // Add an item to the state to suppress
-                // logging of extra lines of data
-                // that are sent after the size limit has
-                // been hit.
-                session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
-                // then let the client know that the size
-                // limit has been hit.
-                response = new 
SMTPResponse(SMTPRetCode.QUOTA_EXCEEDED,DSNStatus.getStatus(DSNStatus.PERMANENT,
-                                DSNStatus.SYSTEM_MSG_TOO_BIG) + " Error 
processing message: " + e.getMessage());
-              
-                StringBuffer errorBuffer = new StringBuffer(256).append(
-                        "Rejected message from ").append(
-                        session.getState().get(SMTPSession.SENDER).toString())
-                        .append(" from host ").append(session.getRemoteHost())
-                        .append(" (").append(session.getRemoteIPAddress())
-                        .append(") exceeding system maximum message size of ")
-                        .append(
-                                session.getConfigurationData()
-                                        .getMaxMessageSize());
-                getLogger().error(errorBuffer.toString());
-            } else {
-                response = new 
SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
-                                DSNStatus.UNDEFINED_STATUS) + " Error 
processing message: " + me.getMessage());
-                
-                getLogger().error(
-                        "Unknown error occurred while processing DATA.", me);
-            }
-            session.popLineHandler();
-            session.writeSMTPResponse(response);
-            return;
-        } finally {
-            if (msgIn != null) {
-                try {
-                    msgIn.close();
-                } catch (Exception e) {
-                    // Ignore close exception
-                }
-                msgIn = null;
-            }
-        }
-
-    }
-
-
-
-
-
 
 
     private MailHeaders processMailHeaders(SMTPSession session, MailHeaders 
headers)
@@ -289,9 +260,26 @@
         // Received: header may precede it, but the Return-Path header
         // should be removed when making final delivery.
      // headers.removeHeader(RFC2822Headers.RETURN_PATH);
-        StringBuffer headerLineBuffer = new StringBuffer(512);
         // We will rebuild the header object to put our Received header at the 
top
         Enumeration headerLines = headers.getAllHeaderLines();
+        MailHeaders newHeaders = createNewReceivedMailHeaders(session);
+
+        // Add all the original message headers back in next
+        while (headerLines.hasMoreElements()) {
+            newHeaders.addHeaderLine((String) headerLines.nextElement());
+        }
+        return newHeaders;
+    }
+
+
+    /**
+     * @param session
+     * @param headerLineBuffer
+     * @return
+     * @throws MessagingException
+     */
+    private MailHeaders createNewReceivedMailHeaders(SMTPSession session) 
throws MessagingException {
+        StringBuffer headerLineBuffer = new StringBuffer(512);
         MailHeaders newHeaders = new MailHeaders();
         
         String heloMode = (String) 
session.getConnectionState().get(SMTPSession.CURRENT_HELO_MODE);
@@ -351,86 +339,26 @@
         }
         headerLineBuffer = null;
         newHeaders.addHeaderLine("          " + rfc822DateFormat.format(new 
Date()));
-
-        // Add all the original message headers back in next
-        while (headerLines.hasMoreElements()) {
-            newHeaders.addHeaderLine((String) headerLines.nextElement());
-        }
         return newHeaders;
     }
 
+
     /**
-     * Processes the mail message coming in off the wire.  Reads the
-     * content and delivers to the spool.
-     *
-     * @param session SMTP session object
-     * @param headers the headers of the mail being read
-     * @param msgIn the stream containing the message content
+     * @param session
+     * @param mail
      */
-    private void processMail(SMTPSession session, MailHeaders headers, 
InputStream msgIn)
-        throws MessagingException {
-        ByteArrayInputStream headersIn = null;
-        MailImpl mail = null;
-        List recipientCollection = null;
-        try {
-            headersIn = new ByteArrayInputStream(headers.toByteArray());
-            recipientCollection = (List) 
session.getState().get(SMTPSession.RCPT_LIST);
-            mail =
-                new 
MailImpl(session.getConfigurationData().getMailServer().getId(),
-                             (MailAddress) 
session.getState().get(SMTPSession.SENDER),
-                             recipientCollection,
-                             new SequenceInputStream(new 
SequenceInputStream(headersIn, msgIn),
-                                     new ReaderInputStream(new 
StringReader("\r\n"))));
-            // Call mail.getSize() to force the message to be
-            // loaded. Need to do this to enforce the size limit
-            if (session.getConfigurationData().getMaxMessageSize() > 0) {
-                mail.getMessageSize();
-            }
-            mail.setRemoteHost(session.getRemoteHost());
-            mail.setRemoteAddr(session.getRemoteIPAddress());
-            if (session.getUser() != null) {
-                mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, 
session.getUser());
-            }
-            
-            if (session.isRelayingAllowed()) {
-                mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
-            }
-            
-            session.popLineHandler();
-            
-            session.getState().put(LAST_MAIL_KEY, mail);
-        } catch (MessagingException me) {
-            // if we get here, it means that we received a
-            // MessagingException, which would happen BEFORE we call
-            // session.setMail, so the mail object is still strictly
-            // local to us, and we really should clean it up before
-            // re-throwing the MessagingException for our call chain
-            // to process.
-            //
-            // So why has this worked at all so far?  Initial
-            // conjecture is that it has depended upon finalize to
-            // call dispose.  Not in the MailImpl, which doesn't have
-            // one, but even further down in the MimeMessageInputStreamSource.
-
-            if (mail != null) {
-                mail.dispose();
-            }
-            throw me;
-        } finally {
-            if (recipientCollection != null) {
-                recipientCollection.clear();
-            }
-            recipientCollection = null;
-            if (headersIn != null) {
-                try {
-                    headersIn.close();
-                } catch (IOException ioe) {
-                    // Ignore exception on close.
-                }
-            }
-            headersIn = null;
+    private void mailPostProcessor(SMTPSession session, MailImpl mail) {
+        mail.setRemoteHost(session.getRemoteHost());
+        mail.setRemoteAddr(session.getRemoteIPAddress());
+        if (session.getUser() != null) {
+            mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, 
session.getUser());
         }
-
+        
+        if (session.isRelayingAllowed()) {
+            mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
+        }
+        
+        session.getState().put(LAST_MAIL_KEY, mail);
     }
     
     /**

Modified: 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java?view=diff&rev=491368&r1=491367&r2=491368
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SMTPServerTest.java
 Sat Dec 30 18:51:49 2006
@@ -281,7 +281,7 @@
 
         int size = ((MimeMessage) 
m_mailServer.getLastMail().getMessage()).getSize();
 
-        assertEquals(size, 2);
+        assertEquals(2, size);
     }
 
     public void testSimpleMailSendWithHELO() throws Exception {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to