Author: norman
Date: Tue Dec 26 07:51:07 2006
New Revision: 490313

URL: http://svn.apache.org/viewvc?view=rev&rev=490313
Log:
Change OnMessage to return SMTPResponse, some more cleanup . See JAMES-750

Modified:
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/MessageHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPSession.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
    
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
    
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/JunkScoreHandlerTest.java
    
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
    
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/URIRBLHandlerTest.java

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/MessageHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/MessageHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/MessageHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/MessageHandler.java
 Tue Dec 26 07:51:07 2006
@@ -31,6 +31,6 @@
     /*
      * Handle Message
     **/
-    void onMessage(SMTPSession session);
+    SMTPResponse onMessage(SMTPSession session);
 
 }

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
 Tue Dec 26 07:51:07 2006
@@ -279,7 +279,10 @@
                   List messageHandlers = handlerChain.getMessageHandlers();
                   int count = messageHandlers.size();
                   for(int i =0; i < count; i++) {
-                      ((MessageHandler)messageHandlers.get(i)).onMessage(this);
+                      SMTPResponse response = 
((MessageHandler)messageHandlers.get(i)).onMessage(this);
+                      
+                      writeSMTPResponse(response);
+                      
                       //if the response is received, stop processing of 
command handlers
                       if(mode == MESSAGE_ABORT_MODE) {
                           break;
@@ -403,10 +406,8 @@
         this.handlerChain = handlerChain;
     }
 
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#writeResponse(String)
-     */
-    public void writeResponse(String respString) {
+
+    private void writeResponse(String respString) {
         writeLoggedFlushedResponse(respString);
         //TODO Explain this well
         if(mode == COMMAND_MODE) {

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPSession.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPSession.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPSession.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPSession.java
 Tue Dec 26 07:51:07 2006
@@ -47,7 +47,7 @@
      *
      * @param respString String that needs to send to the client
      */
-    void writeResponse(String respString);
+   // void writeResponse(String respString);
 
     /**
      * Reads a line of characters off the command line.

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/AuthCmdHandler.java
 Tue Dec 26 07:51:07 2006
@@ -25,6 +25,7 @@
 import org.apache.james.smtpserver.LineHandler;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 
@@ -73,10 +74,10 @@
      */
     private SMTPResponse doAUTH(SMTPSession session, String argument) {
         if (session.getUser() != null) {
-            return new SMTPResponse("503", 
DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" User has 
previously authenticated. "
+            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, 
DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" User has 
previously authenticated. "
                     + " Further authentication is not required!");
         } else if (argument == null) {
-            return new SMTPResponse("501", 
DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" 
Usage: AUTH (authentication type) <challenge>");
+            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, 
DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" 
Usage: AUTH (authentication type) <challenge>");
         } else {
             String initialResponse = null;
             if ((argument != null) && (argument.indexOf(" ") > 0)) {
@@ -92,7 +93,7 @@
                         public void onLine(SMTPSession session, byte[] line) {
                             try {
                                 String l = new String(line, "US-ASCII");
-                                System.err.println("((("+line+")))");
+                                //System.err.println("((("+line+")))");
                                 SMTPResponse res = doPlainAuthPass(session, l);
                                 session.writeSMTPResponse(res);
                             } catch (UnsupportedEncodingException e) {
@@ -204,14 +205,14 @@
         session.popLineHandler();
         // Authenticate user
         if ((user == null) || (pass == null)) {
-            return new SMTPResponse("501", "Could not decode parameters for 
AUTH PLAIN");
+            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, "Could 
not decode parameters for AUTH PLAIN");
         } else if 
(session.getConfigurationData().getUsersRepository().test(user, pass)) {
             session.setUser(user);
             getLogger().info("AUTH method PLAIN succeeded");
-            return new SMTPResponse("235", "Authentication Successful");
+            return new SMTPResponse(SMTPRetCode.AUTH_OK, "Authentication 
Successful");
         } else {
             getLogger().error("AUTH method PLAIN failed");
-            return new SMTPResponse("535", "Authentication Failed");
+            return new SMTPResponse(SMTPRetCode.AUTH_FAILED, "Authentication 
Failed");
         }
     }
 
@@ -257,7 +258,7 @@
     }
     
     private void doLoginAuthPassCheck(SMTPSession session, String user, String 
pass) {
-        String responseString = null;
+        SMTPResponse response = null;
         if (pass != null) {
             try {
                 pass = Base64.decodeAsString(pass);
@@ -269,23 +270,22 @@
         }
         // Authenticate user
         if ((user == null) || (pass == null)) {
-            responseString = "501 Could not decode parameters for AUTH LOGIN";
+            response = new 
SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,"Could not decode parameters 
for AUTH LOGIN");
         } else if 
(session.getConfigurationData().getUsersRepository().test(user, pass)) {
             session.setUser(user);
-            responseString = "235 Authentication Successful";
+            response = new SMTPResponse(SMTPRetCode.AUTH_OK, "Authentication 
Successful");
             if (getLogger().isDebugEnabled()) {
                 // TODO: Make this string a more useful debug message
                 getLogger().debug("AUTH method LOGIN succeeded");
             }
         } else {
-            responseString = "535 Authentication Failed";
+            response = new SMTPResponse(SMTPRetCode.AUTH_FAILED, 
"Authentication Failed");
             // TODO: Make this string a more useful error message
             getLogger().error("AUTH method LOGIN failed");
         }
         session.popLineHandler();
         session.popLineHandler();
-        session.writeResponse(responseString);
-        return;
+        session.writeSMTPResponse(response);
     }
 
     /**
@@ -304,7 +304,7 @@
                         .append(" is an unrecognized authentication type");
             getLogger().error(errorBuffer.toString());
         }
-        return new SMTPResponse("504", "Unrecognized Authentication Type");
+        return new SMTPResponse(SMTPRetCode.PARAMETER_NOT_IMPLEMENTED, 
"Unrecognized Authentication Type");
     }
 
 

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/DataCmdHandler.java
 Tue Dec 26 07:51:07 2006
@@ -34,6 +34,7 @@
 import org.apache.james.smtpserver.SizeLimitedInputStream;
 import org.apache.james.util.CharTerminatedInputStream;
 import org.apache.james.util.DotStuffingInputStream;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.RFC2822Headers;
@@ -172,7 +173,7 @@
     
 
     public void handleStream(SMTPSession session, InputStream stream) {
-        String responseString;
+        SMTPResponse response = null;
         InputStream msgIn = new CharTerminatedInputStream(stream, 
SMTPTerminator);
         try {
             // 2006/12/24 - We can remove this now that every single line is 
pushed and
@@ -215,10 +216,9 @@
                 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();
+                response = new 
SMTPResponse(SMTPRetCode.QUOTA_EXCEEDED,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())
@@ -230,15 +230,14 @@
                                         .getMaxMessageSize());
                 getLogger().error(errorBuffer.toString());
             } else {
-                responseString = "451 "
-                        + DSNStatus.getStatus(DSNStatus.TRANSIENT,
-                                DSNStatus.UNDEFINED_STATUS)
-                        + " Error processing message: " + me.getMessage();
+                response = new 
SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
+                                DSNStatus.UNDEFINED_STATUS) + " Error 
processing message: " + me.getMessage());
+                
                 getLogger().error(
                         "Unknown error occurred while processing DATA.", me);
             }
             session.popLineHandler();
-            session.writeResponse(responseString);
+            session.writeSMTPResponse(response);
             return;
         } finally {
             if (msgIn != null) {

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SendMailHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SendMailHandler.java
 Tue Dec 26 07:51:07 2006
@@ -28,7 +28,9 @@
 import org.apache.james.services.MailServer;
 import org.apache.james.smtpserver.MessageHandler;
 import org.apache.james.smtpserver.MessageSizeException;
+import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.Mail;
 
@@ -57,12 +59,11 @@
      * Adds header to the message
      * @see org.apache.james.smtpserver#onMessage(SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
+    public SMTPResponse onMessage(SMTPSession session) {
         getLogger().debug("sending mail");
 
         Mail mail = session.getMail();
-        
-        String responseString = null;
+
         try {
             mailServer.sendMail(mail);
             Collection theRecipients = mail.getRecipients();
@@ -96,7 +97,7 @@
                    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.";
+                  
                    StringBuffer errorBuffer =
                      new StringBuffer(256)
                          .append("Rejected message from ")
@@ -108,17 +109,15 @@
                          .append(") exceeding system maximum message size of ")
                          
.append(session.getConfigurationData().getMaxMessageSize());
                    getLogger().error(errorBuffer.toString());
+                   
+                   return new SMTPResponse(SMTPRetCode.MAIL_OK, 
DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error 
processing message.");
               } else {
-                   responseString = "451 
"+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error 
processing message.";
                    getLogger().error("Unknown error occurred while processing 
DATA.", me);
+                   
+                   return new 
SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+"
 Error processing message.");
               }
-              session.writeResponse(responseString);
-              return;
          }
-         responseString = "250 
"+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message 
received";
-         session.writeResponse(responseString);
-
-    
+         return new 
SMTPResponse(SMTPRetCode.MAIL_OK,DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+"
 Message received");
     }
 
 }

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/SetMimeHeaderHandler.java
 Tue Dec 26 07:51:07 2006
@@ -26,6 +26,7 @@
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.james.smtpserver.MessageHandler;
+import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
 
 import javax.mail.internet.MimeMessage;
@@ -78,11 +79,13 @@
         this.headerValue = headerValue;
     }
 
+
     /**
      * Adds header to the message
-     * @see org.apache.james.smtpserver#onMessage(SMTPSession)
+     *
+     * @see 
org.apache.james.smtpserver.MessageHandler#onMessage(org.apache.james.smtpserver.SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
+    public SMTPResponse onMessage(SMTPSession session) {
         try {
             MimeMessage message = session.getMail().getMessage ();
 
@@ -95,6 +98,8 @@
         } catch (javax.mail.MessagingException me) {
             getLogger().error(me.getMessage());
         }
+        
+        return null;
     }
 
 

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java
 Tue Dec 26 07:51:07 2006
@@ -34,10 +34,12 @@
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.smtpserver.ConnectHandler;
 import org.apache.james.smtpserver.MessageHandler;
+import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
 import org.apache.james.util.junkscore.ComposedJunkScore;
 import org.apache.james.util.junkscore.JunkScore;
 import org.apache.james.util.junkscore.JunkScoreImpl;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 
 /**
@@ -98,8 +100,8 @@
     /**
      * @see 
org.apache.james.smtpserver.MessageHandler#onMessage(org.apache.james.smtpserver.SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
-        checkScore(session);
+    public SMTPResponse onMessage(SMTPSession session) {
+        return checkScore(session);
     }
 
     /**
@@ -107,7 +109,7 @@
      * 
      * @param session the SMTPSession
      */
-    private void checkScore(SMTPSession session) {
+    private SMTPResponse checkScore(SMTPSession session) {
         JunkScore score1 = (JunkScore) 
session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION);
         JunkScore score2 = (JunkScore) 
session.getState().get(JunkScore.JUNK_SCORE);
         JunkScore composed = new ComposedJunkScore(score1,score2);
@@ -119,27 +121,23 @@
             session.getMail().setAttribute(JunkScore.JUNK_SCORE_COMPOSED_ATTR, 
String.valueOf(composed.getCompleteStoredScores()));
         } else if (action.equals(REJECT_ACTION)) {
             if (maxScore <  composed.getCompleteStoredScores()) {
-
-                
-                String 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";
+ 
                 StringBuffer buffer = 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(
-                            ") " + responseString).append(
-                            ". Required rejection hits: "
-                                    + maxScore
-                                    + " hits: " + 
composed.getCompleteStoredScores());
+                            "). This message reach the smap hits treshold. 
Required rejection hits: ")
+                    .append(maxScore).append(" hits: ")
+                    .append(composed.getCompleteStoredScores());
                 getLogger().info(buffer.toString());
                 
-                session.writeResponse(responseString);
+                //session.writeResponse(responseString);
                 session.setStopHandlerProcessing(true);
                 session.abortMessage();
+                return new SMTPResponse(SMTPRetCode.TRANSACTION_FAILED, 
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");
             }
         } else if (action.equals(HEADER_ACTION)) {
             try {
@@ -163,6 +161,7 @@
                 getLogger().info("Unable to add Junkscore to header: " + 
e.getMessage());
             }
         }
+        return null;
     }
         
     /**

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
 Tue Dec 26 07:51:07 2006
@@ -35,6 +35,7 @@
 import org.apache.james.smtpserver.MessageHandler;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -240,15 +241,17 @@
 
         return commands;
     }
-
+    
     /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
+     * @see 
org.apache.james.smtpserver.MessageHandler#onMessage(org.apache.james.smtpserver.SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
+    public SMTPResponse 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));
+    
+        return null;
     }
     
 
@@ -289,11 +292,11 @@
 
         // Check if session is blocklisted
         if (blocklisted != null && blocklisted.equals("true")) {
-            data.setRejectResponseString("530 " + 
DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " "
+            data.setRejectResponseString(SMTPRetCode.TRANSACTION_FAILED + " " 
+ 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) + " "
+            data.setRejectResponseString(SMTPRetCode.LOCAL_ERROR + " " + 
DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER) + " "
                     + "Temporarily rejected: Problem on SPF lookup");
         }
         data.setJunkScoreLogString("Not match SPF-Record. Add junkScore: " + 
getScore());

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
 Tue Dec 26 07:51:07 2006
@@ -30,8 +30,10 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.smtpserver.MessageHandler;
+import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
 import org.apache.james.util.SpamAssassinInvoker;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.mailet.Mail;
 
@@ -140,13 +142,13 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
+     * @see 
org.apache.james.smtpserver.MessageHandler#onMessage(org.apache.james.smtpserver.SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
+    public SMTPResponse onMessage(SMTPSession session) {
 
         // Not scan the message if relaying allowed
         if (session.isRelayingAllowed() && !checkAuthNetworks) {
-            return;
+            return null;
         }
 
         try {
@@ -174,25 +176,20 @@
                     // if the hits are bigger the rejectionHits reject the
                     // message
                     if (spamdRejectionHits <= hits) {
-                        String 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";
                         StringBuffer buffer = 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(
-                                        ") " + responseString).append(
-                                        ". Required rejection hits: "
-                                                + spamdRejectionHits
-                                                + " hits: " + hits);
+                                
.append(session.getRemoteIPAddress()).append(") This message reach the spam 
hits treshold. Required rejection hits: ")
+                                .append(spamdRejectionHits).append(" hits: ")
+                                .append(hits);
                         getLogger().info(buffer.toString());
-                        session.writeResponse(responseString);
 
                         // Message reject .. abort it!
                         session.abortMessage();
+                        return new 
SMTPResponse(SMTPRetCode.TRANSACTION_FAILED,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");
                     }
                 } catch (NumberFormatException e) {
                     // hits unknown
@@ -201,6 +198,6 @@
         } catch (MessagingException e) {
             getLogger().error(e.getMessage());
         }
-
+        return null;
     }
 }

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
 Tue Dec 26 07:51:07 2006
@@ -45,6 +45,7 @@
 import org.apache.james.smtpserver.MessageHandler;
 import org.apache.james.smtpserver.SMTPResponse;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.SMTPRetCode;
 import org.apache.james.util.mail.dsn.DSNStatus;
 import org.apache.james.util.urirbl.URIScanner;
 
@@ -158,14 +159,10 @@
     }
     
     /**
-     * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
+     * @see 
org.apache.james.smtpserver.MessageHandler#onMessage(org.apache.james.smtpserver.SMTPSession)
      */
-    public void onMessage(SMTPSession session) {
-        SMTPResponse response = doProcessing(session);
-        
-        if (response != null) {
-            session.writeSMTPResponse(response);
-        }
+    public SMTPResponse onMessage(SMTPSession session) {
+        return doProcessing(session);
     }
 
     /**
@@ -283,11 +280,11 @@
 
         if (detail != null) {
            
-            data.setRejectResponseString("554 " + 
DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER)
+            data.setRejectResponseString(SMTPRetCode.TRANSACTION_FAILED + " " 
+ 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)
+            data.setRejectResponseString(SMTPRetCode.TRANSACTION_FAILED + " " 
+ DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_OTHER)
                 + " Rejected: message contains domain " + target + " listed by 
" + uRblServer);
         }  
 

Modified: 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/util/mail/SMTPRetCode.java
 Tue Dec 26 07:51:07 2006
@@ -37,6 +37,9 @@
 
     // <domain> Service closing transmission channel
     public static final String SYSTEM_QUIT = "221";
+    
+    // Auth ok
+    public static final String AUTH_OK = "235";
 
     // Requested mail action okay, completed
     public static final String MAIL_OK = "250";
@@ -83,6 +86,9 @@
 
     // Command parameter not implemented
     public static final String PARAMETER_NOT_IMPLEMENTED = "504";
+    
+    // Auth failed
+    public static final String AUTH_FAILED = "535";
 
     // Requested action not taken: mailbox unavailable
     // (e.g., mailbox not found, no access, or command rejected

Modified: 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/JunkScoreHandlerTest.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/JunkScoreHandlerTest.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/JunkScoreHandlerTest.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/JunkScoreHandlerTest.java
 Tue Dec 26 07:51:07 2006
@@ -47,7 +47,6 @@
     private final static double SCORE2 = 7.1;
 
     public void setUp() {
-        response = null;
         stopped = false;
         messageAborted = false;
     }
@@ -67,10 +66,6 @@
                 return cState;
             }
 
-            public void writeResponse(String resp) {
-                response = resp;
-            }
-
             public void setStopHandlerProcessing(boolean b) {
                 stopped = b;
             }
@@ -133,7 +128,7 @@
         assertNull("Not rejected",response);
         ((JunkScore) 
session.getState().get(JunkScore.JUNK_SCORE)).setStoredScore(KEY1, SCORE1);
         ((JunkScore) 
session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).setStoredScore(KEY2,
 SCORE2);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
     
         assertNotNull("Rejected",response);
         assertTrue("Rejected",stopped);
@@ -150,7 +145,7 @@
         handler.onConnect(session);
         ((JunkScore) 
session.getState().get(JunkScore.JUNK_SCORE)).setStoredScore(KEY1, SCORE1);
         ((JunkScore) 
session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION)).setStoredScore(KEY2,
 SCORE2);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
     
         MimeMessage message = session.getMail().getMessage();
         assertNotNull("Header added",message.getHeader("X-JUNKSCORE")[0]);

Modified: 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
 Tue Dec 26 07:51:07 2006
@@ -41,16 +41,9 @@
 
 public class SpamAssassinHandlerTest extends TestCase {
     private SMTPSession mockedSMTPSession;
-
-    private String response = null;
-    
+ 
     public final static String SPAMD_HOST = "localhost";
 
-    public void setUp() {
-        // reset reponse
-        response = null;
-    }
-
     private SMTPSession setupMockedSMTPSession(final Mail mail) {
         mockedSMTPSession = new AbstractSMTPSession() {
 
@@ -89,20 +82,12 @@
             public void setRelayingAllowed(boolean relayingAllowed) {
                 this.relayingAllowed = relayingAllowed;
             }
-
-            public void writeResponse(String respString) {
-                response = respString;
-            }
         };
 
         return mockedSMTPSession;
 
     }
 
-    private String getResponse() {
-        return response;
-    }
-
     private Mail setupMockedMail(MimeMessage message) {
         MockMail mail = new MockMail();
         mail.setMessage(message);
@@ -132,9 +117,9 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
         assertEquals("email was not spam", session.getMail().getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "NO");
         assertNotNull("spam hits", session.getMail().getAttribute(
@@ -155,9 +140,9 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(2000.0);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
         assertEquals("email was spam", session.getMail().getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
         assertNotNull("spam hits", session.getMail().getAttribute(
@@ -177,9 +162,9 @@
         handler.setSpamdHost(SPAMD_HOST);
         handler.setSpamdPort(port);
         handler.setSpamdRejectionHits(200.0);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
-        assertNotNull("Email was rejected", getResponse());
+        assertNotNull("Email was rejected", response);
         assertEquals("email was spam", session.getMail().getAttribute(
                 SpamAssassinInvoker.FLAG_MAIL_ATTRIBUTE_NAME), "YES");
         assertNotNull("spam hits", session.getMail().getAttribute(

Modified: 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/URIRBLHandlerTest.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/URIRBLHandlerTest.java?view=diff&rev=490313&r1=490312&r2=490313
==============================================================================
--- 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/URIRBLHandlerTest.java
 (original)
+++ 
james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/URIRBLHandlerTest.java
 Tue Dec 26 07:51:07 2006
@@ -56,13 +56,6 @@
     private static final String URISERVER = "multi.surbl.org.";
     private SMTPSession mockedSMTPSession;
 
-    private SMTPResponse response = null;
-    
-    public void setUp() {
-        // reset reponse
-        response = null;
-    }
-
     private SMTPSession setupMockedSMTPSession(final Mail mail) {
         mockedSMTPSession = new AbstractSMTPSession() {
 
@@ -103,10 +96,6 @@
             public void setRelayingAllowed(boolean relayingAllowed) {
                 this.relayingAllowed = relayingAllowed;
             }
-
-            public void writeSMTPResponse(SMTPResponse resp) {
-            response = resp;
-            }
             
             public void setStopHandlerProcessing(boolean processing) {
                 this.processing = processing;
@@ -121,10 +110,6 @@
 
     }
 
-    private SMTPResponse getResponse() {
-        return response;
-    }
-
     private Mail setupMockedMail(MimeMessage message) {
         MockMail mail = new MockMail();
         mail.setMessage(message);
@@ -205,10 +190,10 @@
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
         assertFalse("Not Stop handler processing", 
session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
     }
     
     public void testBlocked() throws IOException, MessagingException {
@@ -223,10 +208,10 @@
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
         assertTrue("Stop handler processing", 
session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
+        assertNotNull("Email was rejected", response);
     }
     
     public void testBlockedMultiPart() throws IOException, MessagingException {
@@ -241,10 +226,10 @@
         ContainerUtil.enableLogging(handler, new MockLogger());
         handler.setDnsServer(setupMockedDnsServer());
         handler.setUriRblServer(servers);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
         assertTrue("Stop handler processing", 
session.getStopHandlerProcessing());
-        assertNotNull("Email was rejected", getResponse());
+        assertNotNull("Email was rejected", response);
     }
     
     public void testAddJunkScore() throws IOException, MessagingException {
@@ -262,10 +247,10 @@
         handler.setUriRblServer(servers);
         handler.setAction("junkScore");
         handler.setScore(20);
-        handler.onMessage(session);
+        SMTPResponse response = handler.onMessage(session);
 
         assertFalse("Not stop handler processing", 
session.getStopHandlerProcessing());
-        assertNull("Email was not rejected", getResponse());
+        assertNull("Email was not rejected", response);
         assertEquals("JunkScore added", ((JunkScore) 
session.getState().get(JunkScore.JUNK_SCORE)).getStoredScore("UriRBLCheck"), 
20.0, 0d);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to