You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/10/20 07:47:25 UTC

svn commit: r826961 [1/2] - in /james/server/trunk: phoenix-deployment/src/conf/ smtp-protocol-library/ smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/ smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/c...

Author: norman
Date: Tue Oct 20 05:47:23 2009
New Revision: 826961

URL: http://svn.apache.org/viewvc?rev=826961&view=rev
Log:
Move some handlers which are james specific
Try to work on a more generic smtpserver to factor it out later

Added:
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidRcptHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java
      - copied, changed from r826597, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineMessageHookHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesDataCmdHandler.java
      - copied, changed from r826597, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesMessageHook.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesRcptCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesSPFHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/SendMailHandler.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SendMailHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/SenderAuthIdentifyVerificationRcptHook.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SenderAuthIdentifyVerificationRcptHook.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/SetMimeHeaderHandler.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SetMimeHeaderHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/SpamAssassinHandler.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SpamAssassinHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/TLDLookup.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/TLDLookup.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/URIRBLHandler.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/URIRBLHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/URIScanner.java
      - copied, changed from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/URIScanner.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/ValidRcptHandler.java
Removed:
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SendMailHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SenderAuthIdentifyVerificationRcptHook.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SetMimeHeaderHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SpamAssassinHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/TLDLookup.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/URIRBLHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/URIScanner.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidRcptHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataCmdHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineMessageHookHandler.java
Modified:
    james/server/trunk/phoenix-deployment/src/conf/james-smtphandlerchain.xml
    james/server/trunk/smtp-protocol-library/pom.xml
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SPFHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/AddDefaultAttributesMessageHook.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/CoreCmdHandlerLoader.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java

Modified: james/server/trunk/phoenix-deployment/src/conf/james-smtphandlerchain.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/conf/james-smtphandlerchain.xml?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-smtphandlerchain.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-smtphandlerchain.xml Tue Oct 20 05:47:23 2009
@@ -72,7 +72,7 @@
      <!-- If checkAuthNetworks is set to true sender domain will be checked also for clients that -->
      <!-- are allowed to relay. Default is false. -->  
      <!--
-     <handler class="org.apache.james.smtpserver.core.fastfail.SPFHandler">
+     <handler class="org.apache.james.smtpserver.integration.JamesSPFHandler">
          <checkAuthNetworks> false </checkAuthNetworks>
          <blockSoftFail> false </blockSoftFail>
          <blockPermError> true </blockPermError>
@@ -171,7 +171,7 @@
      <!-- accept the email. So its possible to reject a message on smtplevel if a -->
      <!-- configured hits amount is reached. -->
      <!--
-     <handler class="org.apache.james.smtpserver.core.fastfail.SpamAssassinHandler">
+     <handler class="org.apache.james.smtpserver.integration.SpamAssassinHandler">
          <spamdHost> 127.0.0.1 </spamdHost>
          <spamdPort> 783 </spamdPort>
          <spamdRejectionHits> 10 </spamdRejectionHits>
@@ -183,7 +183,7 @@
      <!-- this domains against uriRbllists. See http://www.surbl.org for more informations. -->
      <!-- The message get rejected if a domain matched . -->
      <!--
-     <handler class="org.apache.james.smtpserver.core.fastfail.URIRBLHandler">
+     <handler class="org.apache.james.smtpserver.integration.URIRBLHandler">
          <action> reject </action>
          <getDetail> true </getDetail>
          <checkAuthNetworks> false </checkAuthNetworks>
@@ -194,7 +194,7 @@
      -->
      
      <!-- 
-     <handler class="org.apache.james.smtpserver.core.SetMimeHeaderHandler">
+     <handler class="org.apache.james.smtpserver.integration.SetMimeHeaderHandler">
          <headername>SPF-test</headername>
          <headervalue>passed</headervalue>
      </handler>
@@ -203,5 +203,5 @@
      <!--  The default message receiving handler -->
      <!--  The default behaviour is to put the message in the root processor of -->
      <!--  the spooler -->
-     <handler class="org.apache.james.smtpserver.core.SendMailHandler"></handler>
+     <handler class="org.apache.james.smtpserver.integration.SendMailHandler"></handler>
 </handlerchain>

Modified: james/server/trunk/smtp-protocol-library/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/pom.xml?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/pom.xml (original)
+++ james/server/trunk/smtp-protocol-library/pom.xml Tue Oct 20 05:47:23 2009
@@ -34,18 +34,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
-      <artifactId>james-server-user-api</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.james</groupId>
       <artifactId>james-server-domain-api</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.james</groupId>
-      <artifactId>james-server-javamail-util</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.james</groupId>
       <artifactId>james-server-common-util</artifactId>
     </dependency>
     <dependency>
@@ -77,12 +69,25 @@
       <artifactId>apache-jspf</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.apache.excalibur.components</groupId>
-      <artifactId>excalibur-datasource</artifactId>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mailet-base</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.mail</groupId>
+          <artifactId>mail</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.apache.avalon.cornerstone.datasources</groupId>
-      <artifactId>cornerstone-datasources-api</artifactId>
+      <groupId>org.apache.james</groupId>
+      <artifactId>james-server-javamail-util</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.mail</groupId>
+          <artifactId>mail</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
+    
   </dependencies>
 </project>
\ No newline at end of file

Added: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java?rev=826961&view=auto
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java (added)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java Tue Oct 20 05:47:23 2009
@@ -0,0 +1,42 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.protocol;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.mailet.MailAddress;
+
+public interface MailEnvelope {
+
+	public int getSize();
+
+	public List<MailAddress> getRecipients();
+
+	public MailAddress getSender();
+
+	public void setRecipients(List<MailAddress> recipientCollection);
+
+	public OutputStream getBodyOutputStream() throws Exception;
+
+	public InputStream getBodyInputStream() throws Exception;
+}

Added: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java?rev=826961&view=auto
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java (added)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java Tue Oct 20 05:47:23 2009
@@ -0,0 +1,71 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.protocol;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.mailet.MailAddress;
+
+public class MailEnvelopeImpl implements MailEnvelope{
+
+    private List<MailAddress> recipients;
+
+    private MailAddress sender;
+
+    private ByteArrayOutputStream outputStream;
+
+    public int getSize() {
+        if (outputStream == null)
+            return -1;
+        return outputStream.size();
+    }
+
+    public List<MailAddress> getRecipients() {
+        return recipients;
+    }
+
+    public MailAddress getSender() {
+        return sender;
+    }
+
+    public void setRecipients(List<MailAddress> recipientCollection) {
+        this.recipients = recipientCollection;
+    }
+
+    public void setSender(MailAddress sender) {
+        this.sender = sender;
+    }
+
+    public OutputStream getBodyOutputStream() {
+        this.outputStream = new ByteArrayOutputStream(100000);
+        return outputStream;
+    }
+
+    public InputStream getBodyInputStream() {
+        return new ByteArrayInputStream(outputStream.toByteArray());
+    }
+}
+
+

Added: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java?rev=826961&view=auto
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java (added)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java Tue Oct 20 05:47:23 2009
@@ -0,0 +1,163 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.smtpserver.protocol.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.api.protocol.ExtensibleHandler;
+import org.apache.james.api.protocol.WiringException;
+import org.apache.james.dsn.DSNStatus;
+import org.apache.james.smtpserver.protocol.CommandHandler;
+import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.MailEnvelopeImpl;
+import org.apache.james.smtpserver.protocol.SMTPRequest;
+import org.apache.james.smtpserver.protocol.SMTPResponse;
+import org.apache.james.smtpserver.protocol.SMTPRetCode;
+import org.apache.james.smtpserver.protocol.SMTPSession;
+import org.apache.mailet.MailAddress;
+
+
+/**
+  * handles DATA command
+ */
+public class DataCmdHandler implements CommandHandler, ExtensibleHandler {
+
+    public final class DataConsumerLineHandler implements LineHandler {
+        /**
+         * @see org.apache.james.smtpserver.protocol.LineHandler#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[])
+         */
+        public void onLine(SMTPSession session, byte[] line) {
+            // Discard everything until the end of DATA session
+            if (line.length == 3 && line[0] == 46) {
+                session.popLineHandler();
+            }
+        }
+    }
+
+    public final class DataLineFilterWrapper implements LineHandler {
+
+        private DataLineFilter filter;
+        private LineHandler next;
+        
+        public DataLineFilterWrapper(DataLineFilter filter, LineHandler next) {
+            this.filter = filter;
+            this.next = next;
+        }
+        public void onLine(SMTPSession session, byte[] line) {
+            filter.onLine(session, line, next);
+        }
+                
+    }
+   
+    public final static String MAILENV = "MAILENV";
+    
+    private LineHandler lineHandler;
+    
+    /**
+     * process DATA command
+     *
+     * @see org.apache.james.smtpserver.protocol.CommandHandler#onCommand(SMTPSession)
+     */
+    public SMTPResponse onCommand(SMTPSession session, SMTPRequest request) {
+        String parameters = request.getArgument();
+        SMTPResponse response = doDATAFilter(session,parameters);
+        
+        if (response == null) {
+            return doDATA(session, parameters);
+        } else {
+            return response;
+        }
+    }
+
+
+    /**
+     * Handler method called upon receipt of a DATA command.
+     * Reads in message data, creates header, and delivers to
+     * mail server service for delivery.
+     *
+     * @param session SMTP session object
+     * @param argument the argument passed in with the command by the SMTP client
+     */
+    @SuppressWarnings("unchecked")
+    protected SMTPResponse doDATA(SMTPSession session, String argument) {
+        MailEnvelopeImpl env = new MailEnvelopeImpl();
+        env.setRecipients(new ArrayList<MailAddress>((Collection)session.getState().get(SMTPSession.RCPT_LIST)));
+        env.setSender((MailAddress) session.getState().get(SMTPSession.SENDER));
+        session.getState().put(MAILENV, env);
+        session.pushLineHandler(lineHandler);
+        
+        return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>");
+    }
+    
+    /**
+     * @see org.apache.james.smtpserver.protocol.CommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        Collection<String> implCommands = new ArrayList<String>();
+        implCommands.add("DATA");
+        
+        return implCommands;
+    }
+
+
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#getMarkerInterfaces()
+     */
+    public List getMarkerInterfaces() {
+        List classes = new LinkedList();
+        classes.add(DataLineFilter.class);
+        return classes;
+    }
+
+
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
+     */
+    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
+        if (DataLineFilter.class.equals(interfaceName)) {
+
+            LineHandler lineHandler = new DataConsumerLineHandler();
+            for (int i = extension.size() - 1; i >= 0; i--) {
+                lineHandler = new DataLineFilterWrapper((DataLineFilter) extension.get(i), lineHandler);
+            }
+
+            this.lineHandler = lineHandler;
+        }
+    }
+
+    protected SMTPResponse doDATAFilter(SMTPSession session, String argument) {
+        if ((argument != null) && (argument.length() > 0)) {
+            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with DATA command");
+        }
+        if (!session.getState().containsKey(SMTPSession.SENDER)) {
+            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No sender specified");
+        } else if (!session.getState().containsKey(SMTPSession.RCPT_LIST)) {
+            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No recipients specified");
+        }
+        return null;
+    }
+    
+    protected LineHandler getLineHandler() {
+    	return lineHandler;
+    }
+
+}

Added: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java?rev=826961&view=auto
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java (added)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java Tue Oct 20 05:47:23 2009
@@ -0,0 +1,169 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.smtpserver.protocol.core;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.api.protocol.ExtensibleHandler;
+import org.apache.james.api.protocol.LogEnabled;
+import org.apache.james.api.protocol.WiringException;
+import org.apache.james.dsn.DSNStatus;
+import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.MailEnvelopeImpl;
+import org.apache.james.smtpserver.protocol.SMTPResponse;
+import org.apache.james.smtpserver.protocol.SMTPRetCode;
+import org.apache.james.smtpserver.protocol.SMTPSession;
+import org.apache.james.smtpserver.protocol.hook.HookResult;
+import org.apache.james.smtpserver.protocol.hook.HookResultHook;
+import org.apache.james.smtpserver.protocol.hook.MessageHook;
+import org.apache.mailet.Mail;
+
+public final class DataLineMessageHookHandler implements DataLineFilter, ExtensibleHandler, LogEnabled {
+
+    /** This log is the fall back shared by all instances */
+    private static final Log FALLBACK_LOG = LogFactory.getLog(DataLineMessageHookHandler.class);
+    
+    /** Non context specific log should only be used when no context specific log is available */
+    private Log serviceLog = FALLBACK_LOG;
+    
+    private List messageHandlers;
+    
+    private List rHooks;
+    
+    /**
+     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
+     */
+    public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+        MailEnvelopeImpl env = (MailEnvelopeImpl) session.getState().get(DataCmdHandler.MAILENV);
+        OutputStream out = env.getBodyOutputStream();
+        
+        try {
+            // 46 is "."
+            // Stream terminated
+            if (line.length == 3 && line[0] == 46) {
+                out.flush();
+                out.close();
+                
+                processExtensions(session, env);
+                session.popLineHandler();
+
+            // DotStuffing.
+            } else if (line[0] == 46 && line[1] == 46) {
+                out.write(line,1,line.length-1);
+            // Standard write
+            } else {
+                // TODO: maybe we should handle the Header/Body recognition here
+                // and if needed let a filter to cache the headers to apply some
+                // transformation before writing them to output.
+                out.write(line);
+            }
+            out.flush();
+        } catch (IOException e) {
+            SMTPResponse response;
+            response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT,
+                            DSNStatus.UNDEFINED_STATUS) + " Error processing message: " + e.getMessage());
+            
+            session.getLogger().error(
+                    "Unknown error occurred while processing DATA.", e);
+            session.writeSMTPResponse(response);
+            return;
+        }
+    }
+
+
+    /**
+     * @param session
+     */
+    private void processExtensions(SMTPSession session, MailEnvelopeImpl mail) {
+        if(mail != null && mail instanceof Mail && messageHandlers != null) {
+            try {
+                int count = messageHandlers.size();
+                for(int i =0; i < count; i++) {
+                    Object rawHandler =  messageHandlers.get(i);
+                    session.getLogger().debug("executing message handler " + rawHandler);
+                    HookResult hRes = ((MessageHook)rawHandler).onMessage(session, mail);
+                    
+                    if (rHooks != null) {
+                        for (int i2 = 0; i2 < rHooks.size(); i2++) {
+                            Object rHook = rHooks.get(i2);
+                            session.getLogger().debug("executing hook " + rHook);
+                            hRes = ((HookResultHook) rHook).onHookResult(session, hRes, rawHandler);
+                        }
+                    }
+                    
+                    SMTPResponse response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(hRes);
+                    
+                    //if the response is received, stop processing of command handlers
+                    if(response != null) {
+                        session.writeSMTPResponse(response);
+                        break;
+                    }
+                }
+            } finally {
+               
+                //do the clean up
+                session.resetState();
+            }
+        }
+    }
+    
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
+     */
+    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
+        if (MessageHook.class.equals(interfaceName)) {
+            this.messageHandlers = extension;
+            if (messageHandlers.size() == 0) {
+                if (serviceLog.isErrorEnabled()) {
+                    serviceLog.error("No messageHandler configured. Check that SendMailHandler is configured in the SMTPHandlerChain");
+                }
+                throw new WiringException("No messageHandler configured");
+            }
+        } else if (HookResultHook.class.equals(interfaceName)) {
+            this.rHooks = extension;
+        }
+    }
+
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#getMarkerInterfaces()
+     */
+    public List<Class<?>> getMarkerInterfaces() {
+        List<Class<?>> classes = new LinkedList<Class<?>>();
+        classes.add(MessageHook.class);
+        classes.add(HookResultHook.class);
+        return classes;
+    }
+
+    /**
+     * Sets the service log.
+     * Where available, a context sensitive log should be used.
+     * @param Log not null
+     */
+    public void setLog(Log log) {
+        this.serviceLog = log;
+    }
+}
\ No newline at end of file

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java Tue Oct 20 05:47:23 2009
@@ -24,10 +24,7 @@
 import java.util.Locale;
 import java.util.StringTokenizer;
 
-import javax.annotation.Resource;
-
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.services.MailServer;
 import org.apache.james.smtpserver.protocol.CommandHandler;
 import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
@@ -44,24 +41,7 @@
 
     public static final String CURRENT_RECIPIENT = "CURRENT_RECIPIENT"; // Current recipient
 
-    private MailServer mailServer;
-    
-    /**
-     * Gets the mail server.
-     * @return the mailServer
-     */
-    public final MailServer getMailServer() {
-        return mailServer;
-    }
-
-    /**
-     * Sets the mail server.
-     * @param mailServer the mailServer to set
-     */
-    @Resource(name="James")
-    public final void setMailServer(MailServer mailServer) {
-        this.mailServer = mailServer;
-    }
+   
     
     /**
      * Handler method called upon receipt of a RCPT command. Reads recipient.
@@ -165,7 +145,7 @@
             // set the default domain
             recipient = recipient
                     + "@"
-                    + mailServer.getDefaultDomain();
+                    + getDefaultDomain();
         }
 
         try {
@@ -276,4 +256,7 @@
                 (MailAddress) session.getState().get(CURRENT_RECIPIENT));
     }
 
+    protected String getDefaultDomain() {
+    	return "localhost";
+    }
 }

Added: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java?rev=826961&view=auto
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java (added)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java Tue Oct 20 05:47:23 2009
@@ -0,0 +1,114 @@
+package org.apache.james.smtpserver.protocol.core;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.SMTPSession;
+import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.RFC822DateFormat;
+
+public class ReceivedDataLineFilter implements DataLineFilter{
+
+    private final static String SOFTWARE_TYPE = "JAMES SMTP Server ";
+    	
+    // Replace this with something usefull
+    // + Constants.SOFTWARE_VERSION;  
+
+    /**
+     * Static RFC822DateFormat used to generate date headers
+     */
+    private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
+	private final static String HEADERS_WRITTEN = "HEADERS_WRITTEN";
+	
+	/**
+	 * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
+	 */
+	public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+		if (session.getState().containsKey(HEADERS_WRITTEN) == false) {
+			addNewReceivedMailHeaders(session, next);
+			session.getState().put(HEADERS_WRITTEN, true);
+		} 
+		next.onLine(session, line);
+	}
+
+ 
+    private void addNewReceivedMailHeaders(SMTPSession session, LineHandler next) {
+        StringBuilder headerLineBuffer = new StringBuilder();
+        
+        String heloMode = (String) session.getConnectionState().get(SMTPSession.CURRENT_HELO_MODE);
+        String heloName = (String) session.getConnectionState().get(SMTPSession.CURRENT_HELO_NAME);
+
+        // Put our Received header first
+        headerLineBuffer.append(RFC2822Headers.RECEIVED + ": from ")
+                        .append(session.getRemoteHost());
+        
+        if (heloName != null) {
+            headerLineBuffer.append(" (")
+                            .append(heloMode)
+                            .append(" ")
+                            .append(heloName)
+                            .append(") ");
+        }
+        
+        headerLineBuffer.append(" ([")
+                        .append(session.getRemoteIPAddress())
+                        .append("])");
+        
+        next.onLine(session,headerLineBuffer.toString().getBytes());
+        headerLineBuffer.delete(0, headerLineBuffer.length());
+        
+        headerLineBuffer.append("          by ")
+                        .append(session.getHelloName())
+                        .append(" (")
+                        .append(SOFTWARE_TYPE)
+                        .append(") with ");
+     
+        // Check if EHLO was used 
+        if ("EHLO".equals(heloMode)) {
+            // Not successful auth
+            if (session.getUser() == null) {
+                headerLineBuffer.append("ESMTP");  
+            } else {
+                // See RFC3848
+                // The new keyword "ESMTPA" indicates the use of ESMTP when the SMTP
+                // AUTH [3] extension is also used and authentication is successfully
+                // achieved.
+                headerLineBuffer.append("ESMTPA");
+            }
+        } else {
+            headerLineBuffer.append("SMTP");
+        }
+        
+        headerLineBuffer.append(" ID ")
+                        .append(session.getSessionID());
+
+        if (((Collection) session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) {
+            // Only indicate a recipient if they're the only recipient
+            // (prevents email address harvesting and large headers in
+            //  bulk email)
+            
+            next.onLine(session,headerLineBuffer.toString().getBytes());
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+            
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+            headerLineBuffer.append("          for <")
+                            .append(((List) session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString())
+                            .append(">;");            
+            
+            next.onLine(session,headerLineBuffer.toString().getBytes());
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+            
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+        } else {
+            // Put the ; on the end of the 'by' line
+            headerLineBuffer.append(";");
+            
+            next.onLine(session,headerLineBuffer.toString().getBytes());
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+        }
+        headerLineBuffer = null;
+        next.onLine(session,("          " + rfc822DateFormat.format(new Date())).getBytes());
+    }
+}

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java Tue Oct 20 05:47:23 2009
@@ -8,6 +8,7 @@
 
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.MailEnvelope;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
 import org.apache.james.smtpserver.protocol.SMTPSession;
 import org.apache.james.smtpserver.protocol.core.DataLineFilter;
@@ -15,7 +16,6 @@
 import org.apache.james.smtpserver.protocol.hook.HookReturnCode;
 import org.apache.james.smtpserver.protocol.hook.MailParametersHook;
 import org.apache.james.smtpserver.protocol.hook.MessageHook;
-import org.apache.mailet.Mail;
 
 /**
  * Handle the ESMTP SIZE extension.
@@ -155,9 +155,9 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.protocol.hook.MessageHook#onMessage(org.apache.james.smtpserver.protocol.SMTPSession, org.apache.mailet.Mail)
+     * @see org.apache.james.smtpserver.protocol.hook.MessageHook#onMessage(org.apache.james.smtpserver.protocol.SMTPSession, org.apache.james.smtpserver.protocol.MailEnvelopeImpl)
      */
-    public HookResult onMessage(SMTPSession session, Mail mail) {
+    public HookResult onMessage(SMTPSession session, MailEnvelope mail) {
         Boolean failed = (Boolean) session.getState().get(MESG_FAILED);
         if (failed != null && failed.booleanValue()) {
             HookResult response = new HookResult(HookReturnCode.DENY, SMTPRetCode.QUOTA_EXCEEDED,DSNStatus.getStatus(DSNStatus.PERMANENT,
@@ -172,8 +172,6 @@
                     .append(
                             session.getMaxMessageSize());
             session.getLogger().error(errorBuffer.toString());
-            // TODO ???
-            // session.pushLineHandler(new DataCmdHandler.DataConsumerLineHandler());
             return response;
         } else {
             return new HookResult(HookReturnCode.DECLINED);

Copied: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java (from r826597, james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidRcptHandler.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java?p2=james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java&p1=james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidRcptHandler.java&r1=826597&r2=826961&rev=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidRcptHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java Tue Oct 20 05:47:23 2009
@@ -22,178 +22,21 @@
 
 package org.apache.james.smtpserver.protocol.core.fastfail;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.james.api.protocol.Configurable;
-import org.apache.james.api.protocol.LogEnabled;
-import org.apache.james.api.user.UsersRepository;
-import org.apache.james.api.vut.ErrorMappingException;
-import org.apache.james.api.vut.VirtualUserTable;
-import org.apache.james.api.vut.VirtualUserTableStore;
 import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
 import org.apache.james.smtpserver.protocol.SMTPSession;
 import org.apache.james.smtpserver.protocol.hook.HookResult;
 import org.apache.james.smtpserver.protocol.hook.HookReturnCode;
 import org.apache.james.smtpserver.protocol.hook.RcptHook;
 import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
+
 
 /**
- * Handler which reject invalid recipients
+ * Handler which want todo an recipient check should extend this
+ *
  */
-public class ValidRcptHandler implements LogEnabled, RcptHook, Configurable {
-    
-
-    /** This log is the fall back shared by all instances */
-    private static final Log FALLBACK_LOG = LogFactory.getLog(ValidRcptHandler.class);
-    
-    /** Non context specific log should only be used when no context specific log is available */
-    private Log serviceLog = FALLBACK_LOG;
-    
-    private UsersRepository users;
-    
-    private VirtualUserTableStore tableStore;
-
-    private Collection<String> recipients = new ArrayList<String>();
-    private Collection<String> domains = new ArrayList<String>();
-    private Collection<Pattern> regex = new ArrayList<Pattern>();
-    private boolean vut = true;
-    private VirtualUserTable table;
-    private String tableName = null;
-
-    
-    /**
-     * Gets the users repository.
-     * @return the users
-     */
-    public final UsersRepository getUsers() {
-        return users;
-    }
-
-    /**
-     * Sets the users repository.
-     * @param users the users to set
-     */
-    @Resource(name="localusersrepository")
-    public final void setUsers(UsersRepository users) {
-        this.users = users;
-    }    
-    
-    /**
-     * Gets the virtual user table store.
-     * @return the tableStore
-     */
-    public final VirtualUserTableStore getTableStore() {
-        return tableStore;
-    }
-
-    /**
-     * Sets the virtual user table store.
-     * @param tableStore the tableStore to set
-     */
-    @Resource(name="virtualusertable-store")
-    public final void setTableStore(VirtualUserTableStore tableStore) {
-        this.tableStore = tableStore;
-        loadTable();
-    }
-    
+public abstract class AbstractValidRcptHandler implements RcptHook {
 
-    /**
-     * @see org.apache.james.api.protocol.Configurable#configure(org.apache.commons.configuration.Configuration)
-     */
-    @SuppressWarnings("unchecked")
-	public void configure(Configuration config) throws ConfigurationException {
-        setValidRecipients(config.getList("validRecipients"));
-        setValidDomains(config.getList("validDomains"));
-        try {
-            setValidRegex(config.getList("validRegexPattern"));
-        } catch(MalformedPatternException mpe) {
-            throw new ConfigurationException("Malformed pattern: ", mpe);
-        }
-        setVirtualUserTableSupport(config.getBoolean("enableVirtualUserTable",true));    
-    	setTableName(config.getString("table",null));   
-    }
-    
-    /**
-     * Set the valid recipients. 
-     * 
-     * @param recip The valid recipients. Commaseperated list
-     */
-    public void setValidRecipients(Collection<String> recips) {
-    	Iterator<String> recipsIt = recips.iterator();
-    	while (recipsIt.hasNext()) {
-            String recipient = recipsIt.next();
-            
-            serviceLog.debug("Add recipient to valid recipients: " + recipient);
-            recipients.add(recipient);
-    	}
-    }
-
-    /**
-     * Set the domains for which every rcpt will be accepted. 
-     * 
-     * @param dom The valid domains. Comma seperated list
-     */
-    public void setValidDomains(Collection<String> doms) {
-    	Iterator<String> domsIt = doms.iterator();
-    	
-        while (domsIt.hasNext()) {
-            String domain = domsIt.next().toLowerCase();
-            serviceLog.debug("Add domain to valid domains: " + domain);
-            domains.add(domain);
-        }  
-    }
-    
-    /**
-     * 
-     * @param reg 
-     * @throws MalformedPatternException
-     */
-    public void setValidRegex(Collection<String> regs) throws MalformedPatternException {
-        Perl5Compiler compiler = new Perl5Compiler();
-                
-        Iterator<String> regsIt = regs.iterator();
-        while (regsIt.hasNext()) {
-            String patternString = regsIt.next();
-
-            serviceLog.debug("Add regex to valid regex: " + patternString);
-            
-            Pattern pattern = compiler.compile(patternString, Perl5Compiler.READ_ONLY_MASK);
-            regex.add(pattern);
-
-        }  
-    }
-    
-    public void setVirtualUserTableSupport(boolean vut) {
-        this.vut = vut;
-    }
-
-    public void setTableName(String tableName) {
-    	this.tableName = tableName;
-        loadTable();
-    }
-
-    private void loadTable() {
-        if (this.tableName == null || this.tableName.equals("")) {
-            this.tableName =  VirtualUserTableStore.DEFAULT_TABLE;
-        }
-        if (tableStore != null) {
-            table = tableStore.getTable(this.tableName);
-        }
-    }
     
     /**
      * @see org.apache.james.smtpserver.protocol.hook.RcptHook#doRcpt(org.apache.james.smtpserver.protocol.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
@@ -201,42 +44,7 @@
     public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {
         
         if (!session.isRelayingAllowed()) {
-            boolean invalidUser = true;
-
-            if (users.contains(rcpt.getLocalPart()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getDomain().toLowerCase())) {
-                invalidUser = false;
-            }
-
-            // check if an valid virtual mapping exists
-            if (invalidUser == true  && vut == true) {
-                try {
-                    Collection<String> targetString = table.getMappings(rcpt.getLocalPart(), rcpt.getDomain());
-            
-                    if (targetString != null && targetString.isEmpty() == false) {
-                        invalidUser = false;
-                    }
-                } catch (ErrorMappingException e) {
-                    String responseString = e.getMessage();
-                    session.getLogger().info("Rejected message. Reject Message: " + responseString);
-                    SMTPResponse resp = new SMTPResponse(responseString);
-                    return new HookResult(HookReturnCode.DENY,resp.getRetCode(),resp.getLines().get(0));
-                }
-            }
-            
-            if (invalidUser == true && !regex.isEmpty()) {
-                Iterator<Pattern> reg = regex.iterator();
-                Perl5Matcher matcher  = new Perl5Matcher();
-                
-                while (reg.hasNext()) {
-                    if (matcher.matches(rcpt.toString(), reg.next())) {
-                        // regex match
-                        invalidUser = false;
-                        break;
-                    }
-                }
-            }
-        
-            if (invalidUser == true) {
+            if (isValidRecipient(session, rcpt) == false) {
                 //user not exist
                 session.getLogger().info("Rejected message. Unknown user: " + rcpt.toString());
                 return new HookResult(HookReturnCode.DENY,SMTPRetCode.TRANSACTION_FAILED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_MAILBOX) + " Unknown user: " + rcpt.toString());
@@ -247,12 +55,12 @@
         return new HookResult(HookReturnCode.DECLINED);
     }
     
+  
     /**
-     * Sets the service log.
-     * Where available, a context sensitive log should be used.
-     * @param Log not null
+     * Return true if email for the given recipient should get accepted
+     * 
+     * @param recipient
+     * @return isValid
      */
-    public void setLog(Log log) {
-        this.serviceLog = log;
-    }
+    protected abstract boolean isValidRecipient(SMTPSession session, MailAddress recipient);
 }

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java Tue Oct 20 05:47:23 2009
@@ -34,7 +34,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.protocol.Configurable;
-import org.apache.james.api.protocol.LogEnabled;
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.smtpserver.protocol.ConnectHandler;
 import org.apache.james.smtpserver.protocol.SMTPSession;
@@ -46,7 +45,7 @@
 /**
   * Connect handler for DNSRBL processing
   */
-public class DNSRBLHandler implements LogEnabled, ConnectHandler, RcptHook, Configurable{
+public class DNSRBLHandler implements  ConnectHandler, RcptHook, Configurable{
     
     /** This log is the fall back shared by all instances */
     private static final Log FALLBACK_LOG = LogFactory.getLog(DNSRBLHandler.class);
@@ -70,15 +69,6 @@
     
     public static final String RBL_DETAIL_MAIL_ATTRIBUTE_NAME = "org.apache.james.smtpserver.rbl.detail";
 
-
-    /**
-     * Sets the service log.
-     * Where available, a context sensitive log should be used.
-     * @param Log not null
-     */
-    public void setLog(Log log) {
-        this.serviceLog = log;
-    }
     
     /**
      * Gets the DNS service.

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SPFHandler.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SPFHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SPFHandler.java Tue Oct 20 05:47:23 2009
@@ -38,9 +38,7 @@
 import org.apache.james.smtpserver.protocol.hook.HookResult;
 import org.apache.james.smtpserver.protocol.hook.HookReturnCode;
 import org.apache.james.smtpserver.protocol.hook.MailHook;
-import org.apache.james.smtpserver.protocol.hook.MessageHook;
 import org.apache.james.smtpserver.protocol.hook.RcptHook;
-import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
 /**
@@ -55,7 +53,7 @@
  * &lt;checkAuthNetworks&gt;false&lt/checkAuthNetworks&gt; 
  * &lt;/handler&gt;
  */
-public class SPFHandler implements LogEnabled, MailHook, RcptHook, MessageHook,Configurable {
+public class SPFHandler implements LogEnabled, MailHook, RcptHook, Configurable {
     
     /** This log is the fall back shared by all instances */
     private static final Log FALLBACK_LOG = LogFactory.getLog(SPFHandler.class);
@@ -204,16 +202,6 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.protocol.hook.MessageHook#onMessage(org.apache.james.smtpserver.protocol.SMTPSession, org.apache.mailet.Mail)
-     */
-    public HookResult onMessage(SMTPSession session, Mail mail) {
-        // Store the spf header as attribute for later using
-        mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session.getState().get(SPF_HEADER));
-    
-        return null;
-    }
-    
-    /**
      * @see org.apache.james.smtpserver.protocol.hook.RcptHook#doRcpt(org.apache.james.smtpserver.protocol.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress)
      */
     public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) {

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java Tue Oct 20 05:47:23 2009
@@ -1,36 +1,35 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.smtpserver.protocol.hook;
-
-import org.apache.james.smtpserver.protocol.SMTPSession;
-import org.apache.mailet.Mail;
-
-/**
- * Custom message handlers must implement this interface
- * The message hooks will be server-wide common to all the SMTPHandlers,
- * therefore the handlers must store all the state information
- * in the SMTPSession object
- */
-public interface MessageHook {
-    /**
-     * Handle Message
-     */
-    HookResult onMessage(SMTPSession session, Mail mail);
-
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.smtpserver.protocol.hook;
+
+import org.apache.james.smtpserver.protocol.MailEnvelope;
+import org.apache.james.smtpserver.protocol.SMTPSession;
+
+/**
+ * Custom message handlers must implement this interface The message hooks will
+ * be server-wide common to all the SMTPHandlers, therefore the handlers must
+ * store all the state information in the SMTPSession object
+ */
+public interface MessageHook {
+	/**
+	 * Handle Message
+	 */
+	HookResult onMessage(SMTPSession session, MailEnvelope mail);
+
+}

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/AddDefaultAttributesMessageHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/AddDefaultAttributesMessageHook.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/AddDefaultAttributesMessageHook.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/AddDefaultAttributesMessageHook.java Tue Oct 20 05:47:23 2009
@@ -22,13 +22,12 @@
 import org.apache.james.smtpserver.protocol.SMTPSession;
 import org.apache.james.smtpserver.protocol.hook.HookResult;
 import org.apache.james.smtpserver.protocol.hook.HookReturnCode;
-import org.apache.james.smtpserver.protocol.hook.MessageHook;
 import org.apache.mailet.Mail;
 
 /**
  * This hook adds the default attributes to the just created Mail 
  */
-public class AddDefaultAttributesMessageHook implements MessageHook {
+public class AddDefaultAttributesMessageHook implements JamesMessageHook {
 
     /**
      * The mail attribute holding the SMTP AUTH user name, if any.

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/CoreCmdHandlerLoader.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/CoreCmdHandlerLoader.java?rev=826961&r1=826960&r2=826961&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/CoreCmdHandlerLoader.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/CoreCmdHandlerLoader.java Tue Oct 20 05:47:23 2009
@@ -30,11 +30,9 @@
 import org.apache.james.smtpserver.protocol.core.NoopCmdHandler;
 import org.apache.james.smtpserver.protocol.core.PostmasterAbuseRcptHook;
 import org.apache.james.smtpserver.protocol.core.QuitCmdHandler;
-import org.apache.james.smtpserver.protocol.core.RcptCmdHandler;
+import org.apache.james.smtpserver.protocol.core.ReceivedDataLineFilter;
 import org.apache.james.smtpserver.protocol.core.RsetCmdHandler;
 import org.apache.james.smtpserver.protocol.core.SMTPCommandDispatcherLineHandler;
-import org.apache.james.smtpserver.protocol.core.SendMailHandler;
-import org.apache.james.smtpserver.protocol.core.SenderAuthIdentifyVerificationRcptHook;
 import org.apache.james.smtpserver.protocol.core.VrfyCmdHandler;
 import org.apache.james.smtpserver.protocol.core.esmtp.AuthCmdHandler;
 import org.apache.james.smtpserver.protocol.core.esmtp.EhloCmdHandler;
@@ -51,7 +49,7 @@
 
     private final String COMMANDDISPATCHER = SMTPCommandDispatcherLineHandler.class.getName();
     private final String AUTHCMDHANDLER = AuthCmdHandler.class.getName();
-    private final String DATACMDHANDLER = DataCmdHandler.class.getName();
+    private final String DATACMDHANDLER = JamesDataCmdHandler.class.getName();
     private final String EHLOCMDHANDLER = EhloCmdHandler.class.getName();
     private final String EXPNCMDHANDLER = ExpnCmdHandler.class.getName();
     private final String HELOCMDHANDLER = HeloCmdHandler.class.getName();
@@ -59,7 +57,7 @@
     private final String MAILCMDHANDLER = MailCmdHandler.class.getName();
     private final String NOOPCMDHANDLER = NoopCmdHandler.class.getName();
     private final String QUITCMDHANDLER = QuitCmdHandler.class.getName();
-    private final String RCPTCMDHANDLER = RcptCmdHandler.class.getName();
+    private final String RCPTCMDHANDLER = JamesRcptCmdHandler.class.getName();
     private final String RSETCMDHANDLER = RsetCmdHandler.class.getName();
     private final String VRFYCMDHANDLER = VrfyCmdHandler.class.getName();
     private final String MAILSIZEHOOK = MailSizeEsmtpExtension.class.getName();
@@ -68,7 +66,8 @@
     private final String POSTMASTERABUSEHOOK = PostmasterAbuseRcptHook.class.getName();
     private final String AUTHREQUIREDTORELAY = AuthRequiredToRelayRcptHook.class.getName();
     private final String SENDERAUTHIDENTITYVERIFICATION = SenderAuthIdentifyVerificationRcptHook.class.getName();
-    private final String DATALINEMESSAGEHOOKHANDLER = DataLineMessageHookHandler.class.getName();
+    private final String RECEIVEDDATALINEFILTER = ReceivedDataLineFilter.class.getName();
+    private final String DATALINEMESSAGEHOOKHANDLER = DataLineJamesMessageHookHandler.class.getName();
     private final String STARTTLSHANDLER = StartTlsCmdHandler.class.getName();
 
     // MessageHooks
@@ -98,6 +97,7 @@
         commands.add(AUTHREQUIREDTORELAY);
         commands.add(SENDERAUTHIDENTITYVERIFICATION);
         commands.add(POSTMASTERABUSEHOOK);
+        commands.add(RECEIVEDDATALINEFILTER);
         commands.add(DATALINEMESSAGEHOOKHANDLER);
         commands.add(STARTTLSHANDLER);
         // Add the default messageHooks

Copied: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java (from r826597, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineMessageHookHandler.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java?p2=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java&p1=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineMessageHookHandler.java&r1=826597&r2=826961&rev=826961&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineMessageHookHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java Tue Oct 20 05:47:23 2009
@@ -22,7 +22,9 @@
 package org.apache.james.smtpserver.integration;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -41,6 +43,7 @@
 import org.apache.james.dsn.DSNStatus;
 import org.apache.james.services.MailServer;
 import org.apache.james.smtpserver.protocol.LineHandler;
+import org.apache.james.smtpserver.protocol.MailEnvelope;
 import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
 import org.apache.james.smtpserver.protocol.SMTPSession;
@@ -52,19 +55,26 @@
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
-public final class DataLineMessageHookHandler implements DataLineFilter, ExtensibleHandler, LogEnabled {
+/**
+ * 
+ * Handles the calling of JamesMessageHooks
+ *
+ */
+public final class DataLineJamesMessageHookHandler implements DataLineFilter, ExtensibleHandler, LogEnabled {
 
     /** This log is the fall back shared by all instances */
-    private static final Log FALLBACK_LOG = LogFactory.getLog(DataLineMessageHookHandler.class);
+    private static final Log FALLBACK_LOG = LogFactory.getLog(DataLineJamesMessageHookHandler.class);
     
     /** Non context specific log should only be used when no context specific log is available */
     private Log serviceLog = FALLBACK_LOG;
     
-    private List messageHandlers;
+    private List<JamesMessageHook> messageHandlers;
     
-    private List rHooks;
+    private List<HookResultHook> rHooks;
     
     private MailServer mailServer;
+
+	private List<MessageHook> mHandlers;
     
     /**
      * Gets the mail server.
@@ -87,8 +97,8 @@
      * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
      */
     public void onLine(SMTPSession session, byte[] line, LineHandler next) {
-        MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(DataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE);
-        OutputStream out = (OutputStream)  session.getState().get(DataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM);
+        MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE);
+        OutputStream out = (OutputStream)  session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM);
         try {
             // 46 is "."
             // Stream terminated
@@ -145,61 +155,97 @@
         }
     }
 
+	/**
+	 * @param session
+	 */
+	private void processExtensions(SMTPSession session, Mail mail) {
+		if (mail != null && messageHandlers != null) {
+			try {
+				for (int i = 0; i < mHandlers.size(); i++) {
+					MessageHook rawHandler = mHandlers.get(i);
+					session.getLogger().debug(
+							"executing james message handler " + rawHandler);
+					HookResult hRes = rawHandler.onMessage(session,
+							new MailToMailEnvelopeWrapper(mail));
+
+					if (rHooks != null) {
+						for (int i2 = 0; i2 < rHooks.size(); i2++) {
+							Object rHook = rHooks.get(i2);
+							session.getLogger()
+									.debug("executing hook " + rHook);
+							hRes = ((HookResultHook) rHook).onHookResult(
+									session, hRes, rawHandler);
+						}
+					}
+
+					SMTPResponse response = AbstractHookableCmdHandler
+							.calcDefaultSMTPResponse(hRes);
+
+					// if the response is received, stop processing of command
+					// handlers
+					if (response != null) {
+						session.writeSMTPResponse(response);
+						return;
+					}
+				}
+
+				int count = messageHandlers.size();
+				for (int i = 0; i < count; i++) {
+					Object rawHandler = messageHandlers.get(i);
+					session.getLogger().debug(
+							"executing james message handler " + rawHandler);
+					HookResult hRes = ((JamesMessageHook) rawHandler)
+							.onMessage(session, (Mail) mail);
+
+					if (rHooks != null) {
+						for (int i2 = 0; i2 < rHooks.size(); i2++) {
+							Object rHook = rHooks.get(i2);
+							session.getLogger()
+									.debug("executing hook " + rHook);
+							hRes = ((HookResultHook) rHook).onHookResult(
+									session, hRes, rawHandler);
+						}
+					}
+
+					SMTPResponse response = AbstractHookableCmdHandler
+							.calcDefaultSMTPResponse(hRes);
+
+					// if the response is received, stop processing of command
+					// handlers
+					if (response != null) {
+						session.writeSMTPResponse(response);
+						break;
+					}
+				}
+			} finally {
+				// Dispose the mail object and remove it
+				if (mail != null) {
+					ContainerUtil.dispose(mail);
+					mail = null;
+				}
+				// do the clean up
+				session.resetState();
+			}
+		}
+	}
 
-    /**
-     * @param session
-     */
-    private void processExtensions(SMTPSession session, Mail mail) {
-        if(mail != null && mail instanceof Mail && messageHandlers != null) {
-            try {
-                int count = messageHandlers.size();
-                for(int i =0; i < count; i++) {
-                    Object rawHandler =  messageHandlers.get(i);
-                    session.getLogger().debug("executing message handler " + rawHandler);
-                    HookResult hRes = ((MessageHook)rawHandler).onMessage(session, (Mail) mail);
-                    
-                    if (rHooks != null) {
-                        for (int i2 = 0; i2 < rHooks.size(); i2++) {
-                            Object rHook = rHooks.get(i2);
-                            session.getLogger().debug("executing hook " + rHook);
-                            hRes = ((HookResultHook) rHook).onHookResult(session, hRes, rawHandler);
-                        }
-                    }
-                    
-                    SMTPResponse response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(hRes);
-                    
-                    //if the response is received, stop processing of command handlers
-                    if(response != null) {
-                        session.writeSMTPResponse(response);
-                        break;
-                    }
-                }
-            } finally {
-                // Dispose the mail object and remove it
-                if(mail != null) {
-                    ContainerUtil.dispose(mail);
-                    mail = null;
-                }
-                //do the clean up
-                session.resetState();
-            }
-        }
-    }
     
     /**
      * @see org.apache.james.api.protocol.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
      */
     public void wireExtensions(Class interfaceName, List extension) throws WiringException {
-        if (MessageHook.class.equals(interfaceName)) {
+        if (JamesMessageHook.class.equals(interfaceName)) {
             this.messageHandlers = extension;
             if (messageHandlers.size() == 0) {
                 if (serviceLog.isErrorEnabled()) {
-                    serviceLog.error(
-                                    "No messageHandler configured. Check that SendMailHandler is configured in the SMTPHandlerChain");
+                    serviceLog.error("No messageHandler configured. Check that SendMailHandler is configured in the SMTPHandlerChain");
                 }
                 throw new WiringException("No messageHandler configured");
             }
+        } else if (MessageHook.class.equals(interfaceName)) {
+        	this.mHandlers = extension;
         } else if (HookResultHook.class.equals(interfaceName)) {
+
             this.rHooks = extension;
         }
     }
@@ -209,6 +255,7 @@
      */
     public List<Class<?>> getMarkerInterfaces() {
         List<Class<?>> classes = new LinkedList<Class<?>>();
+        classes.add(JamesMessageHook.class);
         classes.add(MessageHook.class);
         classes.add(HookResultHook.class);
         return classes;
@@ -222,4 +269,60 @@
     public void setLog(Log log) {
         this.serviceLog = log;
     }
+    
+    private class MailToMailEnvelopeWrapper implements MailEnvelope {
+    	private Mail mail;
+    	public MailToMailEnvelopeWrapper(Mail mail) {
+    		this.mail = mail;
+    	}
+    	
+    	/**
+    	 * @see org.apache.james.smtpserver.protocol.MailEnvelope#getBodyInputStream()
+    	 */
+		public InputStream getBodyInputStream() throws Exception {
+			return mail.getMessage().getInputStream();
+		}
+		
+		/**
+		 * Return just null. Not sure if this is a good idea ..
+		 */
+		public OutputStream getBodyOutputStream() {
+			return null;
+		}
+
+		/**
+		 * @see org.apache.james.smtpserver.protocol.MailEnvelope#getRecipients()
+		 */
+		public List<MailAddress> getRecipients() {
+			return new ArrayList<MailAddress>(mail.getRecipients());
+		}
+
+		/**
+		 * (non-Javadoc)
+		 * @see org.apache.james.smtpserver.protocol.MailEnvelope#getSender()
+		 */
+		public MailAddress getSender() {
+			return mail.getSender();
+		}
+		
+		/**
+		 * @see org.apache.james.smtpserver.protocol.MailEnvelope#getSize()
+		 */
+		public int getSize() {
+			try {
+				return new Long(mail.getMessageSize()).intValue();
+			} catch (MessagingException e) {
+				return -1;
+			}
+		}
+
+		/**
+		 * (non-Javadoc)
+		 * @see org.apache.james.smtpserver.protocol.MailEnvelope#setRecipients(java.util.List)
+		 */
+		public void setRecipients(List<MailAddress> recipientCollection) {
+			mail.setRecipients(recipientCollection);
+		}
+    	
+    }
 }
\ No newline at end of file

Copied: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesDataCmdHandler.java (from r826597, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataCmdHandler.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesDataCmdHandler.java?p2=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesDataCmdHandler.java&p1=james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataCmdHandler.java&r1=826597&r2=826961&rev=826961&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataCmdHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/JamesDataCmdHandler.java Tue Oct 20 05:47:23 2009
@@ -20,82 +20,28 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
 
 import javax.annotation.Resource;
 import javax.mail.MessagingException;
 
-import org.apache.james.Constants;
-import org.apache.james.api.protocol.ExtensibleHandler;
-import org.apache.james.api.protocol.WiringException;
-import org.apache.james.core.MailHeaders;
 import org.apache.james.core.MimeMessageInputStreamSource;
-import org.apache.james.dsn.DSNStatus;
 import org.apache.james.services.MailServer;
-import org.apache.james.smtpserver.protocol.CommandHandler;
-import org.apache.james.smtpserver.protocol.LineHandler;
-import org.apache.james.smtpserver.protocol.SMTPRequest;
 import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
 import org.apache.james.smtpserver.protocol.SMTPSession;
-import org.apache.james.smtpserver.protocol.core.DataLineFilter;
-import org.apache.mailet.base.RFC2822Headers;
-import org.apache.mailet.base.RFC822DateFormat;
+import org.apache.james.smtpserver.protocol.core.DataCmdHandler;
 
 
 /**
   * handles DATA command
  */
-public class DataCmdHandler implements CommandHandler, ExtensibleHandler {
+public class JamesDataCmdHandler extends DataCmdHandler {
 
-    public final class DataConsumerLineHandler implements LineHandler {
-        /**
-         * @see org.apache.james.smtpserver.protocol.LineHandler#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[])
-         */
-        public void onLine(SMTPSession session, byte[] line) {
-            // Discard everything until the end of DATA session
-            if (line.length == 3 && line[0] == 46) {
-                session.popLineHandler();
-            }
-        }
-    }
-
-    private final class DataLineFilterWrapper implements LineHandler {
-
-        private DataLineFilter filter;
-        private LineHandler next;
-        
-        public DataLineFilterWrapper(DataLineFilter filter, LineHandler next) {
-            this.filter = filter;
-            this.next = next;
-        }
-        public void onLine(SMTPSession session, byte[] line) {
-            filter.onLine(session, line, next);
-        }
-                
-    }
     
     static final String DATA_MIMEMESSAGE_STREAMSOURCE = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE";
 
     static final String DATA_MIMEMESSAGE_OUTPUTSTREAM = "org.apache.james.core.DataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM";
 
-    private final static String SOFTWARE_TYPE = "JAMES SMTP Server "
-                                                 + Constants.SOFTWARE_VERSION;
-
-    /**
-     * Static RFC822DateFormat used to generate date headers
-     */
-    private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
-
-    // Keys used to store/lookup data in the internal state hash map
-
-    private LineHandler lineHandler;
-
     private MailServer mailServer;
     
     /**
@@ -114,24 +60,7 @@
     public final void setMailServer(MailServer mailServer) {
         this.mailServer = mailServer;
     }
-    
-    /**
-     * process DATA command
-     *
-     * @see org.apache.james.smtpserver.protocol.CommandHandler#onCommand(SMTPSession)
-     */
-    public SMTPResponse onCommand(SMTPSession session, SMTPRequest request) {
-        String parameters = request.getArgument();
-        SMTPResponse response = doDATAFilter(session,parameters);
-        
-        if (response == null) {
-            return doDATA(session, parameters);
-        } else {
-            return response;
-        }
-    }
-
-
+ 
     /**
      * Handler method called upon receipt of a DATA command.
      * Reads in message data, creates header, and delivers to
@@ -140,29 +69,18 @@
      * @param session SMTP session object
      * @param argument the argument passed in with the command by the SMTP client
      */
-    @SuppressWarnings("unchecked")
-    private SMTPResponse doDATA(SMTPSession session, String argument) {
-//        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());
-//            }
-//        }
-
+    protected SMTPResponse doDATA(SMTPSession session, String argument) {
         try {
             MimeMessageInputStreamSource mmiss = new MimeMessageInputStreamSource(mailServer.getId());
             OutputStream out = mmiss.getWritableOutputStream();
-
+            /*
             // Prepend output headers with out Received
             MailHeaders mh = createNewReceivedMailHeaders(session);
             for (Enumeration en = mh.getAllHeaderLines(); en.hasMoreElements(); ) {
                 out.write(en.nextElement().toString().getBytes());
                 out.write("\r\n".getBytes());
             }
-            
+            */
             session.getState().put(DATA_MIMEMESSAGE_STREAMSOURCE, mmiss);
             session.getState().put(DATA_MIMEMESSAGE_OUTPUTSTREAM, out);
 
@@ -175,52 +93,18 @@
         }
         
         // out = new PipedOutputStream(messageIn);
-        session.pushLineHandler(lineHandler);
+        session.pushLineHandler(getLineHandler());
         
         return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>");
     }
     
-
-
-
-    /**
-     * TODO: the "createNewReceivedMailHeaders" part has been already ported.
-     * The part that add a Date or a From if there is no From but a Sender has not been 
-     * backported.
-     */
-    private MailHeaders processMailHeaders(SMTPSession session, MailHeaders headers)
-        throws MessagingException {
-        // If headers do not contains minimum REQUIRED headers fields,
-        // add them
-        if (!headers.isSet(RFC2822Headers.DATE)) {
-            headers.setHeader(RFC2822Headers.DATE, rfc822DateFormat.format(new Date()));
-        }
-        if (!headers.isSet(RFC2822Headers.FROM) && session.getState().get(SMTPSession.SENDER) != null) {
-            headers.setHeader(RFC2822Headers.FROM, session.getState().get(SMTPSession.SENDER).toString());
-        }
-        // RFC 2821 says that we cannot examine the message to see if
-        // Return-Path headers are present.  If there is one, our
-        // Received: header may precede it, but the Return-Path header
-        // should be removed when making final delivery.
-     // headers.removeHeader(RFC2822Headers.RETURN_PATH);
-        // We will rebuild the header object to put our Received header at the top
-        Enumeration headerLines = headers.getAllHeaderLines();
-        MailHeaders newHeaders = createNewReceivedMailHeaders(session);
-
-        // Add all the original message headers back in next
-        while (headerLines.hasMoreElements()) {
-            newHeaders.addHeaderLine((String) headerLines.nextElement());
-        }
-        return newHeaders;
-    }
-
-
     /**
      * @param session
      * @param headerLineBuffer
      * @return
      * @throws MessagingException
      */
+    /*
     private MailHeaders createNewReceivedMailHeaders(SMTPSession session) throws MessagingException {
         StringBuilder headerLineBuffer = new StringBuilder(512);
         MailHeaders newHeaders = new MailHeaders();
@@ -293,51 +177,5 @@
         newHeaders.addHeaderLine("          " + rfc822DateFormat.format(new Date()));
         return newHeaders;
     }
-
-    /**
-     * @see org.apache.james.smtpserver.protocol.CommandHandler#getImplCommands()
-     */
-    public Collection<String> getImplCommands() {
-        Collection<String> implCommands = new ArrayList<String>();
-        implCommands.add("DATA");
-        
-        return implCommands;
-    }
-
-
-    /**
-     * @see org.apache.james.api.protocol.ExtensibleHandler#getMarkerInterfaces()
-     */
-    public List getMarkerInterfaces() {
-        List classes = new LinkedList();
-        classes.add(DataLineFilter.class);
-        return classes;
-    }
-
-
-    /**
-     * @see org.apache.james.api.protocol.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
-     */
-    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
-        if (DataLineFilter.class.equals(interfaceName)) {
-            LineHandler lineHandler = new DataConsumerLineHandler();
-            for (int i = extension.size() - 1; i >= 0; i--) {
-                lineHandler = new DataLineFilterWrapper((DataLineFilter) extension.get(i), lineHandler);
-            }
-            this.lineHandler = lineHandler;
-        }
-    }
-
-    private SMTPResponse doDATAFilter(SMTPSession session, String argument) {
-        if ((argument != null) && (argument.length() > 0)) {
-            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with DATA command");
-        }
-        if (!session.getState().containsKey(SMTPSession.SENDER)) {
-            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No sender specified");
-        } else if (!session.getState().containsKey(SMTPSession.RCPT_LIST)) {
-            return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No recipients specified");
-        }
-        return null;
-    }
-
+    */
 }



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