james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r802017 [2/3] - in /james/server/sandbox/active/smtp_refactor/smtpserver-function/src: main/java/org/apache/james/smtpserver/core/ main/java/org/apache/james/smtpserver/core/filter/ main/java/org/apache/james/smtpserver/core/filter/fastfail...
Date Fri, 07 Aug 2009 14:11:33 GMT
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.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/MaxRcptHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java Fri Aug  7 14:11:31 2009
@@ -21,19 +21,18 @@
 
 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.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
+import org.apache.mailet.MailAddress;
 
 
-public class MaxRcptHandler extends AbstractJunkHandler implements
-        CommandHandler, Configurable {
+public class MaxRcptHandler extends AbstractLogEnabled implements
+        PostRcptListener, Configurable {
 
     private int maxRcpt = 0;
 
@@ -50,8 +49,6 @@
             throw new ConfigurationException(
                     "Please set the maxRcpt configuration value");
         }
-        
-        super.configure(handlerConfiguration);
     }
 
     /**
@@ -65,41 +62,16 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        doProcessing(session);
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
      */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("RCPT");
-        
-        return implCommands;
-    }
-
-    /**
-     * @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
-        return ((session.getRcptCount() + 1) > maxRcpt);
-    }
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
+		  // check if the max recipients has reached
+        if((session.getRcptCount() + 1) > maxRcpt) {
+        	return "452 "  + DSNStatus.getStatus(DSNStatus.NETWORK, DSNStatus.DELIVERY_TOO_MANY_REC)
+            	+ " Requested action not taken: max recipients reached";
+        }
+    	return null;
 
-    /**
-     * @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.setRejectResponseString("452 "  + 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/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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -19,28 +19,29 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
+import java.net.UnknownHostException;
+
 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.api.dnsservice.DNSService;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostEhloListener;
+import org.apache.james.smtpserver.core.PostHeloListener;
+import org.apache.james.smtpserver.core.PostRcptListener;
 import org.apache.james.smtpserver.junkscore.JunkScore;
 import org.apache.mailet.MailAddress;
 
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
-
 /**
  * This CommandHandler can be used to reject not resolvable EHLO/HELO
  */
-public class ResolvableEhloHeloHandler extends AbstractJunkHandler implements
-        CommandHandler, Configurable, Serviceable {
+public class ResolvableEhloHeloHandler extends AbstractLogEnabled implements
+        Configurable, Serviceable,PostEhloListener,PostHeloListener,PostRcptListener{
 
     public final static String BAD_EHLO_HELO = "BAD_EHLO_HELO";
 
@@ -67,7 +68,6 @@
             setCheckAuthUsers(configAuthUser.getValueAsBoolean(false));
         }
         
-        super.configure(handlerConfiguration);
     }
 
     /**
@@ -107,30 +107,20 @@
         this.dnsServer = dnsServer;
     }
 
+
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScore(org.apache.james.smtpserver.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")) {
-            doProcessing(session);
-        }
+    protected JunkScore getJunkScore(SMTPSession session) {
+        return (JunkScore) session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION);
     }
 
     /**
-     * Check if EHLO/HELO is resolvable
-     * 
-     * @param session
-     *            The SMTPSession
-     * @param argument
-     *            The argument
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostEhloListener#onEhlo(org.apache.james.smtpserver.SMTPSession, java.lang.String)
      */
-    protected void checkEhloHelo(SMTPSession session, String argument) {
-        /**
+	public String onEhlo(SMTPSession session, String heloName) {
+		 /**
          * don't check if the ip address is allowed to relay. Only check if it
          * is set in the config.
          */
@@ -138,71 +128,39 @@
             // try to resolv the provided helo. If it can not resolved do not
             // accept it.
             try {
-                dnsServer.getByName(argument);
+                dnsServer.getByName(heloName);
             } catch (UnknownHostException e) {
                 session.getState().put(BAD_EHLO_HELO, "true");
             }
         }
-    }
-
-
-    /**
-     * @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)
-     */
-    protected boolean check(SMTPSession session) {
-    
-        MailAddress rcpt = (MailAddress) session.getState().get(
-                SMTPSession.CURRENT_RECIPIENT);
+        return null;
+	}
 
+	/**
+	 * (non-Javadoc)
+	 * @see org.apache.james.smtpserver.core.PostHeloListener#onHelo(org.apache.james.smtpserver.SMTPSession, java.lang.String)
+	 */
+	public String onHelo(SMTPSession session, String heloName) {
+		return onEhlo(session, heloName);
+	}
+
+	/**
+	 * (non-Javadoc)
+	 * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
+	 */
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
         // not reject it
         if (session.getState().get(BAD_EHLO_HELO) == null
-                || rcpt.getUser().equalsIgnoreCase("postmaster")
-                || rcpt.getUser().equalsIgnoreCase("abuse"))
-            return false;
+                || rcpt.getLocalPart().equalsIgnoreCase("postmaster")
+                || rcpt.getLocalPart().equalsIgnoreCase("abuse"))
+            return null;
 
         // Check if the client was authenticated
         if (!(session.isAuthRequired() && session.getUser() != null && !checkAuthUsers)) {
-            return true;
+            return "501 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG)
+                + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved";
         }
-        return false;
-    }
-
-
-    /**
-     * @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#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
-     */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        JunkHandlerData data = new JunkHandlerData();
-        
-        data.setJunkScoreLogString("Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved. Add junkScore: " + getScore());
-        data.setRejectLogString("501 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG)
-                + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved");
-    
-        
-        data.setRejectResponseString("501 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG)
-                + " Provided EHLO/HELO " + session.getState().get(SMTPSession.CURRENT_HELO_NAME) + " can not resolved");
-
-        data.setScoreName("ResolvableEhloHeloCheck");
-        return data;
-    }
+		return null;
+	}
 
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -21,21 +21,17 @@
 
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.mailet.MailAddress;
 
 
 import java.net.UnknownHostException;
 
 
 public class ReverseEqualsEhloHeloHandler extends ResolvableEhloHeloHandler {
-
-    /**
-     * Method which get called on HELO/EHLO
-     * 
-     * @param session The SMTPSession
-     * @param argument The argument
-     */
-    protected void checkEhloHelo(SMTPSession session, String argument) {
-        /**
+    
+    @Override
+	public String onEhlo(SMTPSession session, String heloName) {
+    	 /**
          * don't check if the ip address is allowed to relay. Only check if it
          * is set in the config. ed.
          */
@@ -45,7 +41,7 @@
                 // get reverse entry
                 String reverse = dnsServer.getHostName(dnsServer.getByName(
                         session.getRemoteIPAddress()));
-                if (!argument.equals(reverse)) {
+                if (!heloName.equals(reverse)) {
                     badHelo = true;
                 }
             } catch (UnknownHostException e) {
@@ -56,39 +52,24 @@
             if (badHelo)
                 session.getState().put(BAD_EHLO_HELO, "true");
         }
-    }
-    
-    /**
-     * @see JunkHandlerData#getJunkScoreLogString()
-     */
-    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 JunkHandlerData#getRejectLogString()
-     */
-    protected String getRejectLogString(SMTPSession session) {
-        return getResponseString(session);
-    }
-
-    /**
-     * @see JunkHandlerData#getRejectResponseString()
-     */
-    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 null;
+	}
+
+	@Override
+	public String onHelo(SMTPSession session, String heloName) {
+		return onEhlo(session, heloName);
+	}
+
+	@Override
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
+		String responseString = null;
+		if (session.getState().containsKey(BAD_EHLO_HELO)) {
+			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 JunkHandlerData#getScoreName()
-     */
-    protected String getScoreName() {
-        return "ReverseEqualsEhloHeloCheck";
-    }
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -21,21 +21,20 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
-import java.util.ArrayList;
-import java.util.Collection;
-
 import org.apache.avalon.framework.activity.Initializable;
 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.dsn.DSNStatus;
-import org.apache.james.jspf.impl.DefaultSPF;
-import org.apache.james.jspf.impl.SPF;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.exceptions.SPFErrorConstants;
 import org.apache.james.jspf.executor.SPFResult;
-import org.apache.james.smtpserver.CommandHandler;
-import org.apache.james.smtpserver.MessageHandler;
+import org.apache.james.jspf.impl.DefaultSPF;
+import org.apache.james.jspf.impl.SPF;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostDataListener;
+import org.apache.james.smtpserver.core.PostMailListener;
+import org.apache.james.smtpserver.core.PostRcptListener;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
@@ -51,8 +50,8 @@
  * <checkAuthNetworks>false&lt/checkAuthNetworks> 
  * </handler>
  */
-public class SPFHandler extends AbstractJunkHandler implements CommandHandler,
-        MessageHandler,Initializable {
+public class SPFHandler extends AbstractLogEnabled implements 
+        PostDataListener,PostMailListener,PostRcptListener,Initializable {
 
     public static final String SPF_BLOCKLISTED = "SPF_BLOCKLISTED";
 
@@ -100,9 +99,6 @@
         if (configRelay != null) {
             setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
         }
-        
-        super.configure(handlerConfiguration);
-
     }
     
 
@@ -156,150 +152,6 @@
         this.checkAuthNetworks = checkAuthNetworks;
     }
 
-    /**
-     * Calls the SPFcheck
-     * 
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        if (session.getCommandName().equals("MAIL")) {
-            doSPFCheck(session);
-        } else if (session.getCommandName().equals("RCPT")) {
-            doProcessing(session);
-        }
-    }
-
-    /**
-     * Calls a SPF check
-     * 
-     * @param session
-     *            SMTP session object
-     */
-    private void doSPFCheck(SMTPSession session) {
-
-        MailAddress sender = (MailAddress) session.getState().get(
-                SMTPSession.SENDER);
-        String heloEhlo = (String) session.getState().get(
-                SMTPSession.CURRENT_HELO_NAME);
-
-        // We have no Sender or HELO/EHLO yet return false
-        if (sender == null || heloEhlo == null) {
-            getLogger().info("No Sender or HELO/EHLO present");
-        } else {
-            // No checks for authorized cliends
-            if (session.isRelayingAllowed() && checkAuthNetworks == false) {
-                getLogger().info(
-                        "Ipaddress " + session.getRemoteIPAddress()
-                                + " is allowed to relay. Don't check it");
-            } else {
-
-                String ip = session.getRemoteIPAddress();
-
-                SPFResult result = spf
-                        .checkSPF(ip, sender.toString(), heloEhlo);
-
-                String spfResult = result.getResult();
-
-                String explanation = "Blocked - see: "
-                        + result.getExplanation();
-
-                // Store the header
-                session.getState().put(SPF_HEADER, result.getHeaderText());
-
-                getLogger().info(
-                        "Result for " + ip + " - " + sender + " - " + heloEhlo
-                                + " = " + spfResult);
-
-                // Check if we should block!
-                if ((spfResult.equals(SPFErrorConstants.FAIL_CONV))
-                        || (spfResult.equals(SPFErrorConstants.SOFTFAIL_CONV) && blockSoftFail)
-                        || (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV) && blockPermError)) {
-
-                    if (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV)) {
-                        explanation = "Block caused by an invalid SPF record";
-                    }
-                    session.getState().put(SPF_DETAIL, explanation);
-                    session.getState().put(SPF_BLOCKLISTED, "true");
-
-                } else if (spfResult.equals(SPFErrorConstants.TEMP_ERROR_CONV)) {
-                    session.getState().put(SPF_TEMPBLOCKLISTED, "true");
-                }
-            }
-        }
-
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection commands = new ArrayList();
-        commands.add("MAIL");
-        commands.add("RCPT");
-
-        return commands;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
-     */
-    public void onMessage(SMTPSession session) {
-        Mail mail = session.getMail();
-
-        // Store the spf header as attribute for later using
-        mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session.getState().get(SPF_HEADER));
-    }
-    
-
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
-     */
-    protected boolean check(SMTPSession session) {
-        MailAddress recipientAddress = (MailAddress) session.getState().get(
-                SMTPSession.CURRENT_RECIPIENT);
-        String blocklisted = (String) session.getState().get(SPF_BLOCKLISTED);
-        String tempBlocklisted = (String) session.getState().get(SPF_TEMPBLOCKLISTED);
-
-        // Check if the recipient is postmaster or abuse..
-        if (recipientAddress != null
-                && (recipientAddress.getUser().equalsIgnoreCase("postmaster")
-                        || recipientAddress.getUser().equalsIgnoreCase("abuse") || ((session
-                        .isAuthRequired() && session.getUser() != null)))) {
-            
-
-            return false;
-        } else {
-            // Check if session is blocklisted
-            if ((blocklisted != null && blocklisted.equals("true")) || tempBlocklisted != null) {
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
-     */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        String blocklisted = (String) session.getState().get(SPF_BLOCKLISTED);
-        String blocklistedDetail = (String) session.getState().get(SPF_DETAIL);
-        String tempBlocklisted = (String) session.getState().get(SPF_TEMPBLOCKLISTED);
-        JunkHandlerData data = new JunkHandlerData();
-
-        // Check if session is blocklisted
-        if (blocklisted != null && blocklisted.equals("true")) {
-            data.setRejectResponseString("530 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " "
-                    + blocklistedDetail);
-        } else if (tempBlocklisted != null
-                && tempBlocklisted.equals("true")) {
-            data.setRejectResponseString("451 " + DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER) + " "
-                    + "Temporarily rejected: Problem on SPF lookup");
-        }
-        data.setJunkScoreLogString("Not match SPF-Record. Add junkScore: " + getScore());
-        data.setRejectLogString("Not match SPF-Record. Reject email");
-        data.setScoreName("SPFCheck");
-        return data;
-    }
     
     /**
      * Inner class to provide a wrapper for loggin to avalon
@@ -429,4 +281,106 @@
 
     }
 
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostDataListener#onData(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.Mail)
+     */
+	public String onData(SMTPSession session, Mail mail) {
+		// Store the spf header as attribute for later using
+		mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session
+				.getState().get(SPF_HEADER));
+
+		return null;
+	}
+
+
+	/**
+	 * (non-Javadoc)
+	 * @see org.apache.james.smtpserver.core.PostMailListener#onMail(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
+	 */
+	public String onMail(SMTPSession session, MailAddress sender) {
+
+        String heloEhlo = (String) session.getState().get(
+                SMTPSession.CURRENT_HELO_NAME);
+
+        // We have no Sender or HELO/EHLO yet return false
+        if (sender == null || heloEhlo == null) {
+            getLogger().info("No Sender or HELO/EHLO present");
+        } else {
+            // No checks for authorized cliends
+            if (session.isRelayingAllowed() && checkAuthNetworks == false) {
+                getLogger().info(
+                        "Ipaddress " + session.getRemoteIPAddress()
+                                + " is allowed to relay. Don't check it");
+            } else {
+
+                String ip = session.getRemoteIPAddress();
+
+                SPFResult result = spf
+                        .checkSPF(ip, sender.toString(), heloEhlo);
+
+                String spfResult = result.getResult();
+
+                String explanation = "Blocked - see: "
+                        + result.getExplanation();
+
+                // Store the header
+                session.getState().put(SPF_HEADER, result.getHeaderText());
+
+                getLogger().info(
+                        "Result for " + ip + " - " + sender + " - " + heloEhlo
+                                + " = " + spfResult);
+
+                // Check if we should block!
+                if ((spfResult.equals(SPFErrorConstants.FAIL_CONV))
+                        || (spfResult.equals(SPFErrorConstants.SOFTFAIL_CONV) && blockSoftFail)
+                        || (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV) && blockPermError)) {
+
+                    if (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV)) {
+                        explanation = "Block caused by an invalid SPF record";
+                    }
+                    session.getState().put(SPF_DETAIL, explanation);
+                    session.getState().put(SPF_BLOCKLISTED, "true");
+
+                } else if (spfResult.equals(SPFErrorConstants.TEMP_ERROR_CONV)) {
+                    session.getState().put(SPF_TEMPBLOCKLISTED, "true");
+                }
+            }
+        }
+        return null;
+	}
+
+
+	/**
+	 * (non-Javadoc)
+	 * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
+	 */
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
+		MailAddress recipientAddress = (MailAddress) session.getState().get(
+                SMTPSession.CURRENT_RECIPIENT);
+        String blocklisted = (String) session.getState().get(SPF_BLOCKLISTED);
+        String tempBlocklisted = (String) session.getState().get(SPF_TEMPBLOCKLISTED);
+        String blocklistedDetail = (String) session.getState().get(SPF_DETAIL);
+        // Check if the recipient is postmaster or abuse..
+        if (recipientAddress != null
+                && (recipientAddress.getUser().equalsIgnoreCase("postmaster")
+                        || recipientAddress.getUser().equalsIgnoreCase("abuse") || ((session
+                        .isAuthRequired() && session.getUser() != null)))) {
+            
+
+            return null;
+        } else {
+            	 // Check if session is blocklisted
+                if (blocklisted != null && blocklisted.equals("true")) {
+                    return "530 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " "
+                            + blocklistedDetail;
+                } else if (tempBlocklisted != null
+                        && tempBlocklisted.equals("true")) {
+                    return "451 " + DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER) + " "
+                            + "Temporarily rejected: Problem on SPF lookup";
+                          }
+        }
+        return null;
+	}
+
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.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/SpamAssassinHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java Fri Aug  7 14:11:31 2009
@@ -30,8 +30,8 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.MessageHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostDataListener;
 import org.apache.james.util.scanner.SpamAssassinInvoker;
 import org.apache.mailet.Mail;
 
@@ -52,7 +52,7 @@
  * <checkAuthNetworks>false</checkAuthNetworks> </handler>
  */
 public class SpamAssassinHandler extends AbstractLogEnabled implements
-        MessageHandler, Configurable {
+        PostDataListener, Configurable {
 
     /**
      * The port spamd is listen on
@@ -139,18 +139,14 @@
 
     }
 
-    /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
-     */
-    public void onMessage(SMTPSession session) {
-
+	public String onData(SMTPSession session, Mail mail) {
+		String responseString = null;
         // Not scan the message if relaying allowed
         if (session.isRelayingAllowed() && !checkAuthNetworks) {
-            return;
+            return null;
         }
 
         try {
-            Mail mail = session.getMail();
             MimeMessage message = mail.getMessage();
             SpamAssassinInvoker sa = new SpamAssassinInvoker(spamdHost,
                     spamdPort);
@@ -174,7 +170,7 @@
                     // if the hits are bigger the rejectionHits reject the
                     // message
                     if (spamdRejectionHits <= hits) {
-                        String responseString = "554 "
+                        responseString = "554 "
                                 + DSNStatus.getStatus(DSNStatus.PERMANENT,
                                         DSNStatus.SECURITY_OTHER)
                                 + " This message reach the spam hits treshold. Please contact the Postmaster if the email is not SPAM. Message rejected";
@@ -189,10 +185,7 @@
                                                 + spamdRejectionHits
                                                 + " hits: " + hits);
                         getLogger().info(buffer.toString());
-                        session.writeResponse(responseString);
-
-                        // Message reject .. abort it!
-                        session.abortMessage();
+                       
                     }
                 } catch (NumberFormatException e) {
                     // hits unknown
@@ -201,6 +194,7 @@
         } catch (MessagingException e) {
             getLogger().error(e.getMessage());
         }
+		return responseString;
+	}
 
-    }
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.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/SupressDuplicateRcptHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java Fri Aug  7 14:11:31 2009
@@ -22,48 +22,41 @@
 
 package org.apache.james.smtpserver.core.filter.fastfail;
 
-import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
 import org.apache.mailet.MailAddress;
 
 /**
  * 
  * This handler can be used to just ignore duplicated recipients. 
  */
-public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements CommandHandler {
+public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements PostRcptListener {
 
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection c = new ArrayList();
-        c.add("RCPT");
-    
-        return c;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
-        Collection rcptList = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
-    
-        // Check if the recipient is allready in the rcpt list
-        if(rcptList != null && rcptList.contains(rcpt)) {
-            StringBuffer responseBuffer = new StringBuffer();
-        
-            responseBuffer.append("250 " + DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID) + " Recipient <")
-                          .append(rcpt.toString()).append("> OK");
-            session.writeResponse(responseBuffer.toString());
-            session.setStopHandlerProcessing(true);
-            
-            getLogger().debug("Duplicate recipient not add to recipient list: " + rcpt.toString());
-        }
-    }
+   
+	/**
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession,
+	 *      org.apache.mailet.MailAddress)
+	 */
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
+		Collection rcptList = (Collection) session.getState().get(
+				SMTPSession.RCPT_LIST);
+
+		// Check if the recipient is allready in the rcpt list
+		if (rcptList != null && rcptList.contains(rcpt)) {
+			StringBuffer responseBuffer = new StringBuffer();
+
+			responseBuffer.append("250 " + DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID) + " Recipient <")
+					.append(rcpt.toString()).append("> OK");
+
+			getLogger().debug("Duplicate recipient not add to recipient list: "+ rcpt.toString());
+			return responseBuffer.toString();
+		}
+		return null;
+	}
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.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/TarpitHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java Fri Aug  7 14:11:31 2009
@@ -21,18 +21,16 @@
 
 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.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
+import org.apache.mailet.MailAddress;
 
 public class TarpitHandler extends AbstractLogEnabled implements
-        CommandHandler, Configurable {
+        PostRcptListener, Configurable {
 
     private int tarpitRcptCount = 0;
 
@@ -96,10 +94,12 @@
         Thread.sleep((long) timeInMillis);
     }
 
+
     /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
      */
-    public void onCommand(SMTPSession session) {
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
 
         int rcptCount = 0;
         rcptCount = session.getRcptCount();
@@ -111,15 +111,6 @@
             } catch (InterruptedException e) {
             }
         }
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("RCPT");
-        
-        return implCommands;
-    }
+        return null;
+	}
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -38,19 +38,21 @@
 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.api.dnsservice.DNSService;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.MessageHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostDataListener;
 import org.apache.james.smtpserver.urirbl.URIScanner;
+import org.apache.mailet.Mail;
 
 /**
  * Extract domains from message and check against URIRBLServer. For more informations see http://www.surbl.org
  */
-public class URIRBLHandler extends AbstractJunkHandler implements MessageHandler,
+public class URIRBLHandler extends AbstractLogEnabled implements PostDataListener,
     Serviceable {
 
     private DNSService dnsServer;
@@ -113,8 +115,6 @@
         if (configRelay != null) {
             setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
         }
-        
-        super.configure(arg0);
 
     }
    
@@ -155,14 +155,7 @@
     public void setGetDetail(boolean getDetail) {
         this.getDetail = getDetail;
     }
-    
-    /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
-     */
-    public void onMessage(SMTPSession session) {
-        doProcessing(session);
-    }
-
+ 
     /**
      * Recursively scans all MimeParts of an email for domain strings. Domain
      * strings that are found are added to the supplied HashSet.
@@ -201,95 +194,84 @@
         return domains;
     }
 
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
-     */
-    protected boolean check(SMTPSession session) {
-        MimeMessage message;
-        
-        // Not scan the message if relaying allowed
-        if (session.isRelayingAllowed() && !checkAuthNetworks) {
-            return false;
-        }
-        
-        try {
-            message = session.getMail().getMessage();
-
-            HashSet domains = scanMailForDomains(message);
-
-            Iterator fDomains = domains.iterator();
-
-            while (fDomains.hasNext()) {
-                Iterator uRbl = uriRbl.iterator();
-                String target = fDomains.next().toString();
-                
-                while (uRbl.hasNext()) {
-                    try {
-                        String uRblServer = uRbl.next().toString();
-                        String address = target + "." + uRblServer;
-                        
-                        if (getLogger().isDebugEnabled()) {
-                            getLogger().debug("Lookup " + address);
-                        }
-                        
-                        dnsServer.getByName(address);
-            
-                        // store server name for later use
-                        session.getState().put(URBLSERVER, uRblServer);
-                        session.getState().put(LISTED_DOMAIN,target);
-
-                        session.abortMessage();
-                        return true;
 
-                    } catch (UnknownHostException uhe) {
-                        // domain not found. keep processing
-                    }
-                }
-            }
-        } catch (MessagingException e) {
-            getLogger().error(e.getMessage());
-        } catch (IOException e) {
-            getLogger().error(e.getMessage());
-        }
-        return false;
-    }
 
     /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostDataListener#onData(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.Mail)
      */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        JunkHandlerData data = new JunkHandlerData();
-    
-        String uRblServer = (String) session.getState().get(URBLSERVER);
-        String target = (String) session.getState().get(LISTED_DOMAIN);
-        String detail = null;
-
-        // we should try to retrieve details
-        if (getDetail) {
-            Collection txt = dnsServer.findTXTRecords(target+ "." + uRblServer);
-
-            // Check if we found a txt record
-            if (!txt.isEmpty()) {
-                // Set the detail
-                detail = txt.iterator().next().toString();
-
-            }
-        }
+	public String onData(SMTPSession session, Mail mail) {
+		MimeMessage message;
 
-        if (detail != null) {
-           
-            data.setRejectResponseString("554 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER)
-                + "Rejected: message contains domain " + target + " listed by " + uRblServer +" . Details: " 
-                + detail);
-        } else {
-            data.setRejectResponseString("554 " + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER)
-                + " Rejected: message contains domain " + target + " listed by " + uRblServer);
-        }  
-
-        data.setJunkScoreLogString("Message sent by " + session.getRemoteIPAddress() + " restricted by " +  uRblServer + " because " + target + " is listed. Add junkScore: " + getScore());
-        data.setRejectLogString("Rejected: message contains domain " + target + " listed by " + uRblServer);
-        data.setScoreName("UriRBLCheck");
-        return data;
-    }
+		// Not scan the message if relaying allowed
+		if (session.isRelayingAllowed() && !checkAuthNetworks) {
+			return null;
+		}
+
+		try {
+			message = mail.getMessage();
+
+			HashSet domains = scanMailForDomains(message);
+
+			Iterator fDomains = domains.iterator();
+
+			while (fDomains.hasNext()) {
+				Iterator uRbl = uriRbl.iterator();
+				String target = fDomains.next().toString();
+
+				while (uRbl.hasNext()) {
+					try {
+						String uRblServer = uRbl.next().toString();
+						String address = target + "." + uRblServer;
+
+						if (getLogger().isDebugEnabled()) {
+							getLogger().debug("Lookup " + address);
+						}
+
+						dnsServer.getByName(address);
+
+						String detail = null;
+
+						// we should try to retrieve details
+						if (getDetail) {
+							Collection txt = dnsServer.findTXTRecords(target
+									+ "." + uRblServer);
+
+							// Check if we found a txt record
+							if (!txt.isEmpty()) {
+								// Set the detail
+								detail = txt.iterator().next().toString();
+
+							}
+						}
+
+						if (detail != null) {
+
+							return "554 "
+									+ DSNStatus.getStatus(DSNStatus.PERMANENT,
+											DSNStatus.SECURITY_OTHER)
+									+ "Rejected: message contains domain "
+									+ target + " listed by " + uRblServer
+									+ " . Details: " + detail;
+						} else {
+							return "554 "
+									+ DSNStatus.getStatus(DSNStatus.PERMANENT,
+											DSNStatus.SECURITY_OTHER)
+									+ " Rejected: message contains domain "
+									+ target + " listed by " + uRblServer;
+						}
+
+					} catch (UnknownHostException uhe) {
+						// domain not found. keep processing
+					}
+				}
+			}
+		} catch (MessagingException e) {
+			getLogger().error(e.getMessage());
+		} catch (IOException e) {
+			getLogger().error(e.getMessage());
+		}
+		return null;
+	}
 
 }

Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.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/ValidRcptHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java Fri Aug  7 14:11:31 2009
@@ -38,8 +38,8 @@
 import org.apache.james.api.vut.VirtualUserTable;
 import org.apache.james.api.vut.VirtualUserTableStore;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
 import org.apache.mailet.MailAddress;
 import org.apache.oro.text.regex.MalformedPatternException;
 import org.apache.oro.text.regex.Pattern;
@@ -49,7 +49,7 @@
 /**
  * Handler which reject invalid recipients
  */
-public class ValidRcptHandler extends AbstractLogEnabled implements CommandHandler, Configurable, Serviceable {
+public class ValidRcptHandler extends AbstractLogEnabled implements PostRcptListener, Configurable, Serviceable {
     
     private Collection recipients = new ArrayList();
     private Collection domains = new ArrayList();
@@ -159,46 +159,23 @@
         this.vut = vut;
     }
 
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection c = new ArrayList();
-        c.add("RCPT");
-            
-        return c;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        if (!session.isRelayingAllowed() && !(session.isAuthRequired() && session.getUser() != null)) {
-            checkValidRcpt(session);
-        } else {
-            getLogger().debug("Sender allowed");
-        }
-    }
-    
-    
     
+
     /**
-     * Check if the recipient should be accepted
-     * 
-     * @param session The SMTPSession
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
      */
-    private void checkValidRcpt(SMTPSession session) {
-        MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
         boolean invalidUser = true;
 
-        if (session.getConfigurationData().getUsersRepository().contains(rcpt.getUser()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getHost().toLowerCase())) {
+        if (session.getConfigurationData().getUsersRepository().contains(rcpt.getLocalPart()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getDomain().toLowerCase())) {
             invalidUser = false;
         }
 
         // check if an valid virtual mapping exists
         if (invalidUser == true  && vut == true) {
             try {
-                Collection targetString = table.getMappings(rcpt.getUser(), rcpt.getHost());
+                Collection targetString = table.getMappings(rcpt.getLocalPart(), rcpt.getDomain());
         
                 if (targetString != null && targetString.isEmpty() == false) {
                     invalidUser = false;
@@ -208,9 +185,7 @@
                 String responseString = e.getMessage();
                 
                 getLogger().info("Rejected message. Reject Message: " + responseString);
-            
-                session.writeResponse(responseString);
-                session.setStopHandlerProcessing(true);
+                return responseString;
             }
         }
         
@@ -232,9 +207,8 @@
             String responseString = "554 " + DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.toString();
         
             getLogger().info("Rejected message. Unknown user: " + rcpt.toString());
-        
-            session.writeResponse(responseString);
-            session.setStopHandlerProcessing(true);
+            return responseString;
         }
-    }
+		return null;
+	}
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -27,6 +27,7 @@
 
 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;
@@ -34,15 +35,15 @@
 import org.apache.james.api.dnsservice.TemporaryResolutionException;
 import org.apache.james.api.dnsservice.util.NetMatcher;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
 import org.apache.mailet.MailAddress;
 
 /**
  * This class can be used to reject email with bogus MX which is send from a authorized user or an authorized
  * network.
  */
-public class ValidRcptMX extends AbstractJunkHandler implements CommandHandler,
+public class ValidRcptMX extends AbstractLogEnabled implements PostRcptListener,
     Serviceable {
 
     private DNSService dnsServer = null;
@@ -78,8 +79,6 @@
             throw new ConfigurationException(
                 "Please configure at least on invalid MX network");
         }
-        
-        super.configure(arg0);
     }
 
     /**
@@ -104,21 +103,6 @@
         setDNSServer((DNSService) arg0.lookup(DNSService.ROLE));
     }
 
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection c = new ArrayList();
-        c.add("RCPT");
-        return c;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-     */
-    public void onCommand(SMTPSession session) {
-        doProcessing(session);
-    }
 
     /**
      * Set the DNSService
@@ -130,56 +114,40 @@
         this.dnsServer = dnsServer;
     }
 
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
-     */
-    protected boolean check(SMTPSession session) {
-        MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
+ 
 
-        String domain = rcpt.getHost();
 
-        // Email should be deliver local
-        if (domain.equals(LOCALHOST)) return false;
- 
-        Iterator mx = null;
-        try {
-            mx = dnsServer.findMXRecords(domain).iterator();
-        } catch (TemporaryResolutionException e1) {
-            //  TODO: Should we reject temporary ?
-        }
+	public String onRcpt(SMTPSession session, MailAddress rcpt) {
 
-        if (mx != null && mx.hasNext()) {
-            while (mx.hasNext()) {
-                String mxRec = mx.next().toString();
-
-                try {
-                    String ip = dnsServer.getByName(mxRec).getHostAddress();
-
-                    // Check for invalid MX
-                    if (bNetwork.matchInetNetwork(ip)) {
-                        return true;
-                    }
-                } catch (UnknownHostException e) {
-                    // Ignore this
-                }
-            }
-        }
-        return false;
-    }
+	        String domain = rcpt.getDomain();
 
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
-     */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
-        JunkHandlerData data = new JunkHandlerData();
-
-        data.setRejectResponseString("530" + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteIPAddress() 
-            + " for domain " + rcpt.getHost() + ". Reject email");
-       
-        data.setJunkScoreLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Add JunkScore: " + getScore());
-        data.setRejectLogString("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getHost() + ". Reject email");
-        data.setScoreName("ValidRcptMXCheck");
-        return data;
-    }
+	        // Email should be deliver local
+	        if (domain.equals(LOCALHOST)) return null;
+	 
+	        Iterator mx = null;
+	        try {
+	            mx = dnsServer.findMXRecords(domain).iterator();
+	        } catch (TemporaryResolutionException e1) {
+	            //  TODO: Should we reject temporary ?
+	        }
+
+	        if (mx != null && mx.hasNext()) {
+	            while (mx.hasNext()) {
+	                String mxRec = mx.next().toString();
+
+	                try {
+	                    String ip = dnsServer.getByName(mxRec).getHostAddress();
+
+	                    // Check for invalid MX
+	                    if (bNetwork.matchInetNetwork(ip)) {
+	                    	getLogger().info("Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getDomain() + ". Reject email");
+	                        return "530" + DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Invalid MX " + session.getRemoteIPAddress() + " for domain " + rcpt.getDomain() + ". Reject email";
+	                    }
+	                } catch (UnknownHostException e) {
+	                    // Ignore this
+	                }
+	            }
+	        }
+	        return null;
+	}
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -21,25 +21,25 @@
 
 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.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.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostMailListener;
 import org.apache.mailet.MailAddress;
 
 public class ValidSenderDomainHandler
-    extends AbstractJunkHandler
-    implements CommandHandler, Configurable, Serviceable {
+    extends AbstractLogEnabled
+    implements Configurable, Serviceable, PostMailListener {
     
     private boolean checkAuthClients = false;
     
@@ -55,8 +55,6 @@
         if(configRelay != null) {
             setCheckAuthClients(configRelay.getValueAsBoolean(false));
         }
-        
-        super.configure(handlerConfiguration);
     }
     
     /**
@@ -85,64 +83,31 @@
     }
     
     /**
-     * @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)
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.core.PostMailListener#onMail(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
      */
-    protected boolean check(SMTPSession session) {
-        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
-            
-        // null sender so return
-        if (senderAddress == null) return false;
-            
-        /**
-         * 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 = null;
-            
-                
-            // try to resolv the provided domain in the senderaddress. If it can not resolved do not accept it.
-            try {
-                records = dnsServer.findMXRecords(senderAddress.getHost());
-            } catch (TemporaryResolutionException e) {
-                // TODO: Should we reject temporary ?
-            }
-        
-            if (records == null || records.size() == 0) {
-                session.getState().remove(SMTPSession.SENDER);
-                return true;
-            }
-        }
-        return false;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
-     */
-    public Collection getImplCommands() {
-        Collection implCommands = new ArrayList();
-        implCommands.add("MAIL");
-        
-        return implCommands;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
-     */
-    public JunkHandlerData getJunkHandlerData(SMTPSession session) {
-        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
-        JunkHandlerData data = new JunkHandlerData();
-    
-        data.setRejectResponseString("501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+ " sender " + senderAddress + " contains a domain with no valid MX records");
-        data.setJunkScoreLogString("Sender " + senderAddress + " contains a domain with no valid MX records. Add Junkscore: " + getScore());
-        data.setRejectLogString("Sender " + senderAddress + " contains a domain with no valid MX records");
-        data.setScoreName("ValidSenderDomainCheck");
-        return data;
-    }
+	public String onMail(SMTPSession session, MailAddress senderAddress) {         
+	        // null sender so return
+	        if (senderAddress == null) return null;
+	            
+	        /**
+	         * 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 = null;
+	            
+	                
+	            // try to resolv the provided domain in the senderaddress. If it can not resolved do not accept it.
+	            try {
+	                records = dnsServer.findMXRecords(senderAddress.getHost());
+	            } catch (TemporaryResolutionException e) {
+	                // TODO: Should we reject temporary ?
+	            }
+	        
+	            if (records == null || records.size() == 0) {
+	                return "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+ " sender " + senderAddress + " contains a domain with no valid MX records";
+	            }
+	        }
+	        return null;
+	}
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -282,25 +282,5 @@
         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/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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -36,14 +36,11 @@
 
 
 public class MaxRcptHandlerTest extends TestCase{
-    
-    private String response;
-    
+        
     private SMTPSession setupMockedSession(final int rcptCount) {
         SMTPSession session = new AbstractSMTPSession() {
             HashMap state = new HashMap();
-            boolean processing = false;
-            
+
             public Map getState() {
                 return state;
             }
@@ -51,18 +48,8 @@
             public boolean isRelayingAllowed() {
                 return false;
             }
+
             
-            public void writeResponse(String resp) {
-                response = resp;
-            }
-            
-            public void setStopHandlerProcessing(boolean processing) {
-                this.processing = processing;
-            }
-            
-            public boolean getStopHandlerProcessing() {
-                return processing;
-            }
             
             public int getRcptCount() {
                 return rcptCount;
@@ -78,44 +65,20 @@
     
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.setAction("reject");
-        handler.setMaxRcpt(2);
-        handler.onCommand(session);
-    
-        assertNotNull("Rejected.. To many recipients", response);
-        assertTrue("Reject.. Stop processing",session.getStopHandlerProcessing());
-    }
-    
-    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);
-        handler.onCommand(session);
-    
-        assertNull("Not Rejected.. we use junkScore action", response);
-        assertFalse("Not Rejected.. we use junkScore action",session.getStopHandlerProcessing());
-        assertEquals("Get Score", ((JunkScore) session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("MaxRcptCheck"),20.0,0d);
+        assertNotNull("Rejected.. To many recipients", handler.onRcpt(session,null));
     }
     
+   
     public void testNotRejectMaxRcpt() {
         SMTPSession session = setupMockedSession(3);
         MaxRcptHandler handler = new MaxRcptHandler();
     
         ContainerUtil.enableLogging(handler,new MockLogger());
     
-        handler.setAction("reject");
         handler.setMaxRcpt(4);
-        handler.onCommand(session);
-    
-        assertNull("Not Rejected..", response);
-        assertFalse("Not stop processing",session.getStopHandlerProcessing());
+        
+        assertNull("Not Rejected..", handler.onRcpt(session,null));
     }
 
 }

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=802017&r1=802016&r2=802017&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  7 14:11:31 2009
@@ -49,39 +49,14 @@
     
     public final static String RCPT = "RCPT";
     
-    private String response = null;
     
-    private String command = null;
-    
-    public void setUp() {
-        response = null;
-        command = null;
-    }
-    
-    private String getResponse() {
-        return response;
-    }
-    
-    private void setCommand(String command) {
-        this.command = command;
-    }
-    
-    private SMTPSession setupMockSession(final String argument,
-             final boolean relaying, final boolean authRequired, final String user, final MailAddress recipient) {
+    private SMTPSession setupMockSession(final boolean relaying, final boolean authRequired, final String user) {
         
         SMTPSession session = new AbstractSMTPSession() {
 
-            boolean stop = false;
             HashMap connectionMap = new HashMap();
             HashMap map = new HashMap();
             
-            public String getCommandArgument() {
-                return argument;
-            }
-            
-            public String getCommandName() {
-                return command;
-            }
             
             public boolean isAuthRequired() {
                 return authRequired;
@@ -95,24 +70,12 @@
                 return connectionMap;
             }
             
-            public void writeResponse(String resp) {
-                response = resp;
-            }
             
             public boolean isRelayingAllowed() {
                 return relaying;
             }
-            
-            public void setStopHandlerProcessing(boolean stop) {
-                this.stop = stop;
-            }
-            
-            public boolean getStopHandlerProcessing() {
-                return stop;
-            }
-            
+
             public Map getState() {
-                map.put(SMTPSession.CURRENT_RECIPIENT, recipient);
                 return map;
             }
             
@@ -135,7 +98,7 @@
     }
     
     public void testRejectInvalidHelo() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(false,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -143,22 +106,18 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,INVALID_HOST));
         assertNotNull("Invalid HELO",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNotNull("Reject", getResponse());
+        assertNotNull("Reject",handler.onRcpt(session,new MailAddress("test@localhost")));
         
-        assertTrue("Stop handler processing",session.getStopHandlerProcessing());
     }
     
     
     public void testNotRejectValidHelo() throws ParseException {
-        SMTPSession session = setupMockSession(VALID_HOST,false,false,null,new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(false,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -166,21 +125,16 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,VALID_HOST));
         assertNull("Valid HELO",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNull("Not reject", getResponse());
-        
-        assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
+        assertNull("Not reject", handler.onRcpt(session,new MailAddress("test@localhost")));
     }
     
     public void testNotRejectInvalidHeloAuthUser() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,false,true,"valid@user",new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(false,true,"valid@user");
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -188,21 +142,16 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        handler.onHelo(session,INVALID_HOST);
         assertNotNull("Value stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNull("Not reject", getResponse());
-        
-        assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
+        assertNull("Not reject", handler.onRcpt(session,new MailAddress("test@localhost")));
     }
     
     public void testRejectInvalidHeloAuthUser() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,false,true,"valid@user",new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(false,true,"valid@user");
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -211,21 +160,17 @@
         handler.setCheckAuthUsers(true);
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        handler.onHelo(session,INVALID_HOST);
         assertNotNull("Value stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNotNull("reject", getResponse());
-        
-        assertTrue("stop handler processing",session.getStopHandlerProcessing());
+        assertNotNull("reject", handler.onRcpt(session,new MailAddress("test@localhost")));
+       
     }
     
     public void testNotRejectRelay() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,true,false,null,new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(true,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -233,21 +178,17 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,INVALID_HOST));
         assertNull("Value not stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNull("Not reject", getResponse());
+        assertNull("Not reject", handler.onRcpt(session,new MailAddress("test@localhost")));
         
-        assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
     }
     
     public void testRejectRelay() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,true,false,null,new MailAddress("test@localhost"));
+        SMTPSession session = setupMockSession(true,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -256,21 +197,17 @@
         handler.setCheckAuthNetworks(true);
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,INVALID_HOST));
         assertNotNull("Value stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNotNull("Reject", getResponse());
+        assertNotNull("Reject", handler.onRcpt(session,new MailAddress("test@localhost")));
         
-        assertTrue("Stop handler processing",session.getStopHandlerProcessing());
     }
     
     public void testNotRejectInvalidHeloPostmaster() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,new MailAddress("postmaster@localhost"));
+        SMTPSession session = setupMockSession(false,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -278,21 +215,16 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,INVALID_HOST));
         assertNotNull("stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNull("Not Reject", getResponse());
-        
-        assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
+        assertNull("Not Reject", handler.onRcpt(session,new MailAddress("postmaster@localhost")));
     }
     
     public void testNotRejectInvalidHeloAbuse() throws ParseException {
-        SMTPSession session = setupMockSession(INVALID_HOST,false,false,null,new MailAddress("abuse@localhost"));
+        SMTPSession session = setupMockSession(false,false,null);
         ResolvableEhloHeloHandler handler = new ResolvableEhloHeloHandler();
         
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -300,42 +232,12 @@
         handler.setDnsServer(setupMockDNSServer());
         
         // helo
-        setCommand(HELO);
-        handler.onCommand(session);
+        assertNull(handler.onHelo(session,INVALID_HOST));
         assertNotNull("stored",session.getState().get(ResolvableEhloHeloHandler.BAD_EHLO_HELO));
         
         
         // rcpt
-        setCommand(RCPT);
-        handler.onCommand(session);
-        assertNull("Not Reject", getResponse());
-        
-        assertFalse("Not stop handler processing",session.getStopHandlerProcessing());
+        assertNull("Not Reject", handler.onRcpt(session,new MailAddress("abuse@localhost")));
     }
     
-    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


Mime
View raw message