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 2006/12/28 09:45:22 UTC

svn commit: r490678 - in /james/server/sandbox/handlerapi-experiment/src: java/org/apache/james/smtpserver/core/ java/org/apache/james/smtpserver/core/filter/fastfail/ test/org/apache/james/smtpserver/

Author: norman
Date: Thu Dec 28 00:45:21 2006
New Revision: 490678

URL: http://svn.apache.org/viewvc?view=rev&rev=490678
Log:
Add an abstract class for handling hooks. Some more refactoring. See JAMES-750 and JAMES-549

Added:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java   (with props)
Modified:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java
    james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
    james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java

Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java?view=auto&rev=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AbstractHookableCmdHandler.java Thu Dec 28 00:45:21 2006
@@ -0,0 +1,133 @@
+/****************************************************************
+ * 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.core;
+
+import java.util.List;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.ExtensibleHandler;
+import org.apache.james.smtpserver.SMTPResponse;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.RcptHook;
+import org.apache.james.util.mail.SMTPRetCode;
+import org.apache.mailet.MailAddress;
+
+/**
+  * Abstract class which Handle hooks. 
+  */
+public abstract class AbstractHookableCmdHandler extends AbstractLogEnabled implements
+        CommandHandler, ExtensibleHandler {
+    
+    /**
+     * Handle command processing
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(org.apache.james.smtpserver.SMTPSession, java.lang.String, java.lang.String) 
+    **/
+    public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+        SMTPResponse response = doFilterChecks(session,command,parameters);
+    
+        if (response == null) {
+            response = processHooks(session, command, parameters);
+            if (response == null) {
+                return doCoreCmd(session, command, parameters);
+            } else {
+                return response;
+            }
+        } else {
+            return response;
+        }
+
+    }
+
+    /**
+     * Process all hooks for the given command
+     * 
+     * @param session the SMTPSession object
+     * @param command the command
+     * @param parameters the paramaters 
+     * @return SMTPResponse
+     */
+    private SMTPResponse processHooks(SMTPSession session,String command,String parameters) {
+        List hooks = getHooks();
+        
+    if(hooks != null) {
+            getLogger().debug("executing  hooks");
+            int count = hooks.size();
+            for(int i =0; i < count; i++) {
+                Object rawHook = hooks.get(i);
+                HookResult result = null;
+                
+                if ("RCPT".equals(command) && rawHook instanceof RcptHook) {
+                    result = ((RcptHook) rawHook).doRcpt(session, (MailAddress) session.getState().get(SMTPSession.SENDER), (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT));
+                }
+                
+                //TODO: Add more hooks
+                
+                if (result != null) {
+                    int rCode = result.getResult();
+                    String smtpRetCode = result.getSmtpRetCode();
+                    String smtpDesc = result.getSmtpDescription();
+                
+                    if (rCode == RcptHook.DENY) {
+                        if (smtpRetCode == null) smtpRetCode = SMTPRetCode.TRANSACTION_FAILED;
+                        if (smtpDesc == null) smtpDesc = "Email rejected";
+                    
+                        return new SMTPResponse(smtpRetCode, smtpDesc);
+                    }else if (rCode == RcptHook.DENYSOFT) {
+                        return new SMTPResponse(SMTPRetCode.LOCAL_ERROR,"Temporary problem. Please try again later");
+                    }
+                }
+            }
+        }
+        return null;
+    }
+    
+
+    /**
+     * Execute Syntax checks and return a SMTPResponse if a syntax error was detected, otherwise null.
+     * 
+     * @param session 
+     * @param command
+     * @param parameters
+     * @return
+     */
+    protected abstract SMTPResponse doFilterChecks(SMTPSession session, String command, String parameters);
+    
+    /**
+     * Execute the core commandHandling.
+     * 
+     * @param session
+     * @param command
+     * @param parameters
+     * @return
+     */
+    protected abstract SMTPResponse doCoreCmd(SMTPSession session , String command, String parameters);
+    
+    /**
+     * Return a list which holds all hooks for the cmdHandler
+     * 
+     * @return
+     */
+    protected abstract List getHooks(); 
+}

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

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/RcptCmdHandler.java Thu Dec 28 00:45:21 2006
@@ -27,12 +27,10 @@
 import java.util.Locale;
 import java.util.StringTokenizer;
 
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.ExtensibleHandler;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.smtpserver.hook.HookResult;
 import org.apache.james.smtpserver.hook.RcptHook;
 import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
@@ -41,60 +39,11 @@
 /**
   * Handles RCPT command
   */
-public class RcptCmdHandler extends AbstractLogEnabled implements
+public class RcptCmdHandler extends AbstractHookableCmdHandler implements
         CommandHandler, ExtensibleHandler {
 
     private List rcptHooks;
     
-    
-    /**
-     * handles RCPT command
-     *
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(org.apache.james.smtpserver.SMTPSession, java.lang.String, java.lang.String) 
-    **/
-    public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
-        SMTPResponse response = doRCPTSyntaxFilter(session,parameters);
-    
-        if (response == null) {
-            response = processExtensions(session);
-            if (response == null) {
-                return doRCPT(session, parameters);
-            } else {
-                return response;
-            }
-        } else {
-            return response;
-        }
-
-    }
-
-    /**
-     * @param session
-     */
-    private SMTPResponse processExtensions(SMTPSession session) {
-        if(rcptHooks != null) {
-            getLogger().debug("executing rcpt hook");
-            int count = rcptHooks.size();
-            for(int i =0; i < count; i++) {
-                    
-                HookResult result = ((RcptHook) rcptHooks.get(i)).doRcpt(session, (MailAddress) session.getState().get(SMTPSession.SENDER), (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT));
-                int rCode = result.getResult();
-                String smtpRetCode = result.getSmtpRetCode();
-                String smtpDesc = result.getSmtpDescription();
-                
-                if (rCode == RcptHook.DENY) {
-                    if (smtpRetCode == null) smtpRetCode = SMTPRetCode.TRANSACTION_FAILED;
-                    if (smtpDesc == null) smtpDesc = "Email rejected";
-                    
-                    return new SMTPResponse(smtpRetCode, smtpDesc);
-                }else if (rCode == RcptHook.DENYSOFT) {
-                    return new SMTPResponse(SMTPRetCode.LOCAL_ERROR,"Temporary problem. Please try again later");
-                }
-            }
-        }
-        return null;
-    }
-
 
     /**
      * Handler method called upon receipt of a RCPT command.
@@ -104,7 +53,7 @@
      * @param session SMTP session object
      * @param argument the argument passed in with the command by the SMTP client
      */
-    private SMTPResponse doRCPT(SMTPSession session, String argument) {
+    protected SMTPResponse doCoreCmd(SMTPSession session, String command, String parameters) {
         Collection rcptColl = (Collection) session.getState().get(
                 SMTPSession.RCPT_LIST);
         if (rcptColl == null) {
@@ -128,7 +77,7 @@
      * @param session SMTP session object
      * @param argument the argument passed in with the command by the SMTP client
      */
-    private SMTPResponse doRCPTSyntaxFilter(SMTPSession session, String argument) {
+     protected SMTPResponse doFilterChecks(SMTPSession session, String command, String argument) {
         String recipient = null;
         if ((argument != null) && (argument.indexOf(":") > 0)) {
             int colonIndex = argument.indexOf(":");
@@ -324,6 +273,13 @@
             this.rcptHooks = extension; 
         }
 
+    }
+    
+    /**
+     * @see org.apache.james.smtpserver.core.AbstractHookableCmdHandler#getHooks()
+     */
+    protected List getHooks() {
+        return rcptHooks;
     }
 
 }

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java Thu Dec 28 00:45:21 2006
@@ -21,6 +21,7 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
@@ -32,6 +33,8 @@
 import org.apache.james.smtpserver.ConnectHandler;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.RcptHook;
 import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
@@ -45,8 +48,8 @@
   * Connect handler for DNSRBL processing
   */
 public class DNSRBLHandler
-    extends AbstractJunkHandler
-    implements ConnectHandler, CommandHandler, Configurable, Serviceable {
+    extends AbstractLogEnabled
+    implements ConnectHandler, RcptHook, Configurable, Serviceable {
     /**
      * The lists of rbl servers to be checked to limit spam
      */
@@ -114,8 +117,6 @@
            getDetail = configuration.getValueAsBoolean();
         }
         
-        super.configure(handlerConfiguration);
-
     }
 
     /**
@@ -247,59 +248,25 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection commands = new ArrayList();
-        commands.add("RCPT");
-        return commands;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     * @see org.apache.james.smtpserver.hook.RcptHook#doRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
      */
-    public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
-        return doProcessing(session);
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
-     */
-    protected boolean check(SMTPSession session) {
+    public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
         String blocklisted = (String) session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
         MailAddress recipientAddress = (MailAddress) session.getState().get(
                 SMTPSession.CURRENT_RECIPIENT);
 
-        return (blocklisted != null && // was found in the RBL
+        if (blocklisted != null && // was found in the RBL
                 !(session.isAuthRequired() && session.getUser() != null) && // Not (SMTP AUTH is enabled and not authenticated)
-                !(recipientAddress.getUser().equalsIgnoreCase("postmaster") || recipientAddress.getUser().equalsIgnoreCase("abuse")));
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScore(org.apache.james.smtpserver.SMTPSession)
-     */
-    protected JunkScore getJunkScore(SMTPSession session) {
-        return JunkScoreHandler.getLazyJunkScoreHandler(session.getConnectionState(), JunkScore.JUNK_SCORE_SESSION);
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
-     */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        JunkHandlerData data = new JunkHandlerData();
-        
-        data.setJunkScoreLogString("Ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Add junkScore: " + getScore());
-        data.setRejectLogString("ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Reject email");
-    
-        if (blocklistedDetail != null) {
-            data.setRejectResponseString(new SMTPResponse(SMTPRetCode.AUTH_REQUIRED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail));
-        } else {
-            data.setRejectResponseString(new SMTPResponse(SMTPRetCode.AUTH_REQUIRED, DSNStatus.getStatus(DSNStatus.PERMANENT,
-                            DSNStatus.SECURITY_AUTH)  + " Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress() 
-                            + " is restricted.  Contact the postmaster for details."));
+                !(recipientAddress.getUser().equalsIgnoreCase("postmaster") || recipientAddress.getUser().equalsIgnoreCase("abuse"))) {
+            if (blocklistedDetail == null) {
+                return new HookResult(RcptHook.DENY,DSNStatus.getStatus(DSNStatus.PERMANENT,
+                        DSNStatus.SECURITY_AUTH)  + " Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress() 
+                        + " is restricted.  Contact the postmaster for details.");
+            } else {
+                return new HookResult(RcptHook.DENY,"530",DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail);
+            }
+           
         }
-        data.setScoreName("DNSRBLCheck");
-        return data;
+        return new HookResult(RcptHook.OK);
     }
-
 }

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java Thu Dec 28 00:45:21 2006
@@ -28,6 +28,8 @@
 import org.apache.james.smtpserver.SMTPSession;
 import org.apache.james.smtpserver.hook.HookResult;
 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.MailAddress;
 
@@ -49,8 +51,6 @@
             throw new ConfigurationException(
                     "Please set the maxRcpt configuration value");
         }
-        
-        // super.configure(handlerConfiguration);
     }
 
     /**
@@ -68,23 +68,12 @@
      */
     public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
         if ((session.getRcptCount() + 1) > maxRcpt) {
-            return new HookResult(RcptHook.DENY);
+            getLogger().info("Maximum recipients of " + maxRcpt + " reached");
+            
+            return new HookResult(RcptHook.DENY, SMTPRetCode.SYSTEM_STORAGE_ERROR, DSNStatus.getStatus(DSNStatus.NETWORK, DSNStatus.DELIVERY_TOO_MANY_REC)
+                    + " Requested action not taken: max recipients reached");
         } else {
             return new HookResult(RcptHook.OK);
         }
     }
-
-
-    /*
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        JunkHandlerData data = new JunkHandlerData();
-    
-        data.setRejectResponseString(new SMTPResponse(SMTPRetCode.SYSTEM_STORAGE_ERROR, DSNStatus.getStatus(DSNStatus.NETWORK, DSNStatus.DELIVERY_TOO_MANY_REC)
-                + " Requested action not taken: max recipients reached"));
-        data.setJunkScoreLogString("Maximum recipients of " + maxRcpt + " reached. Add JunkScore: " +getScore());
-        data.setRejectLogString("Maximum recipients of " + maxRcpt + " reached");
-        data.setScoreName("MaxRcptCheck");
-        return data;
-    }
-    */
 }

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java Thu Dec 28 00:45:21 2006
@@ -21,23 +21,21 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
-import java.util.ArrayList;
-import java.util.Collection;
-
 import org.apache.avalon.framework.configuration.Configurable;
 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.smtpserver.CommandHandler;
-import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.hook.HookResult;
+import org.apache.james.smtpserver.hook.RcptHook;
+import org.apache.mailet.MailAddress;
 
 /**
  * Add tarpit support to SMTPServer. See http://www.palomine.net/qmail/tarpit.html for more information
  *
  */
 public class TarpitHandler extends AbstractLogEnabled implements
-        CommandHandler, Configurable {
+        RcptHook, Configurable {
 
     private int tarpitRcptCount = 0;
 
@@ -89,11 +87,11 @@
     public void setTarpitSleepTime(long tarpitSleepTime) {
         this.tarpitSleepTime = tarpitSleepTime;
     }
-    
+
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(org.apache.james.smtpserver.SMTPSession, java.lang.String, java.lang.String) 
-     */  
-    public SMTPResponse onCommand(SMTPSession session, String command, String parameters) {
+     * @see org.apache.james.smtpserver.hook.RcptHook#doRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
+     */
+    public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
 
         int rcptCount = 0;
         rcptCount = session.getRcptCount();
@@ -103,16 +101,6 @@
             session.sleep(tarpitSleepTime);
         }
         
-        return null;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("RCPT");
-        
-        return implCommands;
+        return new HookResult(RcptHook.OK);
     }
 }

Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java Thu Dec 28 00:45:21 2006
@@ -38,8 +38,6 @@
 import org.apache.james.services.DNSServer;
 import org.apache.james.smtpserver.core.filter.fastfail.DNSRBLHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.util.junkscore.JunkScore;
-import org.apache.james.util.junkscore.JunkScoreImpl;
 import org.apache.mailet.MailAddress;
 
 import junit.framework.TestCase;
@@ -126,14 +124,13 @@
         mockedSMTPSession = new AbstractSMTPSession() {
             HashMap state = new HashMap();
             HashMap connectionState = new HashMap();
-            boolean stopHandler = false;
             
             public String getRemoteIPAddress() {
                 return remoteIp;
             }
 
             public Map getState() {
-            state.put(SMTPSession.CURRENT_RECIPIENT, rcpt);
+                state.put(SMTPSession.CURRENT_RECIPIENT, rcpt);
                 return state;
             }
 
@@ -149,22 +146,10 @@
                 return 0;
             }
 
-            public void setStopHandlerProcessing(boolean b) {
-                stopHandler = b;  
-            }
-
-            public boolean getStopHandlerProcessing() {
-                return stopHandler;
-            }
-
             public Map getConnectionState() {       
                 return connectionState;
             }
 
-            public void resetConnectionState() {
-                connectionState.clear();
-            }
-
         };
     }
 
@@ -280,27 +265,6 @@
         }
         
         assertTrue("Invalid config",exception);
-    }
-
-    public void testAddJunkScore() throws ParseException {
-        DNSRBLHandler rbl = new DNSRBLHandler();
-
-        ContainerUtil.enableLogging(rbl, new MockLogger());
-
-        setupMockedSMTPSession(new MailAddress("any@domain"));
-        mockedSMTPSession.getConnectionState().put(JunkScore.JUNK_SCORE_SESSION, new JunkScoreImpl());
-        rbl.setDNSServer(mockedDnsServer);
-
-        rbl.setBlacklist(new String[] { "bl.spamcop.net." });
-        rbl.setGetDetail(false);
-        rbl.setScore(20);
-        rbl.setAction("junkScore");
-        rbl.onConnect(mockedSMTPSession);
-        assertNull("No details",mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-        assertNotNull("Listed on RBL",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
-        
-        rbl.onCommand(mockedSMTPSession,"RCPT","<te...@test>");
-        assertEquals("Score stored",((JunkScore) mockedSMTPSession.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).getStoredScore("DNSRBLCheck"), 20.0, 0d);
     }
 
 }

Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java?view=diff&rev=490678&r1=490677&r2=490678
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/TarpitHandlerTest.java Thu Dec 28 00:45:21 2006
@@ -18,9 +18,12 @@
  ****************************************************************/
 package org.apache.james.smtpserver;
 
+import javax.mail.internet.ParseException;
+
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.james.smtpserver.core.filter.fastfail.TarpitHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.mailet.MailAddress;
 
 import junit.framework.TestCase;
 
@@ -45,7 +48,7 @@
         return session;
     }
 
-    public void testTarpit() {
+    public void testTarpit() throws ParseException {
         long tarpitTime = 1000;
         long tarpitTolerance = 100;
         long startTime;
@@ -58,13 +61,13 @@
 
         // no tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(0),"RCPT","<te...@test>");
+        handler.doRcpt(setupMockedSession(0),null,new MailAddress("test@test"));
         assertTrue("No tarpit",
                 (System.currentTimeMillis() - startTime) < tarpitTime - tarpitTolerance);
 
         // tarpit used
         startTime = System.currentTimeMillis();
-        handler.onCommand(setupMockedSession(3),"RCPT","<te...@test>");
+        handler.doRcpt(setupMockedSession(3),null,new MailAddress("test@test"));
         assertTrue("tarpit",
                 (System.currentTimeMillis() - startTime) >= tarpitTime - tarpitTolerance);
     }



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