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/11/17 13:00:03 UTC

svn commit: r476116 - in /james/server/trunk/src: java/org/apache/james/smtpserver/core/filter/fastfail/ test/org/apache/james/smtpserver/

Author: norman
Date: Fri Nov 17 04:00:02 2006
New Revision: 476116

URL: http://svn.apache.org/viewvc?view=rev&rev=476116
Log:
More classes now extends AbstractActionHandler. See JAMES-614
Some refactorings to remove duplicated code.

Added:
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java
      - copied, changed from r476101, james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractActionHandler.java
Removed:
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractActionHandler.java
Modified:
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
    james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
    james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
    james/server/trunk/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java

Copied: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java (from r476101, james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractActionHandler.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java?view=diff&rev=476116&p1=james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractActionHandler.java&r1=476101&p2=james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractActionHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java Fri Nov 17 04:00:02 2006
@@ -34,7 +34,7 @@
  *       Or maybe add a Handler which loads other handlers ?
  *
  */
-public abstract class AbstractActionHandler extends AbstractLogEnabled implements Configurable {
+public abstract class AbstractJunkHandler extends AbstractLogEnabled implements Configurable {
     private String action = "reject";
     private double score = 0;
 
@@ -93,20 +93,22 @@
     }
     
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     * Process the checking
+     * 
+     * @param session the SMTPSession
      */
-    public void onCommand(SMTPSession session) {
+    protected void doProcessing(SMTPSession session) {
         if (check(session)) {
             if (getAction().equals(JunkScoreConfigUtil.JUNKSCORE)) {
-                if (getLogger().isInfoEnabled()) {
-                    getLogger().info(getJunkScoreLogString(session)+" Add Junkscore: " + getScore());
-                }
+                getLogger().info(getJunkScoreLogString(session));
                 JunkScore junk = getJunkScore(session);
                 junk.setStoredScore(getScoreName(), getScore());
                  
             } else {
                 String response = getResponseString(session);
-                getLogger().info(response);
+                
+                if (getRejectLogString(session) != null) getLogger().info(getRejectLogString(session));
+                
                 session.writeResponse(response);
                 // After this filter match we should not call any other handler!
                 session.setStopHandlerProcessing(true);
@@ -153,7 +155,7 @@
     protected abstract String getScoreName();
     
     /**
-     * Return the JunkScore object
+     * Return the JunkScore object.
      * 
      * @return junkScore
      */

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java Fri Nov 17 04:00:02 2006
@@ -21,7 +21,6 @@
 
 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 +31,7 @@
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.ConnectHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.MailAddress;
 
@@ -43,7 +43,7 @@
   * Connect handler for DNSRBL processing
   */
 public class DNSRBLHandler
-    extends AbstractLogEnabled
+    extends AbstractJunkHandler
     implements ConnectHandler, CommandHandler, Configurable, Serviceable {
     /**
      * The lists of rbl servers to be checked to limit spam
@@ -111,6 +111,8 @@
         if(configuration != null) {
            getDetail = configuration.getValueAsBoolean();
         }
+        
+        super.configure(handlerConfiguration);
 
     }
 
@@ -255,36 +257,68 @@
      * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
      */
     public void onCommand(SMTPSession session) {
-        String responseString = null;
+        doProcessing(session);       
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected boolean check(SMTPSession session) {
         String blocklisted = (String) session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
         MailAddress recipientAddress = (MailAddress) session.getState().get(
                 SMTPSession.CURRENT_RECIPIENT);
 
-        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"))) {
-
-            // trying to send e-mail to other than postmaster or abuse
-            if (blocklistedDetail != null) {
-                responseString = "530 "
-                        + DSNStatus.getStatus(DSNStatus.PERMANENT,
-                                DSNStatus.SECURITY_AUTH) + " "
-                        + blocklistedDetail;
-            } else {
-                responseString = "530 "
-                        + DSNStatus.getStatus(DSNStatus.PERMANENT,
-                                DSNStatus.SECURITY_AUTH)
-                        + " Rejected: unauthenticated e-mail from "
-                        + session.getRemoteIPAddress()
-                        + " is restricted.  Contact the postmaster for details.";
-            }
-            session.writeResponse(responseString);
+        return (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")));
+    }
 
-            // After this filter match we should not call any other handler!
-            session.setStopHandlerProcessing(true);
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScore(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected JunkScore getJunkScore(SMTPSession session) {
+        return (JunkScore) session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION);
+    }
+    
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getJunkScoreLogString(SMTPSession session) {
+        return "Ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Add junkScore: " + getScore();
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getRejectLogString(SMTPSession session) {
+        return "ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Reject email";
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getResponseString(SMTPSession session) {
+        String responseString;
+        if (blocklistedDetail != null) {
+            responseString = "530 "
+                    + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                            DSNStatus.SECURITY_AUTH) + " "
+                    + blocklistedDetail;
+        } else {
+            responseString = "530 "
+                    + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                            DSNStatus.SECURITY_AUTH)
+                    + " Rejected: unauthenticated e-mail from "
+                    + session.getRemoteIPAddress()
+                    + " is restricted.  Contact the postmaster for details.";
         }
+        return responseString;
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getScoreName()
+     */
+    protected String getScoreName() {
+        return "DNSRBLCheck";
     }
 }

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java Fri Nov 17 04:00:02 2006
@@ -29,9 +29,10 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.mail.dsn.DSNStatus;
 
-public class MaxRcptHandler extends AbstractActionHandler implements
+public class MaxRcptHandler extends AbstractJunkHandler implements
         CommandHandler, Configurable {
 
     private int maxRcpt = 0;
@@ -64,6 +65,13 @@
     }
 
     /**
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     */
+    public void onCommand(SMTPSession session) {
+        doProcessing(session);
+    }
+    
+    /**
      * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
      */
     public Collection getImplCommands() {
@@ -74,7 +82,7 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#check(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
      */
     protected boolean check(SMTPSession session) {
         // check if the max recipients has reached
@@ -82,21 +90,21 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getJunkScoreLogString(SMTPSession session) {
-        return "Maximum recipients of " + maxRcpt + " reached.";
+        return "Maximum recipients of " + maxRcpt + " reached. Add JunkScore: " +getScore();
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getRejectLogString(SMTPSession session) {
         return getResponseString(session);
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getResponseString(SMTPSession session) {
         String responseString = "452 "
@@ -107,10 +115,9 @@
     }
     
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getScoreName()
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getScoreName()
      */
     protected String getScoreName() {
         return "MaxRcptCheck";
     }
-
 }

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java Fri Nov 17 04:00:02 2006
@@ -22,13 +22,13 @@
 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.avalon.framework.service.ServiceException;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.services.DNSServer;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.MailAddress;
 
@@ -39,16 +39,16 @@
 /**
  * This CommandHandler can be used to reject not resolvable EHLO/HELO
  */
-public class ResolvableEhloHeloHandler extends AbstractLogEnabled implements
+public class ResolvableEhloHeloHandler extends AbstractJunkHandler implements
         CommandHandler, Configurable, Serviceable {
 
     public final static String BAD_EHLO_HELO = "BAD_EHLO_HELO";
 
-    private boolean checkAuthNetworks = false;
+    protected boolean checkAuthNetworks = false;
 
     private boolean checkAuthUsers = false;
 
-    private DNSServer dnsServer = null;
+    protected DNSServer dnsServer = null;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -66,6 +66,8 @@
         if (configAuthUser != null) {
             setCheckAuthUsers(configAuthUser.getValueAsBoolean(false));
         }
+        
+        super.configure(handlerConfiguration);
     }
 
     /**
@@ -115,7 +117,7 @@
                 || command.equals("EHLO")) {
             checkEhloHelo(session, argument);
         } else if (command.equals("RCPT")) {
-            reject(session, argument);
+            doProcessing(session);
         }
     }
 
@@ -127,7 +129,7 @@
      * @param argument
      *            The argument
      */
-    private void checkEhloHelo(SMTPSession session, String argument) {
+    protected void checkEhloHelo(SMTPSession session, String argument) {
         /**
          * don't check if the ip address is allowed to relay. Only check if it
          * is set in the config.
@@ -143,15 +145,24 @@
         }
     }
 
+
     /**
-     * Reject on invalid EHLO/HELO
-     * 
-     * @param session
-     *            The SMTPSession
-     * @param argument
-     *            The argument
+     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+     */
+    public Collection getImplCommands() {
+        Collection implCommands = new ArrayList();
+        implCommands.add("EHLO");
+        implCommands.add("HELO");
+        implCommands.add("RCPT");
+
+        return implCommands;
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
      */
-    private void reject(SMTPSession session, String argument) {
+    protected boolean check(SMTPSession session) {
+    
         MailAddress rcpt = (MailAddress) session.getState().get(
                 SMTPSession.CURRENT_RECIPIENT);
 
@@ -159,32 +170,52 @@
         if (session.getState().get(BAD_EHLO_HELO) == null
                 || rcpt.getUser().equalsIgnoreCase("postmaster")
                 || rcpt.getUser().equalsIgnoreCase("abuse"))
-            return;
+            return false;
 
         // Check if the client was authenticated
         if (!(session.isAuthRequired() && session.getUser() != null && !checkAuthUsers)) {
-            String responseString = "501 "
-                    + DSNStatus.getStatus(DSNStatus.PERMANENT,
-                            DSNStatus.DELIVERY_INVALID_ARG)
-                    + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved";
-            session.writeResponse(responseString);
-            getLogger().info(responseString);
-
-            // After this filter match we should not call any other handler!
-            session.setStopHandlerProcessing(true);
+            return true;
         }
+        return false;
     }
 
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
      */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("EHLO");
-        implCommands.add("HELO");
-        implCommands.add("RCPT");
+    protected String getJunkScoreLogString(SMTPSession session) {
+        return "Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved. Add junkScore: " + getScore();
+    }
 
-        return implCommands;
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getRejectLogString(SMTPSession session) {
+        return getResponseString(session);
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getResponseString(SMTPSession session) {
+        String responseString = "501 "
+            + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                    DSNStatus.DELIVERY_INVALID_ARG)
+            + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved";
+        return responseString;
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getScoreName()
+     */
+    protected String getScoreName() {
+        return "ResolvableEhloHeloCheck";
+    }
+    
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScore(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected JunkScore getJunkScore(SMTPSession session) {
+        return (JunkScore) session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION);
     }
 
 }

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java Fri Nov 17 04:00:02 2006
@@ -19,101 +19,14 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
-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.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.james.services.DNSServer;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
 import org.apache.james.util.mail.dsn.DSNStatus;
-import org.apache.mailet.MailAddress;
 
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-
-public class ReverseEqualsEhloHeloHandler extends AbstractLogEnabled implements
-        CommandHandler, Configurable, Serviceable {
-
-    public final static String BAD_EHLO_HELO = "BAD_EHLO_HELO";
-
-    private boolean checkAuthNetworks = false;
-
-    private boolean checkAuthUsers = false;
-
-    private DNSServer dnsServer = null;
-
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
-     */
-    public void configure(Configuration handlerConfiguration)
-            throws ConfigurationException {
-        Configuration configRelay = handlerConfiguration.getChild(
-                "checkAuthNetworks", false);
-        if (configRelay != null) {
-            setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
-        }
-
-        Configuration configAuthUser = handlerConfiguration.getChild(
-                "checkAuthUsers", false);
-        if (configAuthUser != null) {
-            setCheckAuthUsers(configAuthUser.getValueAsBoolean(false));
-        }
-    }
 
-    /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
-     */
-    public void service(ServiceManager serviceMan) throws ServiceException {
-        setDnsServer((DNSServer) serviceMan.lookup(DNSServer.ROLE));
-    }
-
-    /**
-     * Set to true if AuthNetworks should be included in the EHLO check
-     * 
-     * @param checkAuthNetworks
-     *            Set to true to enable
-     */
-    public void setCheckAuthNetworks(boolean checkAuthNetworks) {
-        this.checkAuthNetworks = checkAuthNetworks;
-    }
-
-    /**
-     * Set to true if Auth users should be included in the EHLO/HELO check
-     * 
-     * @param checkAuthUsers
-     *            Set to true to enable
-     */
-    public void setCheckAuthUsers(boolean checkAuthUsers) {
-        this.checkAuthUsers = checkAuthUsers;
-    }
+import java.net.UnknownHostException;
 
-    /**
-     * Set the DNSServer
-     * 
-     * @param dnsServer
-     *            The DNSServer
-     */
-    public void setDnsServer(DNSServer dnsServer) {
-        this.dnsServer = dnsServer;
-    }
 
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        String argument = session.getCommandArgument();
-        String command = session.getCommandName();
-        if (command.equals("HELO") || command.equals("EHLO")) {
-            checkEhloHelo(session, argument);
-        } else if (command.equals("RCPT")) {
-            reject(session, argument);
-        }
-    }
+public class ReverseEqualsEhloHeloHandler extends ResolvableEhloHeloHandler {
 
     /**
      * Method which get called on HELO/EHLO
@@ -121,7 +34,7 @@
      * @param session The SMTPSession
      * @param argument The argument
      */
-    private void checkEhloHelo(SMTPSession session, String argument) {
+    protected void checkEhloHelo(SMTPSession session, String argument) {
         /**
          * don't check if the ip address is allowed to relay. Only check if it
          * is set in the config. ed.
@@ -144,49 +57,38 @@
                 session.getState().put(BAD_EHLO_HELO, "true");
         }
     }
-
+    
     /**
-     * Method which get called on RCPT
-     * 
-     * @param session The SMTPSession
-     * @param argument The argument
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
      */
-    private void reject(SMTPSession session, String argument) {
-        MailAddress rcpt = (MailAddress) session.getState().get(
-                SMTPSession.CURRENT_RECIPIENT);
-
-        // not reject it
-        if (session.getState().get(BAD_EHLO_HELO) == null
-                || rcpt.getUser().equalsIgnoreCase("postmaster")
-                || rcpt.getUser().equalsIgnoreCase("abuse"))
-            return;
-
-        // Check if the client was authenticated
-        if (!(session.isAuthRequired() && session.getUser() != null && !checkAuthUsers)) {
-            String responseString = "501 "
-                    + DSNStatus.getStatus(DSNStatus.PERMANENT,
-                            DSNStatus.DELIVERY_INVALID_ARG) + " Provided EHLO "
-                    + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " not equal reverse of "
-                    + session.getRemoteIPAddress();
-
-            session.writeResponse(responseString);
-            getLogger().info(responseString);
-
-            // After this filter match we should not call any other handler!
-            session.setStopHandlerProcessing(true);
-        }
+    protected String getJunkScoreLogString(SMTPSession session) {
+        return "Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " not equal reverse of "
+                    + session.getRemoteIPAddress() + ". Add junkScore: " + getScore();
     }
 
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
      */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("EHLO");
-        implCommands.add("HELO");
-        implCommands.add("RCPT");
+    protected String getRejectLogString(SMTPSession session) {
+        return getResponseString(session);
+    }
 
-        return implCommands;
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
+     */
+    protected String getResponseString(SMTPSession session) {
+        String responseString = "501 "
+            + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                    DSNStatus.DELIVERY_INVALID_ARG)
+            + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " not equal reverse of "
+                    + session.getRemoteIPAddress();
+        return responseString;
     }
 
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getScoreName()
+     */
+    protected String getScoreName() {
+        return "ReverseEqualsEhloHeloCheck";
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java Fri Nov 17 04:00:02 2006
@@ -33,11 +33,12 @@
 import org.apache.james.services.DNSServer;
 import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.MailAddress;
 
 public class ValidSenderDomainHandler
-    extends AbstractActionHandler
+    extends AbstractJunkHandler
     implements CommandHandler, Configurable, Serviceable {
     
     private boolean checkAuthClients = false;
@@ -84,7 +85,14 @@
     }
     
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#check(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     */
+    public void onCommand(SMTPSession session) {
+        doProcessing(session);
+    }
+    
+    /**
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
      */
     protected boolean check(SMTPSession session) {
         MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
@@ -96,8 +104,11 @@
          * don't check if the ip address is allowed to relay. Only check if it is set in the config. 
          */
         if (checkAuthClients || !session.isRelayingAllowed()) {
+            Collection records;
+            
+                
             // try to resolv the provided domain in the senderaddress. If it can not resolved do not accept it.
-            Collection records = dnsServer.findMXRecords(senderAddress.getHost());
+            records = dnsServer.findMXRecords(senderAddress.getHost());
             if (records == null || records.size() == 0) {
                 return true;
             }
@@ -116,23 +127,23 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScoreLogString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getJunkScoreLogString(SMTPSession session) {
-        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
-        String response = "Sender " + senderAddress + " contains a domain with no valid MX records.";
+       MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
+        String response = "Sender " + senderAddress + " contains a domain with no valid MX records. Add Junkscore: " + getScore();
         return response;
     }
     
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getRejectLogString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getRejectLogString(SMTPSession session) {
         return getResponseString(session);
     }
     
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getResponseString(org.apache.james.smtpserver.SMTPSession)
      */
     protected String getResponseString(SMTPSession session) {
         MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
@@ -141,7 +152,7 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractActionHandler#getScoreName()
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getScoreName()
      */
     protected String getScoreName() {
         return "ValidSenderDomainCheck";

Modified: james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java Fri Nov 17 04:00:02 2006
@@ -28,6 +28,8 @@
 import java.util.List;
 import java.util.Map;
 
+import javax.mail.internet.ParseException;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -36,6 +38,9 @@
 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;
 
@@ -117,7 +122,7 @@
     /**
      * Setup mocked smtpsession
      */
-    private void setupMockedSMTPSession() {
+    private void setupMockedSMTPSession(final MailAddress rcpt) {
         mockedSMTPSession = new AbstractSMTPSession() {
             HashMap state = new HashMap();
             HashMap connectionState = new HashMap();
@@ -128,6 +133,7 @@
             }
 
             public Map getState() {
+            state.put(SMTPSession.CURRENT_RECIPIENT, rcpt);
                 return state;
             }
 
@@ -163,12 +169,12 @@
     }
 
     // ip is blacklisted and has txt details
-    public void testBlackListedTextPresent() {
+    public void testBlackListedTextPresent() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
 
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
         rbl.setDNSServer(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
@@ -180,12 +186,12 @@
     }
 
     // ip is blacklisted and has txt details but we don'T want to retrieve the txt record
-    public void testGetNoDetail() {
+    public void testGetNoDetail() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
 
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
         rbl.setDNSServer(mockedDnsServer);
 
         rbl.setBlacklist(new String[] { "bl.spamcop.net." });
@@ -196,13 +202,13 @@
     }
 
     // ip is allowed to relay
-    public void testRelayAllowed() {
+    public void testRelayAllowed() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
 
         setRelayingAllowed(true);
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
 
         rbl.setDNSServer(mockedDnsServer);
 
@@ -214,12 +220,12 @@
     }
 
     // ip not on blacklist
-    public void testNotBlackListed() {
+    public void testNotBlackListed() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
         setRemoteIp("192.168.0.1");
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
 
         rbl.setDNSServer(mockedDnsServer);
 
@@ -231,12 +237,12 @@
     }
 
     // ip on blacklist without txt details
-    public void testBlackListedNoTxt() {
+    public void testBlackListedNoTxt() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
         setRemoteIp("127.0.0.3");
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
 
         rbl.setDNSServer(mockedDnsServer);
 
@@ -248,12 +254,12 @@
     }
 
     // ip on whitelist
-    public void testWhiteListed() {
+    public void testWhiteListed() throws ParseException {
         DNSRBLHandler rbl = new DNSRBLHandler();
 
         ContainerUtil.enableLogging(rbl, new MockLogger());
         setRemoteIp("127.0.0.2");
-        setupMockedSMTPSession();
+        setupMockedSMTPSession(new MailAddress("any@domain"));
 
         rbl.setDNSServer(mockedDnsServer);
 
@@ -274,6 +280,27 @@
         }
         
         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);
+        assertEquals("Score stored",((JunkScore) mockedSMTPSession.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).getStoredScore("DNSRBLCheck"), 20.0, 0d);
     }
 
 }

Modified: james/server/trunk/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java?view=diff&rev=476116&r1=476115&r2=476116
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java Fri Nov 17 04:00:02 2006
@@ -35,6 +35,8 @@
 import org.apache.james.services.DNSServer;
 import org.apache.james.smtpserver.core.filter.fastfail.ResolvableEhloHeloHandler;
 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;
 
 public class ResolvableEhloHeloHandlerTest extends TestCase {
@@ -125,7 +127,7 @@
             public InetAddress getByName(String host) throws UnknownHostException {
                 if (host.equals(INVALID_HOST)) 
                     throw new UnknownHostException();
-                return null;
+                return InetAddress.getLocalHost();
             }
         };
         
@@ -309,5 +311,31 @@
         assertNull("Not Reject", getResponse());
         
         assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
+    }
+    
+    public void testAddJunkScoreInvalidHelo() throws ParseException {
+        SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,new MailAddress("test@localhost"));
+        session.getConnectionState().put(JunkScore.JUNK_SCORE_SESSION, new JunkScoreImpl());
+        ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
+        
+        ContainerUtil.enableLogging(handler,new MockLogger());
+        
+        handler.setDnsServer(setupMockDNSServer());
+        handler.setAction("junkScore");
+        handler.setScore(20);
+        
+        // helo
+        setCommand(HELO);
+        handler.onCommand(session);
+        assertNotNull("Invalid HELO",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
+        
+        
+        // rcpt
+        setCommand(RCPT);
+        handler.onCommand(session);
+        assertNull("Not Reject", getResponse());
+        
+        assertFalse("Don'T stop handler processing",session.getStopHandlerProcessing());
+        assertEquals("JunkScore added", ((JunkScore) session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).getStoredScore("ResolvableEhloHeloCheck"), 20.0, 0d);
     }
 }



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