james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r418606 - in /james/server/sandbox/handlerapi/src: conf/ java/org/apache/james/smtpserver/ java/org/apache/james/smtpserver/basefilter/ java/org/apache/james/smtpserver/core/
Date Sun, 02 Jul 2006 15:19:02 GMT
Author: norman
Date: Sun Jul  2 08:19:01 2006
New Revision: 418606

URL: http://svn.apache.org/viewvc?rev=418606&view=rev
Log:
Move the basefilters for the commandhandlers to own classes and load them.

Added:
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/DataBaseFilterCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/EhloBaseFilterCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/HeloBaseFilterCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/MailBaseFilterCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/RcptBaseFilterCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseFilterCmdHandler.java
Modified:
    james/server/sandbox/handlerapi/src/conf/james-config.xml
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/DataCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/EhloCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/MailCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/RcptCmdHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPSession.java

Modified: james/server/sandbox/handlerapi/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/conf/james-config.xml?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/conf/james-config.xml (original)
+++ james/server/sandbox/handlerapi/src/conf/james-config.xml Sun Jul  2 08:19:01 2006
@@ -932,6 +932,7 @@
             -->            
             
             <!-- The command handler configuration -->
+            <handler class="org.apache.james.smtpserver.core.BaseFilterCmdHandler"></handler>
             <handler class="org.apache.james.smtpserver.core.BaseCmdHandler"></handler>
             
             <!-- The message handler configuration -->

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/DataCmdHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/DataCmdHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/DataCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -94,91 +94,86 @@
      * @param argument the argument passed in with the command by the SMTP client
      */
     private void doDATA(SMTPSession session, String argument) {
+        
+        if (session.getState().get(SMTPSession.STOP_HANDLER_PROCESSING) != null) return;
+        
         String responseString = null;
-        if ((argument != null) && (argument.length() > 0)) {
-            responseString = "500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with DATA command";
-            session.writeResponse(responseString);
-        }
-        if (!session.getState().containsKey(SMTPSession.SENDER)) {
-            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No sender specified";
-            session.writeResponse(responseString);
-        } else if (!session.getState().containsKey(SMTPSession.RCPT_LIST)) {
-            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No recipients specified";
-            session.writeResponse(responseString);
-        } else {
-            responseString = "354 Ok Send data ending with <CRLF>.<CRLF>";
-            session.writeResponse(responseString);
-            InputStream msgIn = new CharTerminatedInputStream(session.getInputStream(), SMTPTerminator);
-            try {
-                msgIn = new BytesReadResetInputStream(msgIn,
-                                                      session.getWatchdog(),
-                                                      session.getConfigurationData().getResetLength());
+        responseString = "354 Ok Send data ending with <CRLF>.<CRLF>";
+        session.writeResponse(responseString);
+        InputStream msgIn = new CharTerminatedInputStream(session
+                .getInputStream(), SMTPTerminator);
+        try {
+            msgIn = new BytesReadResetInputStream(msgIn, session.getWatchdog(),
+                    session.getConfigurationData().getResetLength());
 
-                // if the message size limit has been set, we'll
-                // wrap msgIn with a SizeLimitedInputStream
-                long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
-                if (maxMessageSize > 0) {
-                    if (getLogger().isDebugEnabled()) {
-                        StringBuffer logBuffer =
-                            new StringBuffer(128)
-                                    .append("Using SizeLimitedInputStream ")
-                                    .append(" with max message size: ")
-                                    .append(maxMessageSize);
-                        getLogger().debug(logBuffer.toString());
-                    }
-                    msgIn = new SizeLimitedInputStream(msgIn, maxMessageSize);
+            // if the message size limit has been set, we'll
+            // wrap msgIn with a SizeLimitedInputStream
+            long maxMessageSize = session.getConfigurationData()
+                    .getMaxMessageSize();
+            if (maxMessageSize > 0) {
+                if (getLogger().isDebugEnabled()) {
+                    StringBuffer logBuffer = new StringBuffer(128).append(
+                            "Using SizeLimitedInputStream ").append(
+                            " with max message size: ").append(maxMessageSize);
+                    getLogger().debug(logBuffer.toString());
                 }
-                // Removes the dot stuffing
-                msgIn = new DotStuffingInputStream(msgIn);
-                // Parse out the message headers
-                MailHeaders headers = new MailHeaders(msgIn);
-                headers = processMailHeaders(session, headers);
-                processMail(session, headers, msgIn);
-                headers = null;
-            } catch (MessagingException me) {
-                // Grab any exception attached to this one.
-                Exception e = me.getNextException();
-                // If there was an attached exception, and it's a
-                // MessageSizeException
-                if (e != null && e instanceof MessageSizeException) {
-                    // Add an item to the state to suppress
-                    // logging of extra lines of data
-                    // that are sent after the size limit has
-                    // been hit.
-                    session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
-                    // then let the client know that the size
-                    // limit has been hit.
-                    responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error processing message: "
-                                + e.getMessage();
-                    StringBuffer errorBuffer =
-                        new StringBuffer(256)
-                            .append("Rejected message from ")
-                            .append(session.getState().get(SMTPSession.SENDER).toString())
-                            .append(" from host ")
-                            .append(session.getRemoteHost())
-                            .append(" (")
-                            .append(session.getRemoteIPAddress())
-                            .append(") exceeding system maximum message size of ")
-                            .append(session.getConfigurationData().getMaxMessageSize());
-                    getLogger().error(errorBuffer.toString());
-                } else {
-                    responseString = "451 "+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message: "
-                                + me.getMessage();
-                    getLogger().error("Unknown error occurred while processing DATA.", me);
-                }
-                session.writeResponse(responseString);
-                return;
-            } finally {
-                if (msgIn != null) {
-                    try {
-                        msgIn.close();
-                    } catch (Exception e) {
-                        // Ignore close exception
-                    }
-                    msgIn = null;
+                msgIn = new SizeLimitedInputStream(msgIn, maxMessageSize);
+            }
+            // Removes the dot stuffing
+            msgIn = new DotStuffingInputStream(msgIn);
+            // Parse out the message headers
+            MailHeaders headers = new MailHeaders(msgIn);
+            headers = processMailHeaders(session, headers);
+            processMail(session, headers, msgIn);
+            headers = null;
+        } catch (MessagingException me) {
+            // Grab any exception attached to this one.
+            Exception e = me.getNextException();
+            // If there was an attached exception, and it's a
+            // MessageSizeException
+            if (e != null && e instanceof MessageSizeException) {
+                // Add an item to the state to suppress
+                // logging of extra lines of data
+                // that are sent after the size limit has
+                // been hit.
+                session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
+                // then let the client know that the size
+                // limit has been hit.
+                responseString = "552 "
+                        + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                DSNStatus.SYSTEM_MSG_TOO_BIG)
+                        + " Error processing message: " + e.getMessage();
+                StringBuffer errorBuffer = new StringBuffer(256).append(
+                        "Rejected message from ").append(
+                        session.getState().get(SMTPSession.SENDER).toString())
+                        .append(" from host ").append(session.getRemoteHost())
+                        .append(" (").append(session.getRemoteIPAddress())
+                        .append(") exceeding system maximum message size of ")
+                        .append(
+                                session.getConfigurationData()
+                                        .getMaxMessageSize());
+                getLogger().error(errorBuffer.toString());
+            } else {
+                responseString = "451 "
+                        + DSNStatus.getStatus(DSNStatus.TRANSIENT,
+                                DSNStatus.UNDEFINED_STATUS)
+                        + " Error processing message: " + me.getMessage();
+                getLogger().error(
+                        "Unknown error occurred while processing DATA.", me);
+            }
+            session.writeResponse(responseString);
+            return;
+        } finally {
+            if (msgIn != null) {
+                try {
+                    msgIn.close();
+                } catch (Exception e) {
+                    // Ignore close exception
                 }
+                msgIn = null;
             }
         }
+
     }
 
 

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/EhloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/EhloCmdHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/EhloCmdHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/EhloCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -20,12 +20,12 @@
 import java.util.ArrayList;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.james.util.mail.dsn.DSNStatus;
 
 /**
-  * Handles EHLO command
-  */
-public class EhloCmdHandler extends AbstractLogEnabled implements CommandHandler {
+ * Handles EHLO command
+ */
+public class EhloCmdHandler extends AbstractLogEnabled implements
+        CommandHandler {
 
     /**
      * The name of the command handled by the command handler
@@ -36,7 +36,7 @@
      * processes EHLO command
      *
      * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
-    **/
+     **/
     public void onCommand(SMTPSession session) {
         doEHLO(session, session.getCommandArgument());
     }
@@ -50,58 +50,51 @@
      * @param argument the argument passed in with the command by the SMTP client
      */
     private void doEHLO(SMTPSession session, String argument) {
-        String responseString = null;
         StringBuffer responseBuffer = session.getResponseBuffer();
-        
-     
-        if (argument == null) {
-            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Domain address required: " + COMMAND_NAME;
-            session.writeResponse(responseString);
-        } else {
-            session.resetState();
-            session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
-
-            ArrayList esmtpextensions = new ArrayList();
-
-            esmtpextensions.add(new StringBuffer(session.getConfigurationData().getHelloName())
-                .append(" Hello ")
-                .append(argument)
-                .append(" (")
-                .append(session.getRemoteHost())
-                .append(" [")
-                .append(session.getRemoteIPAddress())
-                .append("])").toString());
-
-            // Extension defined in RFC 1870
-            long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
-            if (maxMessageSize > 0) {
-                esmtpextensions.add("SIZE " + maxMessageSize);
-            }
 
-            if (session.isAuthRequired()) {
-                esmtpextensions.add("AUTH LOGIN PLAIN");
-                esmtpextensions.add("AUTH=LOGIN PLAIN");
-            }
+        if (session.getState().get(SMTPSession.STOP_HANDLER_PROCESSING) != null)
+            return;
+
+        session.resetState();
+        session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
 
-            esmtpextensions.add("PIPELINING");
-            esmtpextensions.add("ENHANCEDSTATUSCODES");
-            // see http://issues.apache.org/jira/browse/JAMES-419 
-            //esmtpextensions.add("8BITMIME");
-
-
-            // Iterator i = esmtpextensions.iterator();
-            for (int i = 0; i < esmtpextensions.size(); i++) {
-                if (i == esmtpextensions.size() - 1) {
-                    responseBuffer.append("250 ");
-                    responseBuffer.append((String) esmtpextensions.get(i));
-                    session.writeResponse(session.clearResponseBuffer());
-                } else {
-                    responseBuffer.append("250-");
-                    responseBuffer.append((String) esmtpextensions.get(i));
-                    session.writeResponse(session.clearResponseBuffer());
-                }
+        ArrayList esmtpextensions = new ArrayList();
+
+        esmtpextensions.add(new StringBuffer(session.getConfigurationData()
+                .getHelloName()).append(" Hello ").append(argument)
+                .append(" (").append(session.getRemoteHost()).append(" [")
+                .append(session.getRemoteIPAddress()).append("])").toString());
+
+        // Extension defined in RFC 1870
+        long maxMessageSize = session.getConfigurationData()
+                .getMaxMessageSize();
+        if (maxMessageSize > 0) {
+            esmtpextensions.add("SIZE " + maxMessageSize);
+        }
+
+        if (session.isAuthRequired()) {
+            esmtpextensions.add("AUTH LOGIN PLAIN");
+            esmtpextensions.add("AUTH=LOGIN PLAIN");
+        }
+
+        esmtpextensions.add("PIPELINING");
+        esmtpextensions.add("ENHANCEDSTATUSCODES");
+        // see http://issues.apache.org/jira/browse/JAMES-419 
+        //esmtpextensions.add("8BITMIME");
+
+        // Iterator i = esmtpextensions.iterator();
+        for (int i = 0; i < esmtpextensions.size(); i++) {
+            if (i == esmtpextensions.size() - 1) {
+                responseBuffer.append("250 ");
+                responseBuffer.append((String) esmtpextensions.get(i));
+                session.writeResponse(session.clearResponseBuffer());
+            } else {
+                responseBuffer.append("250-");
+                responseBuffer.append((String) esmtpextensions.get(i));
+                session.writeResponse(session.clearResponseBuffer());
             }
         }
+
     }
 
 }

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/HeloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/HeloCmdHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/HeloCmdHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/HeloCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -31,7 +31,7 @@
      */
     private final static String COMMAND_NAME = "HELO";
       
-    /*
+    /**
      * process HELO command
      *
      * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
@@ -41,34 +41,24 @@
     }
 
     /**
-     * Handler method called upon receipt of a HELO command.
-     * Responds with a greeting and informs the client whether
-     * client authentication is required.
-     *
      * @param session SMTP session object
      * @param argument the argument passed in with the command by the SMTP client
      */
     private void doHELO(SMTPSession session, String argument) {
         String responseString = null;
-              
-        if (argument == null) {
-            responseString = "501 Domain address required: " + COMMAND_NAME;
-            session.writeResponse(responseString);
-            getLogger().info(responseString);
-        } else {
-            session.resetState();
-            session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
-            session.getResponseBuffer().append("250 ")
-                          .append(session.getConfigurationData().getHelloName())
-                          .append(" Hello ")
-                          .append(argument)
-                          .append(" (")
-                          .append(session.getRemoteHost())
-                          .append(" [")
-                          .append(session.getRemoteIPAddress())
-                          .append("])");
-            responseString = session.clearResponseBuffer();
-            session.writeResponse(responseString);
-        }
+
+        if (session.getState().get(SMTPSession.STOP_HANDLER_PROCESSING) != null)
+            return;
+
+        session.resetState();
+        session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
+        session.getResponseBuffer().append("250 ").append(
+                session.getConfigurationData().getHelloName())
+                .append(" Hello ").append(argument).append(" (").append(
+                        session.getRemoteHost()).append(" [").append(
+                        session.getRemoteIPAddress()).append("])");
+        responseString = session.clearResponseBuffer();
+        session.writeResponse(responseString);
     }
+    
 }

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/MailCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/MailCmdHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/MailCmdHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/MailCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -17,9 +17,6 @@
 
 package org.apache.james.smtpserver;
 
-import java.util.Locale;
-import java.util.StringTokenizer;
-
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.MailAddress;
@@ -30,10 +27,6 @@
 public class MailCmdHandler
     extends AbstractLogEnabled
     implements CommandHandler {
-
-    private final static String MAIL_OPTION_SIZE = "SIZE";
-
-    private final static String MESG_SIZE = "MESG_SIZE"; // The size of the message
     
     /**
      * handles MAIL command
@@ -53,174 +46,22 @@
      * @param argument the argument passed in with the command by the SMTP client
      */
     private void doMAIL(SMTPSession session, String argument) {
-        String responseString = null;
-        StringBuffer responseBuffer = session.getResponseBuffer();
-        String sender = null;
         
-        if ((argument != null) && (argument.indexOf(":") > 0)) {
-            int colonIndex = argument.indexOf(":");
-            sender = argument.substring(colonIndex + 1);
-            argument = argument.substring(0, colonIndex);
-        }
-        if (session.getState().containsKey(SMTPSession.SENDER)) {
-            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Sender already specified";
-            session.writeResponse(responseString);
-        } else if (!session.getState().containsKey(SMTPSession.CURRENT_HELO_MODE) && session.useHeloEhloEnforcement()) {
-            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need HELO or EHLO before MAIL";
-            session.writeResponse(responseString);
-        } else if (argument == null || !argument.toUpperCase(Locale.US).equals("FROM")
-                   || sender == null) {
-            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Usage: MAIL FROM:<sender>";
-            session.writeResponse(responseString);
-        } else {
-            sender = sender.trim();
-            // the next gt after the first lt ... AUTH may add more <>
-            int lastChar = sender.indexOf('>', sender.indexOf('<'));
-            // Check to see if any options are present and, if so, whether they are correctly formatted
-            // (separated from the closing angle bracket by a ' ').
-            if ((lastChar > 0) && (sender.length() > lastChar + 2) && (sender.charAt(lastChar + 1) == ' ')) {
-                String mailOptionString = sender.substring(lastChar + 2);
-
-                // Remove the options from the sender
-                sender = sender.substring(0, lastChar + 1);
-
-                StringTokenizer optionTokenizer = new StringTokenizer(mailOptionString, " ");
-                while (optionTokenizer.hasMoreElements()) {
-                    String mailOption = optionTokenizer.nextToken();
-                    int equalIndex = mailOption.indexOf('=');
-                    String mailOptionName = mailOption;
-                    String mailOptionValue = "";
-                    if (equalIndex > 0) {
-                        mailOptionName = mailOption.substring(0, equalIndex).toUpperCase(Locale.US);
-                        mailOptionValue = mailOption.substring(equalIndex + 1);
-                    }
-
-                    // Handle the SIZE extension keyword
-
-                    if (mailOptionName.startsWith(MAIL_OPTION_SIZE)) {
-                        if (!(doMailSize(session, mailOptionValue, sender))) {
-                            return;
-                        }
-                    } else {
-                        // Unexpected option attached to the Mail command
-                        if (getLogger().isDebugEnabled()) {
-                            StringBuffer debugBuffer =
-                                new StringBuffer(128)
-                                    .append("MAIL command had unrecognized/unexpected option ")
-                                    .append(mailOptionName)
-                                    .append(" with value ")
-                                    .append(mailOptionValue);
-                            getLogger().debug(debugBuffer.toString());
-                        }
-                    }
-                }
-            }
-            if (!sender.startsWith("<") || !sender.endsWith(">")) {
-                responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in MAIL command";
-                session.writeResponse(responseString);
-                if (getLogger().isErrorEnabled()) {
-                    StringBuffer errorBuffer =
-                        new StringBuffer(128)
-                            .append("Error parsing sender address: ")
-                            .append(sender)
-                            .append(": did not start and end with < >");
-                    getLogger().error(errorBuffer.toString());
-                }
-                return;
-            }
-            MailAddress senderAddress = null;
-            //Remove < and >
-            sender = sender.substring(1, sender.length() - 1);
-            if (sender.length() == 0) {
-                //This is the <> case.  Let senderAddress == null
-            } else {
-                 
-                if (sender.indexOf("@") < 0) {
-                    sender = sender + "@localhost";
-                }
-                
-                try {
-                    senderAddress = new MailAddress(sender);
-                } catch (Exception pe) {
-                    responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in sender address";
-                    session.writeResponse(responseString);
-                    if (getLogger().isErrorEnabled()) {
-                        StringBuffer errorBuffer =
-                            new StringBuffer(256)
-                                    .append("Error parsing sender address: ")
-                                    .append(sender)
-                                    .append(": ")
-                                    .append(pe.getMessage());
-                        getLogger().error(errorBuffer.toString());
-                    }
-                    return;
-                }
-            }
-         
-            
-            session.getState().put(SMTPSession.SENDER, senderAddress);
-            responseBuffer.append("250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.ADDRESS_OTHER)+" Sender <")
-                          .append(sender)
-                          .append("> OK");
-            responseString = session.clearResponseBuffer();
-            session.writeResponse(responseString);
-        }
-    }
+        if (session.getState().get(SMTPSession.STOP_HANDLER_PROCESSING) != null) return;
+        
+        
+        StringBuffer responseBuffer = session.getResponseBuffer();
+        String responseString = null;
 
-    /**
-     * Handles the SIZE MAIL option.
-     *
-     * @param session SMTP session object
-     * @param mailOptionValue the option string passed in with the SIZE option
-     * @param tempSender the sender specified in this mail command (for logging purpose)
-     * @return true if further options should be processed, false otherwise
-     */
-    private boolean doMailSize(SMTPSession session, String mailOptionValue, String tempSender) {
-        int size = 0;
-        try {
-            size = Integer.parseInt(mailOptionValue);
-        } catch (NumberFormatException pe) {
-            // This is a malformed option value.  We return an error
-            String responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Syntactically incorrect value for SIZE parameter";
-            session.writeResponse(responseString);
-            getLogger().error("Rejected syntactically incorrect value for SIZE parameter.");
-            return false;
-        }
-        if (getLogger().isDebugEnabled()) {
-            StringBuffer debugBuffer =
-                new StringBuffer(128)
-                    .append("MAIL command option SIZE received with value ")
-                    .append(size)
-                    .append(".");
-                    getLogger().debug(debugBuffer.toString());
-        }
-        long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
-        if ((maxMessageSize > 0) && (size > maxMessageSize)) {
-            // Let the client know that the size limit has been hit.
-            String responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Message size exceeds fixed maximum message size";
-            session.writeResponse(responseString);
-            StringBuffer errorBuffer =
-                new StringBuffer(256)
-                    .append("Rejected message from ")
-                    .append(tempSender != null ? tempSender : null)
-                    .append(" from host ")
-                    .append(session.getRemoteHost())
-                    .append(" (")
-                    .append(session.getRemoteIPAddress())
-                    .append(") of size ")
-                    .append(size)
-                    .append(" exceeding system maximum message size of ")
-                    .append(maxMessageSize)
-                    .append("based on SIZE option.");
-            getLogger().error(errorBuffer.toString());
-            return false;
-        } else {
-            // put the message size in the message state so it can be used
-            // later to restrict messages for user quotas, etc.
-            session.getState().put(MESG_SIZE, new Integer(size));
-        }
-        return true;
+        MailAddress sender = (MailAddress) session.getState().get(
+                SMTPSession.SENDER);
+        responseBuffer.append(
+                "250 "
+                        + DSNStatus.getStatus(DSNStatus.SUCCESS,
+                                DSNStatus.ADDRESS_OTHER) + " Sender <").append(
+                sender).append("> OK");
+        responseString = session.clearResponseBuffer();
+        session.writeResponse(responseString);
+        
     }
-
-
 }

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/RcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/RcptCmdHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/RcptCmdHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/RcptCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -19,8 +19,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Locale;
-import java.util.StringTokenizer;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.util.mail.dsn.DSNStatus;
@@ -32,7 +30,7 @@
 public class RcptCmdHandler extends AbstractLogEnabled implements
         CommandHandler {
 
-    /*
+    /**
      * handles RCPT command
      *
      * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
@@ -51,197 +49,29 @@
      * @param argument the argument passed in with the command by the SMTP client
      */
     private void doRCPT(SMTPSession session, String argument) {
+        
+        if (session.getState().get(SMTPSession.STOP_HANDLER_PROCESSING) != null) return;
+        
         String responseString = null;
         StringBuffer responseBuffer = session.getResponseBuffer();
-        
-        String recipient = null;
-        if ((argument != null) && (argument.indexOf(":") > 0)) {
-            int colonIndex = argument.indexOf(":");
-            recipient = argument.substring(colonIndex + 1);
-            argument = argument.substring(0, colonIndex);
+
+        Collection rcptColl = (Collection) session.getState().get(
+                SMTPSession.RCPT_LIST);
+        if (rcptColl == null) {
+            rcptColl = new ArrayList();
         }
-        if (!session.getState().containsKey(SMTPSession.SENDER)) {
-            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need MAIL before RCPT";
-            session.writeResponse(responseString);
-        } else if (argument == null || !argument.toUpperCase(Locale.US).equals("TO")
-                   || recipient == null) {
-            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Usage: RCPT TO:<recipient>";
-            session.writeResponse(responseString);
-        } else {
-            Collection rcptColl = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
-            if (rcptColl == null) {
-                rcptColl = new ArrayList();
-            }
-            recipient = recipient.trim();
-            int lastChar = recipient.lastIndexOf('>');
-            // Check to see if any options are present and, if so, whether they are correctly formatted
-            // (separated from the closing angle bracket by a ' ').
-            String rcptOptionString = null;
-            if ((lastChar > 0) && (recipient.length() > lastChar + 2) && (recipient.charAt(lastChar + 1) == ' ')) {
-                rcptOptionString = recipient.substring(lastChar + 2);
-
-                // Remove the options from the recipient
-                recipient = recipient.substring(0, lastChar + 1);
-            }
-            if (!recipient.startsWith("<") || !recipient.endsWith(">")) {
-                responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Syntax error in parameters or arguments";
-                session.writeResponse(responseString);
-                if (getLogger().isErrorEnabled()) {
-                    StringBuffer errorBuffer =
-                        new StringBuffer(192)
-                                .append("Error parsing recipient address: ")
-                                .append("Address did not start and end with < >")
-                                .append(getContext(session,null,recipient));
-                    getLogger().error(errorBuffer.toString());
-                }
-                return;
-            }
-            MailAddress recipientAddress = null;
-            //Remove < and >
-            recipient = recipient.substring(1, recipient.length() - 1);
-            if (recipient.indexOf("@") < 0) {
-                recipient = recipient + "@localhost";
-            }
-            
-            try {
-                recipientAddress = new MailAddress(recipient);
-            } catch (Exception pe) {
-                /*
-                 * from RFC2822;
-                 * 553 Requested action not taken: mailbox name not allowed
-                 *     (e.g., mailbox syntax incorrect)
-                 */
-                responseString = "553 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX)+" Syntax error in recipient address";
-                session.writeResponse(responseString);
-
-                if (getLogger().isErrorEnabled()) {
-                    StringBuffer errorBuffer =
-                        new StringBuffer(192)
-                                .append("Error parsing recipient address: ")
-                                .append(getContext(session,recipientAddress,recipient))
-                                .append(pe.getMessage());
-                    getLogger().error(errorBuffer.toString());
-                }
-                return;
-            }
-
-            if (session.isBlockListed() &&                                                // was found in the RBL
-                (!session.isRelayingAllowed() || (session.isAuthRequired() && session.getUser() == null)) &&  // Not an authorized IP or 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 (session.getBlockListedDetail() != null) {
-                    responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" " + session.getBlockListedDetail();
-                } 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;
-            }
-
-            if (session.isAuthRequired() && !session.isRelayingAllowed()) {
-                // Make sure the mail is being sent locally if not
-                // authenticated else reject.
-                if (session.getUser() == null) {
-                    String toDomain = recipientAddress.getHost();
-                    if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
-                        responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Authentication Required";
-                        session.writeResponse(responseString);
-                        StringBuffer sb = new StringBuffer(128);
-                        sb.append("Rejected message - authentication is required for mail request");
-                        sb.append(getContext(session,recipientAddress,recipient));
-                        getLogger().error(sb.toString());
-                        return;
-                    }
-                } else {
-                    // Identity verification checking
-                    if (session.getConfigurationData().isVerifyIdentity()) {
-                        String authUser = (session.getUser()).toLowerCase(Locale.US);
-                        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
-
-                        if ((senderAddress == null) || (!authUser.equals(senderAddress.getUser())) ||
-                            (!session.getConfigurationData().getMailServer().isLocalServer(senderAddress.getHost()))) {
-                            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Incorrect Authentication for Specified Email Address";
-                            session.writeResponse(responseString);
-                            if (getLogger().isErrorEnabled()) {
-                                StringBuffer errorBuffer =
-                                    new StringBuffer(128)
-                                        .append("User ")
-                                        .append(authUser)
-                                        .append(" authenticated, however tried sending email as ")
-                                        .append(senderAddress)
-                                        .append(getContext(session,recipientAddress,recipient));
-                                getLogger().error(errorBuffer.toString());
-                            }
-                            return;
-                        }
-                    }
-                }
-            } else if (!session.isRelayingAllowed()) {
-                String toDomain = recipientAddress.getHost();
-                if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
-                    responseString = "550 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Requested action not taken: relaying denied";
-                    session.writeResponse(responseString);
-                    StringBuffer errorBuffer = new StringBuffer(128)
-                        .append("Rejected message - ")
-                        .append(session.getRemoteIPAddress())
-                        .append(" not authorized to relay to ")
-                        .append(toDomain)
-                        .append(getContext(session,recipientAddress,recipient));
-                    getLogger().error(errorBuffer.toString());
-                    return;
-                }
-            }
-            if (rcptOptionString != null) {
-
-              StringTokenizer optionTokenizer = new StringTokenizer(rcptOptionString, " ");
-              while (optionTokenizer.hasMoreElements()) {
-                  String rcptOption = optionTokenizer.nextToken();
-                  int equalIndex = rcptOption.indexOf('=');
-                  String rcptOptionName = rcptOption;
-                  String rcptOptionValue = "";
-                  if (equalIndex > 0) {
-                      rcptOptionName = rcptOption.substring(0, equalIndex).toUpperCase(Locale.US);
-                      rcptOptionValue = rcptOption.substring(equalIndex + 1);
-                  }
-                  // Unexpected option attached to the RCPT command
-                  if (getLogger().isDebugEnabled()) {
-                      StringBuffer debugBuffer =
-                          new StringBuffer(128)
-                              .append("RCPT command had unrecognized/unexpected option ")
-                              .append(rcptOptionName)
-                              .append(" with value ")
-                              .append(rcptOptionValue)
-                              .append(getContext(session,recipientAddress,recipient));
-                      getLogger().debug(debugBuffer.toString());
-                  }
-              }
-              optionTokenizer = null;
-            }
-    
-            
-            rcptColl.add(recipientAddress);
-            session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
-            responseBuffer.append("250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.ADDRESS_VALID)+" Recipient <")
-                          .append(recipient)
-                          .append("> OK");
-            responseString = session.clearResponseBuffer();
-            session.writeResponse(responseString);
+        MailAddress recipientAddress = (MailAddress) session.getState().get(
+                SMTPSession.CURRENT_RECIPIENT);
+        rcptColl.add(recipientAddress);
+        session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
+        responseBuffer.append(
+                "250 "
+                        + DSNStatus.getStatus(DSNStatus.SUCCESS,
+                                DSNStatus.ADDRESS_VALID) + " Recipient <")
+                .append(recipientAddress).append("> OK");
+        responseString = session.clearResponseBuffer();
+        session.writeResponse(responseString);
             
-        }
+        
     }
-
-
-    private String getContext(SMTPSession session, MailAddress recipientAddress, String recipient){
-        StringBuffer sb = new StringBuffer(128);
-        if(null!=recipientAddress) {
-            sb.append(" [to:" + (recipientAddress).toInternetAddress().getAddress() + "]");
-        } else if(null!=recipient) {
-            sb.append(" [to:" + recipient + "]");
-        }
-        if (null!=session.getState().get(SMTPSession.SENDER)) {
-            sb.append(" [from:" + ((MailAddress)session.getState().get(SMTPSession.SENDER)).toInternetAddress().getAddress() + "]");
-        }
-        return sb.toString();
-    } 
 }

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandler.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandler.java Sun Jul  2 08:19:01 2006
@@ -271,6 +271,9 @@
                   theWatchdog.reset();
                   //if the response is received, stop processing of command handlers
                   if(mode != COMMAND_MODE) {
+                      
+                      // remove the blockin state
+                      getState().remove(SMTPSession.STOP_HANDLER_PROCESSING);
                       break;
                   }
               }

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPSession.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPSession.java?rev=418606&r1=418605&r2=418606&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPSession.java (original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPSession.java Sun Jul  2 08:19:01 2006
@@ -38,6 +38,7 @@
     public final static String RCPT_LIST = "RCPT_LIST";   // The message recipients
     public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO or EHLO
     public final static String STOP_HANDLER_PROCESSING = "STOP_HANDLER_PROCESSING";
+    public static final Object CURRENT_RECIPIENT = "CURRENT_RECIPIENT";
 
     /**
      * Writes response string to the client

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/DataBaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/DataBaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/DataBaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/DataBaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,72 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.basefilter;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+
+
+/**
+  * handles DATA command
+ */
+public class DataBaseFilterCmdHandler
+    extends AbstractLogEnabled
+    implements CommandHandler {
+   
+    /**
+     * process DATA command
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     */
+    public void onCommand(SMTPSession session) {
+        doDATA(session, session.getCommandArgument());
+    }
+
+
+    /**
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    private void doDATA(SMTPSession session, String argument) {
+        String responseString = null;
+        if ((argument != null) && (argument.length() > 0)) {
+            responseString = "500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with DATA command";
+            session.writeResponse(responseString);
+            
+            //TODO: Check if this should been!
+            // After this filter match we should not call any other handler!
+            //session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+        }
+        if (!session.getState().containsKey(SMTPSession.SENDER)) {
+            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No sender specified";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else if (!session.getState().containsKey(SMTPSession.RCPT_LIST)) {
+            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No recipients specified";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+        }
+    }
+}

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/EhloBaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/EhloBaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/EhloBaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/EhloBaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,62 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.basefilter;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+
+/**
+  * Handles EHLO command
+  */
+public class EhloBaseFilterCmdHandler extends AbstractLogEnabled implements CommandHandler {
+
+    /**
+     * The name of the command handled by the command handler
+     */
+    private final static String COMMAND_NAME = "EHLO";
+
+    /**
+     * processes EHLO command
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+    **/
+    public void onCommand(SMTPSession session) {
+        doEHLO(session, session.getCommandArgument());
+    }
+
+    /**
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    private void doEHLO(SMTPSession session, String argument) {
+        String responseString = null;        
+     
+        if (argument == null) {
+            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Domain address required: " + COMMAND_NAME;
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            return;
+            
+        }
+    }
+
+}

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/HeloBaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/HeloBaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/HeloBaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/HeloBaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,62 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.basefilter;
+
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+
+
+/**
+  * Handles HELO command
+  */
+public class HeloBaseFilterCmdHandler extends AbstractLogEnabled implements CommandHandler {
+
+    /**
+     * The name of the command handled by the command handler
+     */
+    private final static String COMMAND_NAME = "HELO";
+      
+    /**
+     * process HELO command
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+    **/
+    public void onCommand(SMTPSession session) {
+        doHELO(session, session.getCommandArgument());
+    }
+
+    /**
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    private void doHELO(SMTPSession session, String argument) {
+        String responseString = null;
+              
+        if (argument == null) {
+            responseString = "501 Domain address required: " + COMMAND_NAME;
+            session.writeResponse(responseString);
+            getLogger().info(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+         
+        }
+    }
+}

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/MailBaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/MailBaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/MailBaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/MailBaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,246 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.basefilter;
+
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.MailAddress;
+
+/**
+  * Handles MAIL command
+  */
+public class MailBaseFilterCmdHandler
+    extends AbstractLogEnabled
+    implements CommandHandler {
+
+    private final static String MAIL_OPTION_SIZE = "SIZE";
+
+    private final static String MESG_SIZE = "MESG_SIZE"; // The size of the message
+    
+    /**
+     * handles MAIL command
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     */
+    public void onCommand(SMTPSession session) {
+        doMAIL(session, session.getCommandArgument());
+    }
+
+
+    /**
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    private void doMAIL(SMTPSession session, String argument) {
+        String responseString = null;
+        String sender = null;
+        
+        if ((argument != null) && (argument.indexOf(":") > 0)) {
+            int colonIndex = argument.indexOf(":");
+            sender = argument.substring(colonIndex + 1);
+            argument = argument.substring(0, colonIndex);
+        }
+        if (session.getState().containsKey(SMTPSession.SENDER)) {
+            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Sender already specified";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else if (!session.getState().containsKey(SMTPSession.CURRENT_HELO_MODE) && session.useHeloEhloEnforcement()) {
+            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need HELO or EHLO before MAIL";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else if (argument == null || !argument.toUpperCase(Locale.US).equals("FROM")
+                   || sender == null) {
+            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Usage: MAIL FROM:<sender>";
+            session.writeResponse(responseString);
+        
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else {
+            sender = sender.trim();
+            // the next gt after the first lt ... AUTH may add more <>
+            int lastChar = sender.indexOf('>', sender.indexOf('<'));
+            // Check to see if any options are present and, if so, whether they are correctly formatted
+            // (separated from the closing angle bracket by a ' ').
+            if ((lastChar > 0) && (sender.length() > lastChar + 2) && (sender.charAt(lastChar + 1) == ' ')) {
+                String mailOptionString = sender.substring(lastChar + 2);
+
+                // Remove the options from the sender
+                sender = sender.substring(0, lastChar + 1);
+
+                StringTokenizer optionTokenizer = new StringTokenizer(mailOptionString, " ");
+                while (optionTokenizer.hasMoreElements()) {
+                    String mailOption = optionTokenizer.nextToken();
+                    int equalIndex = mailOption.indexOf('=');
+                    String mailOptionName = mailOption;
+                    String mailOptionValue = "";
+                    if (equalIndex > 0) {
+                        mailOptionName = mailOption.substring(0, equalIndex).toUpperCase(Locale.US);
+                        mailOptionValue = mailOption.substring(equalIndex + 1);
+                    }
+
+                    // Handle the SIZE extension keyword
+
+                    if (mailOptionName.startsWith(MAIL_OPTION_SIZE)) {
+                        if (!(doMailSize(session, mailOptionValue, sender))) {
+                            return;
+                        }
+                    } else {
+                        // Unexpected option attached to the Mail command
+                        if (getLogger().isDebugEnabled()) {
+                            StringBuffer debugBuffer =
+                                new StringBuffer(128)
+                                    .append("MAIL command had unrecognized/unexpected option ")
+                                    .append(mailOptionName)
+                                    .append(" with value ")
+                                    .append(mailOptionValue);
+                            getLogger().debug(debugBuffer.toString());
+                        }
+                    }
+                }
+            }
+            if (!sender.startsWith("<") || !sender.endsWith(">")) {
+                responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in MAIL command";
+                session.writeResponse(responseString);
+                if (getLogger().isErrorEnabled()) {
+                    StringBuffer errorBuffer =
+                        new StringBuffer(128)
+                            .append("Error parsing sender address: ")
+                            .append(sender)
+                            .append(": did not start and end with < >");
+                    getLogger().error(errorBuffer.toString());
+                }
+                // After this filter match we should not call any other handler!
+                session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                
+                return;
+            }
+            MailAddress senderAddress = null;
+            //Remove < and >
+            sender = sender.substring(1, sender.length() - 1);
+            if (sender.length() == 0) {
+                //This is the <> case.  Let senderAddress == null
+            } else {
+                 
+                if (sender.indexOf("@") < 0) {
+                    sender = sender + "@localhost";
+                }
+                
+                try {
+                    senderAddress = new MailAddress(sender);
+                } catch (Exception pe) {
+                    responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in sender address";
+                    session.writeResponse(responseString);
+                    if (getLogger().isErrorEnabled()) {
+                        StringBuffer errorBuffer =
+                            new StringBuffer(256)
+                                    .append("Error parsing sender address: ")
+                                    .append(sender)
+                                    .append(": ")
+                                    .append(pe.getMessage());
+                        getLogger().error(errorBuffer.toString());
+                    }
+                    
+                    // After this filter match we should not call any other handler!
+                    session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                    
+                    return;
+                }
+            }
+         
+            // Store the senderAddress in session map
+            session.getState().put(SMTPSession.SENDER, senderAddress);
+        }
+    }
+
+    /**
+     * Handles the SIZE MAIL option.
+     *
+     * @param session SMTP session object
+     * @param mailOptionValue the option string passed in with the SIZE option
+     * @param tempSender the sender specified in this mail command (for logging purpose)
+     * @return true if further options should be processed, false otherwise
+     */
+    private boolean doMailSize(SMTPSession session, String mailOptionValue, String tempSender) {
+        int size = 0;
+        try {
+            size = Integer.parseInt(mailOptionValue);
+        } catch (NumberFormatException pe) {
+            // This is a malformed option value.  We return an error
+            String responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Syntactically incorrect value for SIZE parameter";
+            session.writeResponse(responseString);
+            getLogger().error("Rejected syntactically incorrect value for SIZE parameter.");
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+            return false;
+        }
+        if (getLogger().isDebugEnabled()) {
+            StringBuffer debugBuffer =
+                new StringBuffer(128)
+                    .append("MAIL command option SIZE received with value ")
+                    .append(size)
+                    .append(".");
+                    getLogger().debug(debugBuffer.toString());
+        }
+        long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
+        if ((maxMessageSize > 0) && (size > maxMessageSize)) {
+            // Let the client know that the size limit has been hit.
+            String responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Message size exceeds fixed maximum message size";
+            session.writeResponse(responseString);
+            StringBuffer errorBuffer =
+                new StringBuffer(256)
+                    .append("Rejected message from ")
+                    .append(tempSender != null ? tempSender : null)
+                    .append(" from host ")
+                    .append(session.getRemoteHost())
+                    .append(" (")
+                    .append(session.getRemoteIPAddress())
+                    .append(") of size ")
+                    .append(size)
+                    .append(" exceeding system maximum message size of ")
+                    .append(maxMessageSize)
+                    .append("based on SIZE option.");
+            getLogger().error(errorBuffer.toString());
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+            return false;
+        } else {
+            // put the message size in the message state so it can be used
+            // later to restrict messages for user quotas, etc.
+            session.getState().put(MESG_SIZE, new Integer(size));
+        }
+        return true;
+    }
+
+
+}

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/RcptBaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/RcptBaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/RcptBaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/basefilter/RcptBaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,272 @@
+/***********************************************************************
+ * Copyright (c) 1999-2006 The Apache Software Foundation.             *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.basefilter;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.MailAddress;
+
+/**
+  * Handles RCPT command
+  */
+public class RcptBaseFilterCmdHandler extends AbstractLogEnabled implements
+        CommandHandler {
+
+    /**
+     * handles RCPT command
+     *
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+    **/
+    public void onCommand(SMTPSession session) {
+        doRCPT(session, session.getCommandArgument());
+    }
+
+
+    /**
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    private void doRCPT(SMTPSession session, String argument) {
+        String responseString = null;
+        
+        String recipient = null;
+        if ((argument != null) && (argument.indexOf(":") > 0)) {
+            int colonIndex = argument.indexOf(":");
+            recipient = argument.substring(colonIndex + 1);
+            argument = argument.substring(0, colonIndex);
+        }
+        if (!session.getState().containsKey(SMTPSession.SENDER)) {
+            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need MAIL before RCPT";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else if (argument == null || !argument.toUpperCase(Locale.US).equals("TO")
+                   || recipient == null) {
+            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Usage: RCPT TO:<recipient>";
+            session.writeResponse(responseString);
+            
+            // After this filter match we should not call any other handler!
+            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+            
+        } else {
+            Collection rcptColl = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
+            if (rcptColl == null) {
+                rcptColl = new ArrayList();
+            }
+            recipient = recipient.trim();
+            int lastChar = recipient.lastIndexOf('>');
+            // Check to see if any options are present and, if so, whether they are correctly formatted
+            // (separated from the closing angle bracket by a ' ').
+            String rcptOptionString = null;
+            if ((lastChar > 0) && (recipient.length() > lastChar + 2) && (recipient.charAt(lastChar + 1) == ' ')) {
+                rcptOptionString = recipient.substring(lastChar + 2);
+
+                // Remove the options from the recipient
+                recipient = recipient.substring(0, lastChar + 1);
+            }
+            if (!recipient.startsWith("<") || !recipient.endsWith(">")) {
+                responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Syntax error in parameters or arguments";
+                session.writeResponse(responseString);
+                if (getLogger().isErrorEnabled()) {
+                    StringBuffer errorBuffer =
+                        new StringBuffer(192)
+                                .append("Error parsing recipient address: ")
+                                .append("Address did not start and end with < >")
+                                .append(getContext(session,null,recipient));
+                    getLogger().error(errorBuffer.toString());
+                }
+                
+                // After this filter match we should not call any other handler!
+                session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                
+                return;
+            }
+            MailAddress recipientAddress = null;
+            //Remove < and >
+            recipient = recipient.substring(1, recipient.length() - 1);
+            if (recipient.indexOf("@") < 0) {
+                recipient = recipient + "@localhost";
+            }
+            
+            try {
+                recipientAddress = new MailAddress(recipient);
+            } catch (Exception pe) {
+                /*
+                 * from RFC2822;
+                 * 553 Requested action not taken: mailbox name not allowed
+                 *     (e.g., mailbox syntax incorrect)
+                 */
+                responseString = "553 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX)+" Syntax error in recipient address";
+                session.writeResponse(responseString);
+
+                if (getLogger().isErrorEnabled()) {
+                    StringBuffer errorBuffer =
+                        new StringBuffer(192)
+                                .append("Error parsing recipient address: ")
+                                .append(getContext(session,recipientAddress,recipient))
+                                .append(pe.getMessage());
+                    getLogger().error(errorBuffer.toString());
+                }
+                
+                // After this filter match we should not call any other handler!
+                session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                
+                return;
+            }
+
+            if (session.isBlockListed() &&                                                // was found in the RBL
+                (!session.isRelayingAllowed() || (session.isAuthRequired() && session.getUser() == null)) &&  // Not an authorized IP or 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 (session.getBlockListedDetail() != null) {
+                    responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" " + session.getBlockListedDetail();
+                } 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);
+                
+                // After this filter match we should not call any other handler!
+                session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                
+                return;
+            }
+
+            if (session.isAuthRequired() && !session.isRelayingAllowed()) {
+                // Make sure the mail is being sent locally if not
+                // authenticated else reject.
+                if (session.getUser() == null) {
+                    String toDomain = recipientAddress.getHost();
+                    if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
+                        responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Authentication Required";
+                        session.writeResponse(responseString);
+                        StringBuffer sb = new StringBuffer(128);
+                        sb.append("Rejected message - authentication is required for mail request");
+                        sb.append(getContext(session,recipientAddress,recipient));
+                        getLogger().error(sb.toString());
+                        
+                        // After this filter match we should not call any other handler!
+                        session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                        
+                        return;
+                    }
+                } else {
+                    // Identity verification checking
+                    if (session.getConfigurationData().isVerifyIdentity()) {
+                        String authUser = (session.getUser()).toLowerCase(Locale.US);
+                        MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
+
+                        if ((senderAddress == null) || (!authUser.equals(senderAddress.getUser())) ||
+                            (!session.getConfigurationData().getMailServer().isLocalServer(senderAddress.getHost()))) {
+                            responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Incorrect Authentication for Specified Email Address";
+                            session.writeResponse(responseString);
+                            if (getLogger().isErrorEnabled()) {
+                                StringBuffer errorBuffer =
+                                    new StringBuffer(128)
+                                        .append("User ")
+                                        .append(authUser)
+                                        .append(" authenticated, however tried sending email as ")
+                                        .append(senderAddress)
+                                        .append(getContext(session,recipientAddress,recipient));
+                                getLogger().error(errorBuffer.toString());
+                            }
+                            
+                            // After this filter match we should not call any other handler!
+                            session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                            
+                            return;
+                        }
+                    }
+                }
+            } else if (!session.isRelayingAllowed()) {
+                String toDomain = recipientAddress.getHost();
+                if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
+                    responseString = "550 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Requested action not taken: relaying denied";
+                    session.writeResponse(responseString);
+                    StringBuffer errorBuffer = new StringBuffer(128)
+                        .append("Rejected message - ")
+                        .append(session.getRemoteIPAddress())
+                        .append(" not authorized to relay to ")
+                        .append(toDomain)
+                        .append(getContext(session,recipientAddress,recipient));
+                    getLogger().error(errorBuffer.toString());
+                    
+                    // After this filter match we should not call any other handler!
+                    session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                    
+                    return;
+                }
+            }
+            if (rcptOptionString != null) {
+
+              StringTokenizer optionTokenizer = new StringTokenizer(rcptOptionString, " ");
+              while (optionTokenizer.hasMoreElements()) {
+                  String rcptOption = optionTokenizer.nextToken();
+                  int equalIndex = rcptOption.indexOf('=');
+                  String rcptOptionName = rcptOption;
+                  String rcptOptionValue = "";
+                  if (equalIndex > 0) {
+                      rcptOptionName = rcptOption.substring(0, equalIndex).toUpperCase(Locale.US);
+                      rcptOptionValue = rcptOption.substring(equalIndex + 1);
+                  }
+                  // Unexpected option attached to the RCPT command
+                  if (getLogger().isDebugEnabled()) {
+                      StringBuffer debugBuffer =
+                          new StringBuffer(128)
+                              .append("RCPT command had unrecognized/unexpected option ")
+                              .append(rcptOptionName)
+                              .append(" with value ")
+                              .append(rcptOptionValue)
+                              .append(getContext(session,recipientAddress,recipient));
+                      getLogger().debug(debugBuffer.toString());
+                  }
+                  
+                  // After this filter match we should not call any other handler!
+                  session.getState().put(SMTPSession.STOP_HANDLER_PROCESSING, "true");
+                  
+              }
+              optionTokenizer = null;
+            }
+    
+            session.getState().put(SMTPSession.CURRENT_RECIPIENT,recipientAddress);
+        }
+    }
+
+
+    private String getContext(SMTPSession session, MailAddress recipientAddress, String recipient){
+        StringBuffer sb = new StringBuffer(128);
+        if(null!=recipientAddress) {
+            sb.append(" [to:" + (recipientAddress).toInternetAddress().getAddress() + "]");
+        } else if(null!=recipient) {
+            sb.append(" [to:" + recipient + "]");
+        }
+        if (null!=session.getState().get(SMTPSession.SENDER)) {
+            sb.append(" [from:" + ((MailAddress)session.getState().get(SMTPSession.SENDER)).toInternetAddress().getAddress() + "]");
+        }
+        return sb.toString();
+    } 
+}

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseFilterCmdHandler.java?rev=418606&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseFilterCmdHandler.java (added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseFilterCmdHandler.java Sun Jul  2 08:19:01 2006
@@ -0,0 +1,51 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.james.smtpserver.CommandsHandler;
+
+/**
+ * This class represent the base filter command handlers which are shipped with james.
+ */
+public class BaseFilterCmdHandler implements CommandsHandler {
+
+    private final Object DATABASEFILTERCMDHANDLER = "org.apache.james.smtpserver.basefilter.DataBaseFilterCmdHandler";
+    private final Object EHLOBASEFILTERCMDHANDLER = "org.apache.james.smtpserver.basefilter.EhloBaseFilterCmdHandler";
+    private final Object HELOBASEFILTERCMDHANDLER = "org.apache.james.smtpserver.basefilter.HeloBaseFilterCmdHandler";
+    private final Object MAILBASEFILTERCMDHANDLER = "org.apache.james.smtpserver.basefilter.MailBaseFilterCmdHandler";
+    private final Object RCPTBASEFILTERCMDHANDLER = "org.apache.james.smtpserver.basefilter.RcptBaseFilterCmdHandler";
+   
+    /**
+     * @see org.apache.james.smtpserver.CommandsHandler#getCommands()
+     */
+    public Map getCommands() {
+        Map commands = new HashMap();
+        
+        // Insert the basecommands in the Map
+        commands.put("DATA", DATABASEFILTERCMDHANDLER);
+        commands.put("EHLO", EHLOBASEFILTERCMDHANDLER);
+        commands.put("HELO", HELOBASEFILTERCMDHANDLER);
+        commands.put("MAIL", MAILBASEFILTERCMDHANDLER);
+        commands.put("RCPT", RCPTBASEFILTERCMDHANDLER);
+        
+        return commands;
+    }
+}



---------------------------------------------------------------------
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