You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/08/14 16:57:02 UTC

svn commit: r804246 [1/3] - in /james/server/sandbox/active/smtp_refactor: avalon-socket-library/src/main/java/org/apache/james/socket/ core-library/src/main/java/org/apache/james/core/ smtpserver-function/src/main/java/org/apache/james/smtpserver/ smt...

Author: norman
Date: Fri Aug 14 14:57:00 2009
New Revision: 804246

URL: http://svn.apache.org/viewvc?rev=804246&view=rev
Log:
Fix most of the tests only a few left to fix

Added:
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TLDLookup.java
      - copied, changed from r804099, james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/TLDLookup.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIScanner.java
      - copied, changed from r804099, james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/URIScanner.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/Util.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/MockMimeMessage.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMail.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailContext.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMailetConfig.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/test/mock/mailet/MockMatcherConfig.java
Removed:
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/JunkScoreHandlerTest.java
Modified:
    james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
    james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java
    james/server/sandbox/active/smtp_refactor/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPTestConfiguration.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
    james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java

Modified: james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java (original)
+++ james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java Fri Aug 14 14:57:00 2009
@@ -677,7 +677,7 @@
      */
     protected ConnectionHandler newHandler()
             throws Exception {
-        AbstractJamesHandler theHandler = (AbstractJamesHandler)theHandlerPool.get();
+        DelegatingJamesHandler theHandler = (DelegatingJamesHandler)theHandlerPool.get();
         
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("Handler [" +  theHandler + "] obtained from pool.");
@@ -796,7 +796,7 @@
      * @see org.apache.avalon.excalibur.pool.ObjectFactory#newInstance()
      */
     public Object newInstance() throws Exception {
-        final AbstractJamesHandler delegatingJamesHandler = new DelegatingJamesHandler(newProtocolHandlerInstance());
+        final DelegatingJamesHandler delegatingJamesHandler = new DelegatingJamesHandler(newProtocolHandlerInstance(), dnsServer);
         delegatingJamesHandler.setName("Handler-" + handlerCount.getAndAdd(1));
         return delegatingJamesHandler;
     }

Modified: james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java Fri Aug 14 14:57:00 2009
@@ -19,27 +19,448 @@
 
 package org.apache.james.socket;
 
-import org.apache.avalon.framework.logger.Logger;
-import org.apache.james.util.watchdog.Watchdog;
-
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InterruptedIOException;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.net.Socket;
+import java.net.SocketException;
+
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
+import org.apache.avalon.excalibur.pool.Poolable;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.util.InternetPrintWriter;
+import org.apache.james.util.watchdog.Watchdog;
+import org.apache.james.util.watchdog.WatchdogTarget;
 
 /**
  * Common Handler code
  */
-public class DelegatingJamesHandler extends AbstractJamesHandler implements ProtocolHandlerHelper {
+public class DelegatingJamesHandler extends AbstractLogEnabled implements ProtocolHandlerHelper, ConnectionHandler, Poolable {
+ 
+    private static final int DEFAULT_OUTPUT_BUFFER_SIZE = 1024;
+
+    private static final int DEFAULT_INPUT_BUFFER_SIZE = 1024;
+
+    /** Name used by default */
+    private static final String DEFAULT_NAME = "Handler-ANON";
+
+    /**
+     * The thread executing this handler
+     */
+    private Thread handlerThread;
+
+    /**
+     * The TCP/IP socket over which the service interaction
+     * is occurring
+     */
+    private Socket socket;
+
+    /**
+     * The writer to which outgoing messages are written.
+     */
+    private PrintWriter out;
+    
+    /**
+     * The incoming stream of bytes coming from the socket.
+     */
+    private InputStream in;
+
+    /**
+     * The reader associated with incoming characters.
+     */
+    private CRLFTerminatedReader inReader;
+
+    /**
+     * The socket's output stream
+     */
+    private OutputStream outs;
+    
+    /**
+     * The watchdog being used by this handler to deal with idle timeouts.
+     */
+    private Watchdog theWatchdog;
+
+    /**
+     * The watchdog target that idles out this handler.
+     */
+    private final WatchdogTarget theWatchdogTarget = new JamesWatchdogTarget();
+    
+    /**
+     * The remote host name obtained by lookup on the socket.
+     */
+    private String remoteHost = null;
+
+    /**
+     * The remote IP address of the socket.
+     */
+    private String remoteIP = null;
+
+    /**
+     * Used for debug: if not null enable tcp stream dump.
+     */
+    private String tcplogprefix = null;
+
+    /**
+     * Names the handler.
+     * This name is used for contextual logging.
+     */
+    private String name = DEFAULT_NAME;
+    
 
-    protected ProtocolHandler protocolHandler;
+    /**
+     * The DNSService
+     */
+    private final DNSService dnsServer;
     
+    private final ProtocolHandler protocolHandler;
     
-    public DelegatingJamesHandler(ProtocolHandler delegated) {
+    public DelegatingJamesHandler(final ProtocolHandler delegated, final DNSService dnsServer) {
         this.protocolHandler = delegated;
+        this.dnsServer = dnsServer;
         this.protocolHandler.setProtocolHandlerHelper(this);
     }
+
+    /**
+     * Helper method for accepting connections.
+     * This MUST be called in the specializations.
+     *
+     * @param connection The Socket which belongs to the connection 
+     * @throws IOException get thrown if an IO error is detected
+     */
+    protected void initHandler( Socket connection ) throws IOException {
+        this.socket = connection;
+        remoteIP = socket.getInetAddress().getHostAddress();
+        remoteHost = dnsServer.getHostName(socket.getInetAddress());
+
+        try {
+            synchronized (this) {
+                handlerThread = Thread.currentThread();
+            }
+            in = new BufferedInputStream(socket.getInputStream(), DEFAULT_INPUT_BUFFER_SIZE);
+            outs = new BufferedOutputStream(socket.getOutputStream(), DEFAULT_OUTPUT_BUFFER_SIZE);
+            // enable tcp dump for debug
+            if (tcplogprefix != null) {
+                outs = new SplitOutputStream(outs, new FileOutputStream(tcplogprefix+"out"));
+                in = new CopyInputStream(in, new FileOutputStream(tcplogprefix+"in"));
+            }
+            
+            // An ASCII encoding can be used because all transmissions other
+            // that those in the message body command are guaranteed
+            // to be ASCII
+            inReader = new CRLFTerminatedReader(in, "ASCII");
+            
+            out = new InternetPrintWriter(outs, true);
+        } catch (RuntimeException e) {
+            StringBuffer exceptionBuffer = 
+                new StringBuffer(256)
+                    .append("[" + toString() + "] Unexpected exception opening from ")
+                    .append(remoteHost)
+                    .append(" (")
+                    .append(remoteIP)
+                    .append("): ")
+                    .append(e.getMessage());
+            String exceptionString = exceptionBuffer.toString();
+            getLogger().error(exceptionString, e);
+            throw e;
+        } catch (IOException e) {
+            StringBuffer exceptionBuffer = 
+                new StringBuffer(256)
+                    .append("[" + toString() + "] Cannot open connection from ")
+                    .append(remoteHost)
+                    .append(" (")
+                    .append(remoteIP)
+                    .append("): ")
+                    .append(e.getMessage());
+            String exceptionString = exceptionBuffer.toString();
+            getLogger().error(exceptionString, e);
+            throw e;
+        }
+        
+        if (getLogger().isInfoEnabled()) {
+            StringBuffer infoBuffer =
+                new StringBuffer(128)
+                        .append("[" + toString() + "]Connection from ")
+                        .append(remoteHost)
+                        .append(" (")
+                        .append(remoteIP)
+                        .append(")");
+            getLogger().info(infoBuffer.toString());
+        }
+    }
+
+    /**
+     * The method clean up and close the allocated resources
+     */
+    private void cleanHandler() {
+        // Clear the Watchdog
+        if (theWatchdog != null) {
+            ContainerUtil.dispose(theWatchdog);
+            theWatchdog = null;
+        }
+
+        // Clear the streams
+        try {
+            if (inReader != null) {
+                inReader.close();
+            }
+        } catch (IOException ioe) {
+            getLogger().warn("[" + toString() + "] Unexpected exception occurred while closing reader: " + ioe);
+        } finally {
+            inReader = null;
+        }
+
+        in = null;
+
+        if (out != null) {
+            out.close();
+            out = null;
+        }
+        outs = null;
+
+        try {
+            if (socket != null) {
+                socket.close();
+            }
+        } catch (IOException ioe) {
+            getLogger().warn("[" + toString() + "] Unexpected exception occurred while closing socket: " + ioe);
+        } finally {
+            socket = null;
+        }
+        
+        remoteIP = null;
+        remoteHost = null;
+
+        synchronized (this) {
+            handlerThread = null;
+        }
+    }
+
+    /**
+     * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection(java.net.Socket)
+     */
+    public void handleConnection(Socket connection) throws IOException {
+        initHandler(connection);
+
+        final Logger logger = getLogger();
+        try {
+            
+            // Do something:
+            handleProtocol();
+            
+            logger.debug("[" + toString() + "] Closing socket");
+        } catch (SocketException se) {
+            // Indicates a problem at the underlying protocol level
+            if (logger.isWarnEnabled()) {
+                String message =
+                    new StringBuffer(64)
+                        .append("[" + toString() + "]Socket to ")
+                        .append(remoteHost)
+                        .append(" (")
+                        .append(remoteIP)
+                        .append("): ")
+                        .append(se.getMessage()).toString();
+                logger.warn(message);
+                logger.debug(se.getMessage(), se);
+            }
+        } catch ( InterruptedIOException iioe ) {
+            if (logger.isErrorEnabled()) {
+                StringBuffer errorBuffer =
+                    new StringBuffer(64)
+                        .append("[" + toString() + "] Socket to ")
+                        .append(remoteHost)
+                        .append(" (")
+                        .append(remoteIP)
+                        .append(") timeout.");
+                logger.error( errorBuffer.toString(), iioe );
+            }
+        } catch ( IOException ioe ) {
+            if (logger.isWarnEnabled()) {
+                String message =
+                    new StringBuffer(256)
+                            .append("[" + toString() + "] Exception handling socket to ")
+                            .append(remoteHost)
+                            .append(" (")
+                            .append(remoteIP)
+                            .append(") : ")
+                            .append(ioe.getMessage()).toString();
+                logger.warn(message);
+                logger.debug( ioe.getMessage(), ioe );
+            }
+        } catch (RuntimeException e) {
+            errorHandler(e);
+        } finally {
+            //Clear all the session state variables
+            cleanHandler();
+            resetHandler();
+        }
+    }
+
+    /**
+     * Set the Watchdog for use by this handler.
+     *
+     * @param theWatchdog the watchdog
+     */
+    public void setWatchdog(Watchdog theWatchdog) {
+        this.theWatchdog = theWatchdog;
+    }
+
+    /**
+     * Gets the Watchdog Target that should be used by Watchdogs managing
+     * this connection.
+     *
+     * @return the WatchdogTarget
+     */
+    WatchdogTarget getWatchdogTarget() {
+        return theWatchdogTarget;
+    }
+
+    /**
+     * Idle out this connection
+     */
+    void idleClose() {
+        if (getLogger() != null) {
+            getLogger().error("[" + toString() + "] Service Connection has idled out.");
+        }
+        try {
+            if (socket != null) {
+                socket.close();
+            }
+        } catch (Exception e) {
+            // ignored
+        } finally {
+            socket = null;
+        }
+
+        synchronized (this) {
+            // Interrupt the thread to recover from internal hangs
+            if (handlerThread != null) {
+                handlerThread.interrupt();
+                handlerThread = null;
+            }
+        }
+
+    }
+
+    /**
+     * This method logs at a "DEBUG" level the response string that
+     * was sent to the service client.  The method is provided largely
+     * as syntactic sugar to neaten up the code base.  It is declared
+     * private and final to encourage compiler inlining.
+     *
+     * @param responseString the response string sent to the client
+     */
+    private final void logResponseString(String responseString) {
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("[" + toString() + "] Sent: " + responseString);
+        }
+    }
+
+    /**
+     * Write and flush a response string.  The response is also logged.
+     * Should be used for the last line of a multi-line response or
+     * for a single line response.
+     *
+     * @param responseString the response string sent to the client
+     */
+    public final void writeLoggedFlushedResponse(String responseString) {
+        out.println(responseString);
+        out.flush();
+        logResponseString(responseString);
+    }
+
+    /**
+     * Write a response string.  The response is also logged.
+     * Used for multi-line responses.
+     *
+     * @param responseString the response string sent to the client
+     */
+    public final void writeLoggedResponse(String responseString) {
+        out.println(responseString);
+        logResponseString(responseString);
+    }
+
+    /**
+     * A private inner class which serves as an adaptor
+     * between the WatchdogTarget interface and this
+     * handler class.
+     */
+    private class JamesWatchdogTarget
+        implements WatchdogTarget {
+
+        /**
+         * @see org.apache.james.util.watchdog.WatchdogTarget#execute()
+         */
+        public void execute() {
+            DelegatingJamesHandler.this.idleClose();
+        }
+
+        /**
+         * Used for context sensitive logging
+         */
+        @Override
+        public String toString() {
+            return DelegatingJamesHandler.this.toString();
+        }
+    }
+
+    /**
+     * If not null, this will enable dump to file for tcp connections
+     * 
+     * @param streamDumpDir the dir
+     */
+    public void setStreamDumpDir(String streamDumpDir) {
+        if (streamDumpDir != null) {
+            String streamdumpDir=streamDumpDir;
+            this.tcplogprefix = streamdumpDir+"/" + getName() + "_TCP-DUMP."+System.currentTimeMillis()+".";
+            File logdir = new File(streamdumpDir);
+            if (!logdir.exists()) {
+                logdir.mkdir();
+            }
+        } else {
+            this.tcplogprefix = null;
+        }
+    }
+
+    /**
+     * The name of this handler.
+     * Used for context sensitive logging.
+     * @return the name, not null
+     */
+    public final String getName() {
+        return name;
+    }
+
+    /**
+     * The name of this handler.
+     * Note that this name should be file-system safe.
+     * Used for context sensitive logging.
+     * @param name the name to set
+     */
+    public final void setName(final String name) {
+        if (name == null) {
+            this.name = DEFAULT_NAME;
+        } else {
+            this.name = name;
+        }
+    }
+
+    /**
+     * Use for context sensitive logging.
+     * @return the name of the handler
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
     
     /**
      * This method will be implemented checking for the correct class
@@ -80,7 +501,10 @@
      * @see org.apache.james.socket.ProtocolHandlerHelper#defaultErrorHandler(java.lang.RuntimeException)
      */
     public void defaultErrorHandler(RuntimeException e) {
-        super.errorHandler(e);
+        if (getLogger().isErrorEnabled()) {
+            getLogger().error( "[" + toString() + "] Unexpected runtime exception: "
+                               + e.getMessage(), e );
+        }
     }
     
     /**

Modified: james/server/sandbox/active/smtp_refactor/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java (original)
+++ james/server/sandbox/active/smtp_refactor/core-library/src/main/java/org/apache/james/core/MimeMessageInputStreamSource.java Fri Aug 14 14:57:00 2009
@@ -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;
@@ -110,6 +111,21 @@
         }
     }
 
+    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();
+            }
+        }
+    }
+    
     /**
      * Returns the unique identifier of this input stream source
      *
@@ -140,6 +156,14 @@
     }
 
     /**
+     * @return
+     * @throws FileNotFoundException
+     */
+    public OutputStream getWritableOutputStream() throws FileNotFoundException {
+        return new FileOutputStream(file);
+    }
+    
+    /**
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java Fri Aug 14 14:57:00 2009
@@ -21,10 +21,6 @@
 
 package org.apache.james.smtpserver;
 
-import org.apache.james.core.AbstractJamesHandler;
-import org.apache.james.util.CRLFDelimitedByteBuffer;
-import org.apache.james.util.mail.SMTPRetCode;
-
 import java.io.IOException;
 import java.net.Socket;
 import java.util.Collection;
@@ -33,56 +29,57 @@
 import java.util.Map;
 import java.util.Random;
 
+import org.apache.james.Constants;
+import org.apache.james.socket.AbstractJamesHandler;
+import org.apache.james.socket.ProtocolHandler;
+import org.apache.james.socket.ProtocolHandlerHelper;
+import org.apache.james.util.CRLFDelimitedByteBuffer;
+import org.apache.mailet.base.RFC822DateFormat;
+
 /**
  * Provides SMTP functionality by carrying out the server side of the SMTP
  * interaction.
  *
  * @version CVS $Revision$ $Date$
  */
-public class SMTPHandler
-    extends AbstractJamesHandler
-    implements SMTPSession {
-
-    /**
-     * Static Random instance used to generate SMTP ids
-     */
-    private final static Random random = new Random();
-
-    /**
-     * The SMTPHandlerChain object set by SMTPServer
-     */
-    SMTPHandlerChain handlerChain = null;
-
-    /**
-     * The session termination status
-     */
-    private boolean sessionEnded = false;
-
-    /**
-     * The user name of the authenticated user associated with this SMTP transaction.
-     */
-    private String authenticatedUser;
-
-    /**
-     * whether or not authorization is required for this connection
-     */
-    private boolean authSupported;
-
-    /**
-     * whether or not this connection can relay without authentication
-     */
-    private boolean relayingAllowed;
-    
-    /**
-     * The id associated with this particular SMTP interaction.
-     */
-    private String smtpID;
-
-    /**
-     * The per-service configuration data that applies to all handlers
-     */
-    private SMTPHandlerConfigurationData theConfigData;
+public class SMTPHandler implements ProtocolHandler, SMTPSession {
 
+	    private ProtocolHandlerHelper helper;
+	
+	     /**
+	     * The constants to indicate the current processing mode of the session
+	     */
+	    private final static byte COMMAND_MODE = 1;
+	    private final static byte RESPONSE_MODE = 2;
+	    private final static byte MESSAGE_RECEIVED_MODE = 3;
+	    private final static byte MESSAGE_ABORT_MODE = 4;
+	    private boolean sessionEnded = false;
+
+	    /**
+	    * SMTP Server identification string used in SMTP headers
+	     */
+	    private final static String SOFTWARE_TYPE = "JAMES SMTP Server " + Constants.SOFTWARE_VERSION;
+	
+	   /**
+	      * Static Random instance used to generate SMTP ids
+	      */
+	     private final static Random random = new Random();
+	 
+	     /**
+	     * Static RFC822DateFormat used to generate date headers
+	     */
+	     private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
+	
+	   /**
+	    * The name of the currently parsed command
+	    */
+	    String curCommandName =  null;
+
+	   /**
+	    * The value of the currently parsed command
+	    */
+	   String curCommandArgument =  null;
+	
     /**
      * The hash map holds states which should be used in the whole connection
      */
@@ -99,13 +96,19 @@
      */
     private LinkedList connectHandlers;
 
-    /**
-     * @see org.apache.james.core.AbstractJamesHandler#initHandler(java.net.Socket)
-     */
-    protected void initHandler(Socket connection) throws IOException {
-        super.initHandler(connection);
-        lineHandlers = handlerChain.getHandlers(LineHandler.class);
-    }
+	private SMTPHandlerConfigurationData theConfigData;
+
+	private boolean relayingAllowed;
+
+	private boolean authSupported;
+
+	private SMTPHandlerChain handlerChain;
+
+	private String authenticatedUser;
+
+	private String smtpID;
+
+	
 
     /**
      * Set the configuration data for the handler
@@ -120,13 +123,15 @@
         }
     }
     
-    /**
-     * @see org.apache.james.core.AbstractJamesHandler#handleProtocol()
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.socket.ProtocolHandler#handleProtocol()
      */
-    protected void handleProtocol() throws IOException {
+    public void handleProtocol() throws IOException {
         smtpID = random.nextInt(1024) + "";
-        relayingAllowed = theConfigData.isRelayingAllowed(remoteIP);
-        authSupported = theConfigData.isAuthSupported(remoteIP);
+        relayingAllowed = theConfigData.isRelayingAllowed(helper.getRemoteIP());
+        authSupported = theConfigData.isAuthRequired(helper.getRemoteIP());
+
         // Both called in resetHandler, we don't need to call them again here.
         // sessionEnded = false;
         // resetState();
@@ -168,12 +173,13 @@
             }
         }
 
-        theWatchdog.start();
+        CRLFDelimitedByteBuffer bytebufferHandler = new CRLFDelimitedByteBuffer(helper.getInputStream());
+        helper.getWatchdog().start();
         while(!sessionEnded) {
           //parse the command
           byte[] line =  null;
           try {
-              line = readInputLine();
+              line = bytebufferHandler.read();
           } catch (CRLFDelimitedByteBuffer.TerminationException e) {
               writeSMTPResponse(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, "Syntax error at character position " + e.position() + ". CR and LF must be CRLF paired.  See RFC 2821 #2.7.1."));
           } catch (CRLFDelimitedByteBuffer.LineLengthExceededException e) {
@@ -188,11 +194,11 @@
           } else {
               sessionEnded = true;
           }
-          theWatchdog.reset();
+          helper.getWatchdog().reset();
           
         }
-        theWatchdog.stop();
-        getLogger().debug("Closing socket.");
+        helper.getWatchdog().stop();
+        helper.getAvalonLogger().debug("Closing socket.");
     }
 
     /**
@@ -202,7 +208,7 @@
         // Write a single-line or multiline response
         if (response != null) {
             if (response.getRawLine() != null) {
-                writeLoggedFlushedResponse(response.getRawLine());
+                helper.writeLoggedFlushedResponse(response.getRawLine());
             } else {
                 // Iterator i = esmtpextensions.iterator();
                 for (int k = 0; k < response.getLines().size(); k++) {
@@ -211,11 +217,11 @@
                     if (k == response.getLines().size() - 1) {
                         respBuff.append(" ");
                         respBuff.append(response.getLines().get(k));
-                        writeLoggedFlushedResponse(respBuff.toString());
+                        helper.writeLoggedFlushedResponse(respBuff.toString());
                     } else {
                         respBuff.append("-");
                         respBuff.append(response.getLines().get(k));
-                        writeLoggedResponse(respBuff.toString());
+                        helper.writeLoggedResponse(respBuff.toString());
                     }
                 }
             }
@@ -229,7 +235,7 @@
     /**
      * Resets the handler data to a basic state.
      */
-    protected void resetHandler() {
+    public void resetHandler() {
         // not needed anymore because state is inside the connection state
         // resetState();
         resetConnectionState();
@@ -251,6 +257,7 @@
     public void setHandlerChain(SMTPHandlerChain handlerChain) {
         this.handlerChain = handlerChain;
         connectHandlers = handlerChain.getHandlers(ConnectHandler.class);
+        lineHandlers = handlerChain.getHandlers(LineHandler.class);
     }
 
 
@@ -258,14 +265,14 @@
      * @see org.apache.james.smtpserver.SMTPSession#getRemoteHost()
      */
     public String getRemoteHost() {
-        return remoteHost;
+        return helper.getRemoteHost();
     }
 
     /**
      * @see org.apache.james.smtpserver.SMTPSession#getRemoteIPAddress()
      */
     public String getRemoteIPAddress() {
-        return remoteIP;
+        return helper.getRemoteIP();
     }
 
     /**
@@ -404,4 +411,12 @@
         }
     }
 
+	public void errorHandler(RuntimeException e) {
+		helper.defaultErrorHandler(e);
+	}
+
+	public void setProtocolHandlerHelper(ProtocolHandlerHelper phh) {
+		helper = phh;
+	}
+
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java Fri Aug 14 14:57:00 2009
@@ -67,9 +67,24 @@
      * @param remoteIP the remote IP address in String form
      * @return whether SMTP authentication is on
      */
-    boolean isAuthSupported(String remoteIP);
+    boolean isAuthRequired(String remoteIP);
 
     /**
+     * Returns whether SMTP auth is active for this server.
+     *
+     * @return whether SMTP authentication is on
+     */
+    boolean isAuthRequired();
+
+    /**
+     * Returns whether the service validates the identity
+     * of its senders.
+     *
+     * @return whether SMTP authentication is on
+     */
+    boolean isVerifyIdentity();
+    
+    /**
      * Returns whether the remote server needs to send a HELO/EHLO
      * of its senders.
      *

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java Fri Aug 14 14:57:00 2009
@@ -27,6 +27,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.james.Constants;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.dnsservice.util.NetMatcher;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.dnsserver.DNSServer;
@@ -74,7 +75,7 @@
     /**
      * The DNSServer to use for queries
      */
-    private DNSServer dnsServer;
+    private DNSService dnsServer;
     
     /**
      * Whether authentication is required to use
@@ -133,7 +134,7 @@
         mailetcontext = (MailetContext) manager.lookup("org.apache.mailet.MailetContext");
         mailServer = (MailServer) manager.lookup(MailServer.ROLE);
         users = (UsersRepository) manager.lookup(UsersRepository.ROLE);
-        dnsServer = (DNSServer) manager.lookup(DNSServer.ROLE); 
+        dnsServer = (DNSService) manager.lookup(DNSServer.ROLE); 
     }
 
     /**
@@ -259,17 +260,6 @@
     public String getServiceType() {
         return "SMTP Service";
     }
-
-    /**
-     * @see org.apache.avalon.excalibur.pool.ObjectFactory#newInstance()
-     */
-    public Object newInstance() throws Exception {
-        SMTPHandler theHandler = new SMTPHandler();
-        //pass the handler chain to every SMTPhandler
-        theHandler.setHandlerChain(handlerChain);
-        
-        return theHandler;
-    }
     
     /**
      * @see org.apache.avalon.excalibur.pool.ObjectFactory#getCreatedClass()
@@ -322,17 +312,6 @@
             return relayingAllowed;
         }
 
-        /**
-         * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isAuthSupported(String)
-         */
-        public boolean isAuthSupported(String remoteIP) {
-            if (SMTPServer.this.authRequired == AUTH_ANNOUNCE) return true;
-            boolean authRequired = SMTPServer.this.authRequired != AUTH_DISABLED;
-            if (authorizedNetworks != null) {
-                authRequired = authRequired && !SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP);
-            }
-            return authRequired;
-        }
 
         /**
          * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#getMailServer()
@@ -370,6 +349,25 @@
         // TODO Auto-generated method stub
         return SMTPServer.this.addressBracketsEnforcement;
     }
+
+		public boolean isAuthRequired(String remoteIP) {
+			 if (SMTPServer.this.authRequired == AUTH_ANNOUNCE) return true;
+	            boolean authRequired = SMTPServer.this.authRequired != AUTH_DISABLED;
+	            if (authorizedNetworks != null) {
+	                authRequired = authRequired && !SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP);
+	            }
+	            return authRequired;
+		}
+
+		public boolean isAuthRequired() {
+			// TODO Auto-generated method stub
+			return false;
+		}
+
+		public boolean isVerifyIdentity() {
+			// TODO Auto-generated method stub
+			return false;
+		}
         
         //TODO: IF we create here an interface to get DNSServer
         //      we should access it from the SMTPHandlers

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/ExpnCmdHandler.java Fri Aug 14 14:57:00 2009
@@ -24,11 +24,11 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPRetCode;
 import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.util.mail.SMTPRetCode;
-import org.apache.james.util.mail.dsn.DSNStatus;
 
 /**
   * Handles EXPN command

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java Fri Aug 14 14:57:00 2009
@@ -32,6 +32,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.dnsserver.DNSServer;
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.ConnectHandler;
@@ -53,7 +54,7 @@
     private String[] whitelist;
     private String[] blacklist;
     
-    private DNSServer dnsServer = null;
+    private DNSService dnsServer = null;
     
     private boolean getDetail = false;
     
@@ -120,7 +121,7 @@
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager serviceMan) throws ServiceException {
-        setDNSServer((DNSServer) serviceMan.lookup(DNSServer.ROLE));
+        setDNSService((DNSService) serviceMan.lookup(DNSServer.ROLE));
     }
     
     /**
@@ -153,10 +154,10 @@
     /**
      * Set the DNSServer
      * 
-     * @param dnsServer The DNSServer
+     * @param mockedDnsServer The DNSServer
      */
-    public void setDNSServer(DNSServer dnsServer) {
-        this.dnsServer = dnsServer;
+    public void setDNSService(DNSService mockedDnsServer) {
+        this.dnsServer = mockedDnsServer;
     }
 
     /**

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java Fri Aug 14 14:57:00 2009
@@ -28,6 +28,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.dnsserver.DNSServer;
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.SMTPRetCode;
@@ -48,7 +49,7 @@
 
     protected boolean checkAuthNetworks = false;
 
-    protected DNSServer dnsServer = null;
+    protected DNSService dnsService = null;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -66,7 +67,7 @@
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager serviceMan) throws ServiceException {
-        setDnsServer((DNSServer) serviceMan.lookup(DNSServer.ROLE));
+        setDNSService((DNSService) serviceMan.lookup(DNSServer.ROLE));
     }
 
     /**
@@ -82,11 +83,11 @@
     /**
      * Set the DNSServer
      * 
-     * @param dnsServer
+     * @param dnsService
      *            The DNSServer
      */
-    public void setDnsServer(DNSServer dnsServer) {
-        this.dnsServer = dnsServer;
+    public void setDNSService(DNSService dnsService) {
+        this.dnsService = dnsService;
     }
 
     /**
@@ -118,7 +119,7 @@
         // try to resolv the provided helo. If it can not resolved do not
         // accept it.
         try {
-            dnsServer.getByName(argument);
+        	dnsService.getByName(argument);
         } catch (UnknownHostException e) {
             return true;
         }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java Fri Aug 14 14:57:00 2009
@@ -33,7 +33,7 @@
     protected boolean isBadHelo(SMTPSession session, String argument) {
         try {
             // get reverse entry
-            String reverse = dnsServer.getHostName(dnsServer.getByName(
+            String reverse = dnsService.getHostName(dnsService.getByName(
                     session.getRemoteIPAddress()));
             if (!argument.equals(reverse)) {
                 return true;

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java Fri Aug 14 14:57:00 2009
@@ -25,18 +25,19 @@
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.jspf.SPF;
-import org.apache.james.jspf.SPF1Utils;
-import org.apache.james.jspf.SPFResult;
+import org.apache.james.dsn.DSNStatus;
 import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.SPF1Utils;
+import org.apache.james.jspf.executor.SPFResult;
+import org.apache.james.jspf.impl.DefaultSPF;
+import org.apache.james.jspf.impl.SPF;
+import org.apache.james.smtpserver.SMTPRetCode;
 import org.apache.james.smtpserver.SMTPSession;
 import org.apache.james.smtpserver.hook.HookResult;
 import org.apache.james.smtpserver.hook.HookReturnCode;
 import org.apache.james.smtpserver.hook.MailHook;
 import org.apache.james.smtpserver.hook.MessageHook;
 import org.apache.james.smtpserver.hook.RcptHook;
-import org.apache.james.util.mail.SMTPRetCode;
-import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
@@ -110,7 +111,7 @@
      */
     public void initialize() throws Exception {
         if (dnsService == null) {
-            spf = new SPF(new SPFLogger(getLogger()));
+            spf = new DefaultSPF(new SPFLogger(getLogger()));
         } else {
             spf = new SPF(dnsService, new SPFLogger(getLogger()));
         }
@@ -198,6 +199,7 @@
                         + " = " + spfResult);
 
         // Check if we should block!
+        /*
         if ((spfResult.equals(SPF1Utils.FAIL_CONV))
                 || (spfResult.equals(SPF1Utils.SOFTFAIL_CONV) && blockSoftFail)
                 || (spfResult.equals(SPF1Utils.PERM_ERROR_CONV) && blockPermError)) {
@@ -211,6 +213,7 @@
         } else if (spfResult.equals(SPF1Utils.TEMP_ERROR_CONV)) {
             session.getState().put(SPF_TEMPBLOCKLISTED, "true");
         }
+        */
 
     }
 

Copied: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TLDLookup.java (from r804099, james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/TLDLookup.java)
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TLDLookup.java?p2=james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TLDLookup.java&p1=james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/TLDLookup.java&r1=804099&r2=804246&rev=804246&view=diff
==============================================================================
--- james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/TLDLookup.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TLDLookup.java Fri Aug 14 14:57:00 2009
@@ -20,7 +20,7 @@
 
 
 
-package org.apache.james.smtpserver.urirbl;
+package org.apache.james.smtpserver.core.filter.fastfail;
 
 import java.util.HashSet;
 

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java Fri Aug 14 14:57:00 2009
@@ -41,6 +41,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.dnsserver.DNSServer;
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.SMTPSession;
@@ -55,7 +56,7 @@
 public class URIRBLHandler extends AbstractLogEnabled implements MessageHook,
     Serviceable {
 
-    private DNSServer dnsServer;
+    private DNSService dnsServer;
 
     private Collection uriRbl;
 
@@ -71,7 +72,7 @@
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager serviceMan) throws ServiceException {
-        setDnsServer((DNSServer) serviceMan.lookup(DNSServer.ROLE));
+    	setDNSService((DNSService) serviceMan.lookup(DNSServer.ROLE));
     }
 
     /**
@@ -140,11 +141,11 @@
     /**
      * Set the DNSServer
      * 
-     * @param dnsServer
+     * @param service
      *            The DNSServer
      */
-    public void setDnsServer(DNSServer dnsServer) {
-        this.dnsServer = dnsServer;
+    public void setDNSService(DNSService service) {
+        this.dnsServer = service;
     }
 
     /**

Copied: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIScanner.java (from r804099, james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/URIScanner.java)
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIScanner.java?p2=james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIScanner.java&p1=james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/URIScanner.java&r1=804099&r2=804246&rev=804246&view=diff
==============================================================================
--- james/server/sandbox/container/smtpserver-function/src/main/java/org/apache/james/smtpserver/urirbl/URIScanner.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIScanner.java Fri Aug 14 14:57:00 2009
@@ -20,7 +20,7 @@
 
 
 
-package org.apache.james.smtpserver.urirbl;
+package org.apache.james.smtpserver.core.filter.fastfail;
 
 import java.util.HashSet;
 import java.util.Iterator;

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java Fri Aug 14 14:57:00 2009
@@ -30,6 +30,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.dnsservice.TemporaryResolutionException;
 import org.apache.james.api.dnsservice.util.NetMatcher;
 import org.apache.james.dnsserver.DNSServer;
@@ -48,7 +49,7 @@
 public class ValidRcptMX extends AbstractLogEnabled implements RcptHook,
     Serviceable {
 
-    private DNSServer dnsServer = null;
+    private DNSService dnsServer = null;
 
     private static final String LOCALHOST = "localhost";
 
@@ -90,7 +91,7 @@
      * @param networks Collection of networks 
      * @param dnsServer The DNSServer
      */
-    public void setBannedNetworks(Collection networks, DNSServer dnsServer) {
+    public void setBannedNetworks(Collection networks, DNSService dnsServer) {
         bNetwork = new NetMatcher(networks, dnsServer) {
             protected void log(String s) {
                 getLogger().debug(s);
@@ -103,7 +104,7 @@
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager arg0) throws ServiceException {
-        setDNSServer((DNSServer) arg0.lookup(DNSServer.ROLE));
+        setDNSService((DNSService) arg0.lookup(DNSServer.ROLE));
     }
 
     /**
@@ -112,7 +113,7 @@
      * @param dnsServer
      *                The dnsServer
      */
-    public void setDNSServer(DNSServer dnsServer) {
+    public void setDNSService(DNSService dnsServer) {
         this.dnsServer = dnsServer;
     }
 

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java Fri Aug 14 14:57:00 2009
@@ -27,6 +27,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.dnsservice.TemporaryResolutionException;
 import org.apache.james.dnsserver.DNSServer;
 import org.apache.james.dsn.DSNStatus;
@@ -47,7 +48,7 @@
     
     private boolean checkAuthNetworks = false;
     
-    private DNSServer dnsServer = null;
+    private DNSService dnsServer = null;
 
     
     /**
@@ -65,7 +66,7 @@
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
      */
     public void service(ServiceManager serviceMan) throws ServiceException {
-        setDnsServer((DNSServer) serviceMan.lookup(DNSServer.ROLE));
+        setDNSService((DNSService) serviceMan.lookup(DNSServer.ROLE));
     }
     
     /**
@@ -73,7 +74,7 @@
      * 
      * @param dnsServer The DnsServer
      */
-    public void setDnsServer(DNSServer dnsServer) {
+    public void setDNSService(DNSService dnsServer) {
         this.dnsServer = dnsServer;
     }
     

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java Fri Aug 14 14:57:00 2009
@@ -30,21 +30,22 @@
 
 import javax.mail.internet.ParseException;
 
+import junit.framework.TestCase;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.services.AbstractDNSServer;
-import org.apache.james.services.DNSServer;
+import org.apache.james.api.dnsservice.AbstractDNSServer;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.dnsserver.DNSServer;
 import org.apache.james.smtpserver.core.filter.fastfail.DNSRBLHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.mailet.MailAddress;
 
-import junit.framework.TestCase;
-
 public class DNSRBLHandlerTest extends TestCase {
 
-    private DNSServer mockedDnsServer;
+    private DNSService mockedDnsServer;
 
     private SMTPSession mockedSMTPSession;
 
@@ -159,7 +160,7 @@
         ContainerUtil.enableLogging(rbl, new MockLogger());
 
         setupMockedSMTPSession(new MailAddress("any@domain"));
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
@@ -176,7 +177,7 @@
         ContainerUtil.enableLogging(rbl, new MockLogger());
 
         setupMockedSMTPSession(new MailAddress("any@domain"));
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(false);
@@ -194,7 +195,7 @@
         setRelayingAllowed(true);
         setupMockedSMTPSession(new MailAddress("any@domain"));
 
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
@@ -211,7 +212,7 @@
         setRemoteIp("192.168.0.1");
         setupMockedSMTPSession(new MailAddress("any@domain"));
 
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
@@ -228,7 +229,7 @@
         setRemoteIp("127.0.0.3");
         setupMockedSMTPSession(new MailAddress("any@domain"));
 
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);
@@ -245,7 +246,7 @@
         setRemoteIp("127.0.0.2");
         setupMockedSMTPSession(new MailAddress("any@domain"));
 
-        rbl.setDNSServer(mockedDnsServer);
+        rbl.setDNSService(mockedDnsServer);
 
         rbl.setWhitelist(new String[] { "bl.spamcop.net." });
         rbl.setGetDetail(true);

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java Fri Aug 14 14:57:00 2009
@@ -72,24 +72,7 @@
     
         assertEquals("Rejected.. To many recipients", resp, HookReturnCode.DENY);
     }
-    /*
-    public void testAddScoreMaxRcpt() {
-        SMTPSession session = setupMockedSession(3);
-        session.getState().put(JunkScore.JUNK_SCORE, new JunkScoreImpl());
-    
-        MaxRcptHandler handler = new MaxRcptHandler();
-    
-        ContainerUtil.enableLogging(handler,new MockLogger());
-    
-        handler.setAction("junkScore");
-        handler.setScore(20);
-        handler.setMaxRcpt(2);
-        SMTPResponse response = handler.onCommand(session,"RCPT","<te...@test>");
-
-        assertNull("Not Rejected.. we use junkScore action", response);
-        assertEquals("Get Score", ((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("MaxRcptCheck"),20.0,0d);
-    }
-    */
+  
     
     public void testNotRejectMaxRcpt() throws ParseException {
         SMTPSession session = setupMockedSession(3);

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java?rev=804246&r1=804245&r2=804246&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java Fri Aug 14 14:57:00 2009
@@ -21,23 +21,23 @@
 
 package org.apache.james.smtpserver;
 
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.services.AbstractDNSServer;
-import org.apache.james.services.DNSServer;
-import org.apache.james.smtpserver.core.filter.fastfail.ResolvableEhloHeloHandler;
-import org.apache.james.smtpserver.hook.HookReturnCode;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.mailet.MailAddress;
-
-import javax.mail.internet.ParseException;
-
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.mail.internet.ParseException;
+
 import junit.framework.TestCase;
 
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.api.dnsservice.AbstractDNSServer;
+import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.smtpserver.core.filter.fastfail.ResolvableEhloHeloHandler;
+import org.apache.james.smtpserver.hook.HookReturnCode;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.mailet.MailAddress;
+
 public class ResolvableEhloHeloHandlerTest extends TestCase {
 
     public final static String INVALID_HOST = "foo.bar";
@@ -79,8 +79,8 @@
         return session;
     }
     
-    private DNSServer setupMockDNSServer() {
-        DNSServer dns = new AbstractDNSServer(){
+    private DNSService setupMockDNSServer() {
+    	DNSService dns = new AbstractDNSServer(){
             public InetAddress getByName(String host) throws UnknownHostException {
                 if (host.equals(INVALID_HOST)) 
                     throw new UnknownHostException();
@@ -98,7 +98,7 @@
         
         ContainerUtil.enableLogging(handler,new MockLogger());
         
-        handler.setDnsServer(setupMockDNSServer());
+        handler.setDNSService(setupMockDNSServer());
         
         handler.doHelo(session, INVALID_HOST);
         assertNotNull("Invalid HELO",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
@@ -115,7 +115,7 @@
         
         ContainerUtil.enableLogging(handler,new MockLogger());
         
-        handler.setDnsServer(setupMockDNSServer());
+        handler.setDNSService(setupMockDNSServer());
   
         handler.doHelo(session, VALID_HOST);
         assertNull("Valid HELO",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
@@ -151,7 +151,7 @@
         
         ContainerUtil.enableLogging(handler,new MockLogger());
         
-        handler.setDnsServer(setupMockDNSServer());
+        handler.setDNSService(setupMockDNSServer());
 
         handler.doHelo(session, INVALID_HOST);
         assertNotNull("Value stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
@@ -168,7 +168,7 @@
         
         ContainerUtil.enableLogging(handler,new MockLogger());
         
-        handler.setDnsServer(setupMockDNSServer());
+        handler.setDNSService(setupMockDNSServer());
         
 
         handler.doHelo(session, INVALID_HOST);
@@ -185,7 +185,7 @@
         
         ContainerUtil.enableLogging(handler,new MockLogger());
         
-        handler.setDnsServer(setupMockDNSServer());
+        handler.setDNSService(setupMockDNSServer());
         handler.setCheckAuthNetworks(true);
 
         handler.doHelo(session, INVALID_HOST);



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org