james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r905220 [1/4] - in /james/protocols/trunk: ./ smtp/ smtp/src/ smtp/src/main/ smtp/src/main/java/ smtp/src/main/java/org/ smtp/src/main/java/org/apache/ smtp/src/main/java/org/apache/james/ smtp/src/main/java/org/apache/james/dsn/ smtp/src/m...
Date Mon, 01 Feb 2010 09:29:58 GMT
Author: norman
Date: Mon Feb  1 09:29:55 2010
New Revision: 905220

URL: http://svn.apache.org/viewvc?rev=905220&view=rev
Log:
Copy over protocol specific stuff from server to own subproject

Added:
    james/protocols/trunk/pom.xml
    james/protocols/trunk/smtp/
    james/protocols/trunk/smtp/pom.xml
    james/protocols/trunk/smtp/src/
    james/protocols/trunk/smtp/src/main/
    james/protocols/trunk/smtp/src/main/java/
    james/protocols/trunk/smtp/src/main/java/org/
    james/protocols/trunk/smtp/src/main/java/org/apache/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/DSNStatus.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/DNSService.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPConfiguration.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPResponse.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRetCode.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPServerMBean.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPSession.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/TemporaryResolutionException.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractAuthRequiredToRelayRcptHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractHookableCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AcceptRecipientIfRelayingIsAllowed.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/ExpnCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/HeloCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/HelpCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/MailCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/NoopCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/PostmasterAbuseRcptHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/QuitCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/RcptCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/RsetCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/UnknownCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/VrfyCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/WelcomeMessageHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/EhloCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/EhloExtension.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/StartTlsCmdHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractGreylistHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/AbstractValidRcptHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/MaxRcptHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ResolvableEhloHeloHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ReverseEqualsEhloHeloHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SpamTrapHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/SupressDuplicateRcptHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/TarpitHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidSenderDomainHandler.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/AuthHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/HeloHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/HookResult.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/HookResultHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/HookReturnCode.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/MailHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/MailParametersHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/MessageHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/QuitHook.java
    james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/hook/RcptHook.java
    james/protocols/trunk/smtp/src/test/
    james/protocols/trunk/smtp/src/test/java/
    james/protocols/trunk/smtp/src/test/java/org/
    james/protocols/trunk/smtp/src/test/java/org/apache/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/BaseFakeDNSService.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/BaseFakeSMTPSession.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/DNSRBLHandlerTest.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/MaxRcptHandlerTest.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/MockLog.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/ResolvableEhloHeloHandlerTest.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/SpamTrapHandlerTest.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/TarpitHandlerTest.java
    james/protocols/trunk/smtp/src/test/java/org/apache/james/smtpserver/protocol/core/fastfail/ValidSenderDomainHandlerTest.java

Added: james/protocols/trunk/pom.xml
URL: http://svn.apache.org/viewvc/james/protocols/trunk/pom.xml?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/pom.xml (added)
+++ james/protocols/trunk/pom.xml Mon Feb  1 09:29:55 2010
@@ -0,0 +1,248 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+<!--
+  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.    
+-->
+<project>
+  <parent>
+    <artifactId>james-server-root</artifactId>
+    <groupId>org.apache.james</groupId>
+    <version>1.5</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.james</groupId>
+  <artifactId>james-protocols</artifactId>
+  <name>Apache JAMES Protocols</name>
+  <version>1.0-SNAPSHOT</version>
+  <description>JAMES Protocols</description>
+  <url>http://james.apache.org/protocols</url>
+  <inceptionYear>2010</inceptionYear>
+  <packaging>pom</packaging>
+  <modules>
+    <module>api</module>
+    <module>smtp</module>
+  </modules>
+  <ciManagement>
+    <system>hudson</system>
+    <url>http://hudson.zones.apache.org/hudson/view/James/job/james-protocols-trunk/</url>
+    <notifiers>
+      <notifier>
+        <type>mail</type>
+      </notifier>
+    </notifiers>
+  </ciManagement>
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/james/protocols/trunk</connection>
+    <developerConnection>scm:svn:https://${maven.username}@svn.apache.org/repos/asf/james/protocols/trunk</developerConnection>
+    <url>http://svn.apache.org/viewcvs.cgi/james/protocols/trunk?root=Apache-SVN</url>
+  </scm>
+  
+  <repositories>
+   
+    <!-- needed for javamail -->
+    <repository>
+      <id>maven2-repository.dev.java.net</id>
+      <name>Java.net Repository for Maven</name>
+      <url>http://download.java.net/maven/2/</url>
+      <layout>default</layout>
+    </repository>
+   
+
+  </repositories>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <optimize>true</optimize>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <configuration>
+          <archive>
+            <manifest>
+              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+            </manifest>
+          </archive>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+  <reporting>
+    <plugins>
+      <plugin>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          <aggregate>true</aggregate>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-jxr-plugin</artifactId>
+        <configuration>
+          <aggregate>true</aggregate>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-pmd-plugin</artifactId>
+        <configuration>
+          <aggregate>true</aggregate>
+          <targetjdk>1.5</targetjdk>
+          <rulesets>
+            <ruleset>/rulesets/basic.xml</ruleset>
+            <ruleset>/rulesets/controversial.xml</ruleset>
+          </rulesets>
+          <format>xml</format>
+          <linkXref>true</linkXref>
+          <sourceEncoding>utf-8</sourceEncoding>
+          <minimumTokens>100</minimumTokens>
+        </configuration>
+      </plugin>
+      <plugin>
+        <artifactId>maven-site-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <configuration>
+            <onlyCurrentVersion>true</onlyCurrentVersion>
+            <resolutionIds>Closed</resolutionIds>
+            <maxEntries>1000</maxEntries>
+        </configuration>
+        <reportSets>
+            <reportSet>
+                <reports>
+                    <report>jira-report</report>
+                </reports>
+            </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
+  <distributionManagement>
+    <site>
+      <id>server-trunk-website</id>
+      <url>scp://people.apache.org/www/james.apache.org/protocols/trunk/</url>
+    </site>
+  </distributionManagement>
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.james.protocols</groupId>
+        <artifactId>api</artifactId>
+        <version>1.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>commons-logging</groupId>
+        <artifactId>commons-logging</artifactId>
+        <version>1.1</version>
+        <exclusions>
+          <exclusion>
+            <artifactId>logkit</artifactId>
+            <groupId>logkit</groupId>
+          </exclusion>
+          <exclusion>
+            <artifactId>avalon-framework</artifactId>
+            <groupId>avalon-framework</groupId>
+          </exclusion>
+          <exclusion>
+            <artifactId>log4j</artifactId>
+            <groupId>log4j</groupId>
+          </exclusion>
+          <exclusion>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.james</groupId>
+        <artifactId>apache-mailet</artifactId>
+        <version>2.4</version>
+        <exclusions>
+          <exclusion>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.james</groupId>
+        <artifactId>apache-mailet-base</artifactId>
+        <version>1.0</version>
+        <exclusions>
+          <exclusion>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>javax.mail</groupId>
+        <artifactId>mail</artifactId>
+        <version>1.4.3</version>
+      </dependency>
+      <dependency>
+        <groupId>javax.activation</groupId>
+        <artifactId>activation</artifactId>
+        <version>1.1.1</version>
+      </dependency>
+      <dependency>
+        <groupId>commons-codec</groupId>
+        <artifactId>commons-codec</artifactId>
+        <version>1.4</version>
+      </dependency>
+      <dependency>
+        <groupId>commons-configuration</groupId>
+        <artifactId>commons-configuration</artifactId>
+        <version>1.5</version>
+        <exclusions>
+          <exclusion>
+            <artifactId>commons-digester</artifactId>
+            <groupId>commons-digester</groupId>
+          </exclusion>
+          <exclusion>
+            <artifactId>commons-beanutils-core</artifactId>
+            <groupId>commons-beanutils</groupId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>3.8.1</version>
+        <scope>test</scope>
+      </dependency>
+    </dependencies>  
+  </dependencyManagement>
+</project>

Added: james/protocols/trunk/smtp/pom.xml
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/pom.xml?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/pom.xml (added)
+++ james/protocols/trunk/smtp/pom.xml Mon Feb  1 09:29:55 2010
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+<!--
+  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.    
+-->
+<project>
+  <parent>
+    <artifactId>james-protocols</artifactId>
+    <groupId>org.apache.james</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.james.protocols</groupId>
+  <artifactId>smtp</artifactId>
+  <name>Apache JAMES SMTP Protocol</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.james.protocols</groupId>
+      <artifactId>api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mailet-base</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mailet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/DSNStatus.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/DSNStatus.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/DSNStatus.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/dsn/DSNStatus.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,349 @@
+/****************************************************************
+ * 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.dsn;
+
+
+/**
+ * Constants and getters for RFC 3463 Enhanced Mail System Status Codes
+ *
+ */
+public class DSNStatus {
+    // status code classes
+    /**
+     * Success
+     */
+    public static final int SUCCESS = 2;
+
+    /**
+     * Persistent Transient Failure
+     */
+    public static final int TRANSIENT = 4;
+
+    /**
+     * Permanent Failure
+     */
+    public static final int PERMANENT = 5;
+
+    // subjects and details
+
+    /**
+     * Other or Undefined Status
+     */
+    public static final int UNDEFINED = 0;
+
+    /**
+     * Other undefined status
+     */
+    public static final String UNDEFINED_STATUS = "0.0";
+
+    /**
+     * Addressing Status
+     */
+    public static final int ADDRESS = 1;
+
+    /**
+     * Other address status
+     */
+    public static final String ADDRESS_OTHER = "1.0";
+
+    /**
+     * Bad destination mailbox address
+     */
+    public static final String ADDRESS_MAILBOX = "1.1";
+
+    /**
+     * Bad destination system address
+     */
+    public static final String ADDRESS_SYSTEM = "1.2";
+
+    /**
+     * Bad destination mailbox address syntax
+     */
+    public static final String ADDRESS_SYNTAX = "1.3";
+
+    /**
+     * Destination mailbox address ambiguous
+     */
+    public static final String ADDRESS_AMBIGUOUS = "1.4";
+
+    /**
+     * Destination Address valid
+     */
+    public static final String ADDRESS_VALID = "1.5";
+
+    /**
+     * Destimation mailbox has moved, no forwarding address
+     */
+    public static final String ADDRESS_MOVED = "1.6";
+
+    /**
+     * Bad sender's mailbox address syntax
+     */
+    public static final String ADDRESS_SYNTAX_SENDER = "1.7";
+
+    /**
+     * Bad sender's system address
+     */
+    public static final String ADDRESS_SYSTEM_SENDER = "1.8";
+
+
+    /**
+     * Mailbox Status
+     */
+    public static final int MAILBOX = 2;
+
+    /**
+     * Other or Undefined Mailbox Status
+     */
+    public static final String MAILBOX_OTHER = "2.0";
+
+    /**
+     * Mailbox disabled, not accepting messages
+     */
+    public static final String MAILBOX_DISABLED = "2.1";
+
+    /**
+     * Mailbox full
+     */
+    public static final String MAILBOX_FULL = "2.2";
+
+    /**
+     * Message length exceeds administrative limit
+     */
+    public static final String MAILBOX_MSG_TOO_BIG = "2.3";
+
+    /**
+     * Mailing list expansion problem
+     */
+    public static final String MAILBOX_LIST_EXPANSION = "2.4";
+
+
+    /**
+     * Mail System Status
+     */
+    public static final int SYSTEM = 3;
+
+    /**
+     * Other or undefined mail system status
+     */
+    public static final String SYSTEM_OTHER = "3.0";
+
+    /**
+     * Mail system full
+     */
+    public static final String SYSTEM_FULL = "3.1";
+
+    /**
+     * System not accepting messages
+     */
+    public static final String SYSTEM_NOT_ACCEPTING = "3.2";
+
+    /**
+     * System not capable of selected features
+     */
+    public static final String SYSTEM_NOT_CAPABLE = "3.3";
+
+    /**
+     * Message too big for system
+     */
+    public static final String SYSTEM_MSG_TOO_BIG = "3.4";
+
+    /**
+     * System incorrectly configured
+     */
+    public static final String SYSTEM_CFG_ERROR = "3.5";
+
+
+    /**
+     * Network and Routing Status
+     */
+    public static final int NETWORK = 4;
+
+    /**
+     * Other or undefined network or routing status
+     */
+    public static final String NETWORK_OTHER = "4.0";
+
+    /**
+     * No answer form host
+     */
+    public static final String NETWORK_NO_ANSWER = "4.1";
+
+    /**
+     * Bad Connection
+     */
+    public static final String NETWORK_CONNECTION = "4.2";
+
+    /**
+     * Directory server failure
+     */
+    public static final String NETWORK_DIR_SERVER = "4.3";
+
+    /**
+     * Unable to route
+     */
+    public static final String NETWORK_ROUTE = "4.4";
+
+    /**
+     * Mail system congestion
+     */
+    public static final String NETWORK_CONGESTION = "4.5";
+
+    /**
+     * Routing loop detected
+     */
+    public static final String NETWORK_LOOP = "4.6";
+
+    /**
+     * Delivery time expired
+     */
+    public static final String NETWORK_EXPIRED = "4.7";
+
+
+    /**
+     * Mail Delivery Protocol Status
+     */
+    public static final int DELIVERY = 5;
+
+    /**
+     * Other or undefined (SMTP) protocol status
+     */
+    public static final String DELIVERY_OTHER = "5.0";
+
+    /**
+     * Invalid command
+     */
+    public static final String DELIVERY_INVALID_CMD = "5.1";
+
+    /**
+     * Syntax error
+     */
+    public static final String DELIVERY_SYNTAX = "5.2";
+
+    /**
+     * Too many recipients
+     */
+    public static final String DELIVERY_TOO_MANY_REC = "5.3";
+
+    /**
+     * Invalid command arguments
+     */
+    public static final String DELIVERY_INVALID_ARG = "5.4";
+
+    /**
+     * Wrong protocol version
+     */
+    public static final String DELIVERY_VERSION = "5.5";
+
+
+    /**
+     * Message Content or Media Status
+     */
+    public static final int CONTENT = 6;
+
+    /**
+     * Other or undefined media error
+     */
+    public static final String CONTENT_OTHER = "6.0";
+
+    /**
+     * Media not supported
+     */
+    public static final String CONTENT_UNSUPPORTED = "6.1";
+
+    /**
+     * Conversion required and prohibited
+     */
+    public static final String CONTENT_CONVERSION_NOT_ALLOWED = "6.2";
+
+    /**
+     * Conversion required, but not supported
+     */
+    public static final String CONTENT_CONVERSION_NOT_SUPPORTED = "6.3";
+
+    /**
+     * Conversion with loss performed
+     */
+    public static final String CONTENT_CONVERSION_LOSS = "6.4";
+
+    /**
+     * Conversion failed
+     */
+    public static final String CONTENT_CONVERSION_FAILED = "6.5";
+
+
+    /**
+     * Security or Policy Status
+     */
+    public static final int SECURITY = 7;
+
+    /**
+     * Other or undefined security status
+     */
+    public static final String SECURITY_OTHER = "7.0";
+
+    /**
+     * Delivery not authorized, message refused
+     */
+    public static final String SECURITY_AUTH = "7.1";
+
+    /**
+     * Mailing list expansion prohibited
+     */
+    public static final String SECURITY_LIST_EXP = "7.2";
+
+    /**
+     * Security conversion required, but not possible
+     */
+    public static final String SECURITY_CONVERSION = "7.3";
+
+    /**
+     * Security features not supported
+     */
+    public static final String SECURITY_UNSUPPORTED = "7.4";
+
+    /**
+     * Cryptographic failure
+     */
+    public static final String SECURITY_CRYPT_FAIL = "7.5";
+
+    /**
+     * Cryptographic algorithm not supported
+     */
+    public static final String SECURITY_CRYPT_ALGO = "7.6";
+
+    /**
+     * Message integrity failure
+     */
+    public static final String SECURITY_INTEGRITY = "7.7";
+
+
+    // get methods
+
+    public static String getStatus(int type, String detail) {
+        return type + "." + detail;
+    }
+
+    public static String getStatus(int type, int subject, int detail) {
+        return type + "." + subject + "." + detail;
+    }
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/DNSService.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/DNSService.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/DNSService.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/DNSService.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,107 @@
+/****************************************************************
+ * 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.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.mailet.HostAddress;
+
+
+/**
+ * Provides abstraction for DNS resolutions. The interface is Mail specific.
+ * It may be a good idea to make the interface more generic or expose 
+ * commonly needed DNS methods.
+ *
+ */
+public interface DNSService {
+
+    /**
+     * The component role used by components implementing this service
+     */
+     String ROLE = "org.apache.james.smtpserver.protocol.DNSService";
+
+    /**
+     * <p>Return a prioritized unmodifiable list of host handling mail
+     * for the domain.</p>
+     * 
+     * <p>First lookup MX hosts, then MX hosts of the CNAME adress, and
+     * if no server is found return the IP of the hostname</p>
+     *
+     * @param hostname domain name to look up
+     *
+     * @return a unmodifiable list of handling servers corresponding to
+     *         this mail domain name
+     * @throws TemporaryResolutionException get thrown on temporary problems 
+     */
+    Collection<String> findMXRecords(String hostname) throws TemporaryResolutionException;
+
+    /**
+     * Get a collection of DNS TXT Records
+     * 
+     * @param hostname The hostname to check
+     * @return collection of strings representing TXT record values
+     */
+    Collection<String> findTXTRecords(String hostname);
+
+
+    /**
+     * Returns an Iterator over org.apache.mailet.HostAddress, a
+     * specialized subclass of javax.mail.URLName, which provides
+     * location information for servers that are specified as mail
+     * handlers for the given hostname.  This is done using MX records,
+     * and the HostAddress instances are returned sorted by MX priority.
+     * If no host is found for domainName, the Iterator returned will be
+     * empty and the first call to hasNext() will return false.  The
+     * Iterator is a nested iterator: the outer iteration is over the
+     * results of the MX record lookup, and the inner iteration is over
+     * potentially multiple A records for each MX record.  DNS lookups
+     * are deferred until actually needed.
+     *
+     * @since v2.2.0a16-unstable
+     * @param domainName - the domain for which to find mail servers
+     * @return an Iterator over HostAddress instances, sorted by priority
+     * @throws TemporaryResolutionException get thrown on temporary problems
+     */
+    Iterator<HostAddress> getSMTPHostAddresses(String domainName) throws TemporaryResolutionException;
+    
+    /**
+     * @see java.net.InetAddress#getAllByName(String)
+     */
+    public InetAddress[] getAllByName(String host) throws UnknownHostException;
+ 
+    /**
+     * @see java.net.InetAddress#getByName(String)
+     */
+    public InetAddress getByName(String host) throws UnknownHostException;
+
+    /**
+     * @see org.xbill.DNS.Address#getHostName(InetAddress)
+     */
+    public String getHostName(InetAddress addr);
+    
+    /**
+     */
+    public InetAddress getLocalHost() throws UnknownHostException;
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelope.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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;
+
+/**
+ * The MailEnvelope of a SMTP-Transaction
+ * 
+ *
+ */
+public interface MailEnvelope {
+
+    /**
+     * Return the size of the message. If the message is "empty" it will return -1
+     * 
+     * @return size
+     */
+	public int getSize();
+
+	/**
+	 * Return the recipients which where supplied in the RCPT TO: command
+	 * 
+	 * @return recipients
+	 */
+	public List<MailAddress> getRecipients();
+
+	/**
+	 * Return the sender of the mail which was supplied int the MAIL FROM: command. If its a "null" sender,
+	 * null will get returned
+	 * 
+	 * @return sender
+	 */
+	public MailAddress getSender();
+
+
+	/**
+	 * Return the OutputStream of the message
+	 * 
+	 * @return out
+	 * @throws Exception
+	 */
+	public OutputStream getMessageOutputStream() throws Exception;
+
+	/**
+	 * Return the InputStream of the message
+	 * 
+	 * @return in
+	 * @throws Exception
+	 */
+	public InputStream getMessageInputStream() throws Exception;
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/MailEnvelopeImpl.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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;
+
+/**
+ * MailEnvelope implementation which stores everything in memory
+ * 
+ *
+ */
+public class MailEnvelopeImpl implements MailEnvelope{
+
+    private List<MailAddress> recipients;
+
+    private MailAddress sender;
+
+    private ByteArrayOutputStream outputStream;
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.MailEnvelope#getSize()
+     */
+    public int getSize() {
+        if (outputStream == null)
+            return -1;
+        return outputStream.size();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.MailEnvelope#getRecipients()
+     */
+    public List<MailAddress> getRecipients() {
+        return recipients;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.MailEnvelope#getSender()
+     */
+    public MailAddress getSender() {
+        return sender;
+    }
+
+    /**
+     * Set the recipients of the mail
+     * 
+     * @param recipientCollection
+     */
+    public void setRecipients(List<MailAddress> recipientCollection) {
+        this.recipients = recipientCollection;
+    }
+
+    /**
+     * Set the sender of the mail
+     * 
+     * @param sender
+     */
+    public void setSender(MailAddress sender) {
+        this.sender = sender;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.MailEnvelope#getMessageOutputStream()
+     */
+    public OutputStream getMessageOutputStream() {
+        this.outputStream = new ByteArrayOutputStream(100000);
+        return outputStream;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.MailEnvelope#getMessageInputStream()
+     */
+    public InputStream getMessageInputStream() {
+        return new ByteArrayInputStream(outputStream.toByteArray());
+    }
+}
+
+

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPConfiguration.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPConfiguration.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPConfiguration.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPConfiguration.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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;
+
+
+/**
+ * Provides a number of server-wide constant values to the
+ * SMTPHandlers
+ *
+ */
+public interface SMTPConfiguration {
+
+    /**
+     * Returns the service wide hello name
+     *
+     * @return the hello name
+     */
+    String getHelloName();
+
+    /**
+     * Returns the service wide reset length in bytes.
+     *
+     * @return the reset length
+     */
+    int getResetLength();
+
+    /**
+     * Returns the service wide maximum message size in bytes.
+     *
+     * @return the maximum message size
+     */
+    long getMaxMessageSize();
+
+    /**
+     * Returns whether relaying is allowed for the IP address passed.
+     *
+     * @param remoteIP the remote IP address in String form
+     * @return whether relaying is allowed
+     */
+    boolean isRelayingAllowed(String remoteIP);
+
+    /**
+     * Returns whether SMTP AUTH is active for this server, and
+     * necessary for the IP address passed.
+     *
+     * @param remoteIP the remote IP address in String form
+     * @return whether SMTP authentication is on
+     */
+    boolean isAuthRequired(String remoteIP);
+    
+    /**
+     * Returns whether the remote server needs to send a HELO/EHLO
+     * of its senders.
+     *
+     * @return whether SMTP authentication is on
+     */
+    boolean useHeloEhloEnforcement();
+    
+    
+    /**
+     * Return the SMTPGreeting which should used.
+     * 
+     * @return the SMTPGreeting
+     */
+    String getSMTPGreeting();
+    
+    /**
+     * Return wheter the mailserver will accept addresses without brackets enclosed.
+     * 
+     * @return true or false
+     */
+    boolean useAddressBracketsEnforcement();
+    
+    /**
+     * 
+     */
+    boolean isStartTLSSupported();
+
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRequest.java Mon Feb  1 09:29:55 2010
@@ -0,0 +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;
+
+import org.apache.james.protocols.api.BaseRequest;
+
+/**
+ * SMTPRequest which contains a command and an optional argument
+ * 
+ *
+ */
+public final class SMTPRequest extends BaseRequest {
+
+    public SMTPRequest(final String command, final String argument) {
+        super(command, argument);
+    }
+
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPResponse.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPResponse.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPResponse.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPResponse.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,142 @@
+/****************************************************************
+ * 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.util.LinkedList;
+import java.util.List;
+
+import org.apache.james.protocols.api.RetCodeResponse;
+
+/**
+ * Contains an SMTP result
+ */
+public final class SMTPResponse implements RetCodeResponse {
+
+    private String retCode = null;
+    private List<CharSequence> lines = null;
+    private String rawLine = null;
+    private boolean endSession = false;
+    
+    /**
+     * Construct a new SMTPResponse. The given code and description can not be null, if null an IllegalArgumentException
+     * get thrown
+     * 
+     * @param code the returnCode
+     * @param description the description 
+     */
+    public SMTPResponse(String code, CharSequence description) {
+        if (code == null) throw new IllegalArgumentException("SMTPResponse code can not be null");
+        if (description == null) new IllegalArgumentException("SMTPResponse description can not be null");
+    
+        this.setRetCode(code);
+        this.appendLine(description);
+        this.rawLine = code + " " + description;
+    }
+    
+    /**
+     * Construct a new SMTPResponse. The given rawLine need to be in format [SMTPResponseReturnCode SMTResponseDescription].
+     * If this is not the case an IllegalArgumentException get thrown.
+     * 
+     * @param rawLine the raw SMTPResponse
+     */
+    public SMTPResponse(String rawLine) {
+        String args[] = rawLine.split(" ");
+        if (args != null && args.length > 1) {
+            this.setRetCode(args[0]);
+            this.appendLine(new StringBuilder(rawLine.substring(args[0].length()+1)));
+        } else {
+            throw new IllegalArgumentException("Invalid SMTPResponse format. Format should be [SMTPCode SMTPReply]");
+        }
+        this.rawLine = rawLine;
+    }
+    
+    /**
+     * Append the responseLine to the SMTPResponse
+     * 
+     * @param line the responseLine to append
+     */
+    public void appendLine(CharSequence line) {
+        if (lines == null) {
+            lines = new LinkedList<CharSequence>();
+        }
+        lines.add(line);
+    }
+    
+    /**
+     * Return the SMTPCode 
+     * 
+     * @return the SMTPCode
+     */
+    public String getRetCode() {
+        return retCode;
+    }
+
+    /**
+     * Set the SMTPCode
+     *  
+     * @param retCode the SMTPCode
+     */
+    public void setRetCode(String retCode) {
+        this.retCode = retCode;
+    }
+
+    /**
+     * Return a List of all responseLines stored in this SMTPResponse
+     * 
+     * @return all responseLines
+     */
+    public List<CharSequence> getLines() {
+        return lines;
+    }
+
+    /**
+     * Return the raw representation of the Stored SMTPResponse
+     * 
+     * @return rawLine the raw SMTPResponse
+     */
+    public String getRawLine() {
+        return rawLine;
+    }
+
+    /**
+     * Return true if the session is ended
+     * 
+     * @return true if session is ended
+     */
+    public boolean isEndSession() {
+        return endSession;
+    }
+
+    /**
+     * Set to true to end the session
+     * 
+     * @param endSession
+     */
+    public void setEndSession(boolean endSession) {
+        this.endSession = endSession;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return getRetCode() + " " + getLines();
+    }
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRetCode.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRetCode.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRetCode.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPRetCode.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,178 @@
+/****************************************************************
+ * 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;
+
+/**
+ * Result code defined in RFC 2821
+ */
+public class SMTPRetCode {
+    /** System status, or system help reply */
+    public static final String SYSTEM_STATUS = "211";
+
+    /**
+     * Help message (Information on how to use the receiver or the meaning of a
+     * particular non-standard command; this reply is useful only to the human
+     * user)
+     */
+    public static final String HELP_MESSAGE = "214";
+
+    /** <domain> Service ready */
+    public static final String SERVICE_READY = "220";
+
+    /** <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";
+
+    /**
+     * 251 User not local; will forward to <forward-path> (See section 3.4)
+     */
+    public static final String MAIL_FORWARDING = "251";
+
+    /**
+     * Cannot VRFY user, but will accept message and attempt delivery (See
+     * section 3.5.3)
+     */
+    public static final String MAIL_UNDEFINDED = "252";
+
+    public static final String AUTH_READY = "334";
+
+    /** Start mail input; end with <CRLF>.<CRLF> */
+    public static final String DATA_READY = "354";
+
+    /**
+     * <domain> Service not available, closing transmission channel (This may be
+     * a reply to any command if the service knows it must shut down)
+     */
+    public static final String SERVICE_NOT_AVAILABLE = "421";
+
+    /**
+     * This response to the AUTH command indicates that the user needs to
+     * transition to the selected authentication mechanism. This typically done
+     * by authenticating once using the PLAIN authentication mechanism.
+     */
+    public static final String AUTH_PASSWORD_TRANSITION_ERROR = "432";
+
+    /**
+     * Requested mail action not taken: mailbox unavailable (e.g., mailbox busy)
+     */
+    public static final String MAILBOX_TEMP_UNAVAILABLE = "450";
+
+    /**
+     * Requested action aborted: local error in processing
+     */
+    public static final String LOCAL_ERROR = "451";
+
+    /**
+     * Requested action not taken: insufficient system storage
+     */
+    public static final String SYSTEM_STORAGE_ERROR = "452";
+
+    /**
+     * This response to the AUTH command indicates that the authentication
+     * failed due to a temporary server failure.
+     */
+    public static final String AUTH_TEMPORARY_ERROR = "454";
+
+    /**
+     * Syntax error, command unrecognized (This may include errors such as
+     * command line too long)
+     */
+    public static final String SYNTAX_ERROR_COMMAND_UNRECOGNIZED = "500";
+
+    /**
+     * Syntax error in parameters or arguments
+     */
+    public static final String SYNTAX_ERROR_ARGUMENTS = "501";
+
+    /**
+     * Command not implemented (see section 4.2.4)
+     */
+    public static final String UNIMPLEMENTED_COMMAND = "502";
+
+    /**
+     * Bad sequence of commands
+     */
+    public static final String BAD_SEQUENCE = "503";
+
+    /**
+     * Command parameter not implemented
+     */
+    public static final String PARAMETER_NOT_IMPLEMENTED = "504";
+
+    /**
+     * This response may be returned by any command other than AUTH, EHLO, HELO,
+     * NOOP, RSET, or QUIT. It indicates that server policy requires
+     * authentication in order to perform the requested action.
+     */
+    public static final String AUTH_REQUIRED = "530";
+
+    /**
+     * Auth failed
+     */
+    public static final String AUTH_FAILED = "535";
+
+    /**
+     * This response to the AUTH command indicates that the selected
+     * authentication mechanism is weaker than server policy permits for that
+     * user.
+     */
+    public static final String AUTH_MECHANISM_WEAK = "534";
+
+    /**
+     * This response to the AUTH command indicates that the selected
+     * authentication mechanism may only be used when the underlying SMTP
+     * connection is encrypted.
+     */
+    public static final String AUTH_ENCRYPTION_REQUIRED = "538";
+
+    /**
+     * Requested action not taken: mailbox unavailable (e.g., mailbox not found,
+     * no access, or command rejected for policy reasons)
+     */
+    public static final String MAILBOX_PERM_UNAVAILABLE = "550";
+
+    /**
+     * User not local; please try <forward-path> (See section 3.4)
+     */
+    public static final String USER_NOT_LOCAL = "551";
+
+    /**
+     * Requested mail action aborted: exceeded storage allocation
+     */
+    public static final String QUOTA_EXCEEDED = "552";
+
+    /**
+     * Requested action not taken: mailbox name not allowed (e.g., mailbox
+     * syntax incorrect)
+     */
+    public static final String SYNTAX_ERROR_MAILBOX = "553";
+
+    /**
+     * Transaction failed (Or, in the case of a connection-opening response,
+     * "No SMTP service here")
+     */
+    public static final String TRANSACTION_FAILED = "554";
+
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPServerMBean.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPServerMBean.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPServerMBean.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPServerMBean.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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;
+
+/**
+ * An interface to expose James management functionality through JMX.
+ * 
+ * @phoenix:mx-topic name="SMTPServer"
+ */
+public interface SMTPServerMBean {
+    /**
+    * @phoenix:mx-attribute
+    * @phoenix:mx-description Returns flag indicating it this service is enabled 
+    * @phoenix:mx-isWriteable no
+    * 
+    * @return boolean The enabled flag     
+    */  
+    public boolean isEnabled();
+
+    /**
+    * @phoenix:mx-attribute
+    * @phoenix:mx-description Returns the port that the service is bound to 
+    * @phoenix:mx-isWriteable no
+    * 
+    * @return int The port number     
+    */  
+    public int  getPort();
+    
+    /**
+    * @phoenix:mx-attribute
+    * @phoenix:mx-description Returns the address if the network interface the socket is bound to 
+    * @phoenix:mx-isWriteable no
+    * 
+    * @return String The network interface name     
+    */  
+    public String  getNetworkInterface();
+    
+    /**
+    * @phoenix:mx-attribute
+    * @phoenix:mx-description Returns the server socket type, plain or SSL 
+    * @phoenix:mx-isWriteable no
+    * 
+    * @return String The scoekt type, plain or SSL     
+    */  
+    public String  getSocketType();
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPSession.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPSession.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPSession.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/SMTPSession.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,144 @@
+/****************************************************************
+ * 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.util.Map;
+
+import org.apache.james.protocols.api.LineHandler;
+import org.apache.james.protocols.api.TLSSupportedSession;
+
+
+/**
+ * All the handlers access this interface to communicate with
+ * SMTPHandler object
+ */
+
+public interface SMTPSession extends TLSSupportedSession{
+
+    // Keys used to store/lookup data in the internal state hash map
+    /** Sender's email address */
+    public final static String SENDER = "SENDER_ADDRESS";
+    /** The message recipients */
+    public final static String RCPT_LIST = "RCPT_LIST";  
+    /** HELO or EHLO */
+    public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE";
+    public final static String CURRENT_HELO_NAME = "CURRENT_HELO_NAME";
+    /** the Session state */
+    public final static String SESSION_STATE_MAP = "SESSION_STATE_MAP";
+
+    /**
+     * Returns the service wide hello name
+     *
+     * @return the hello name
+     */
+    String getHelloName();
+    
+    /**
+     * Returns whether the remote server needs to send a HELO/EHLO
+     * of its senders.
+     *
+     * @return whether SMTP authentication is on
+     */
+    boolean useHeloEhloEnforcement();
+    
+    /**
+     * Return the SMTPGreeting which should used.
+     * 
+     * @return the SMTPGreeting
+     */
+    String getSMTPGreeting();
+    
+    /**
+     * Returns the service wide maximum message size in bytes.
+     *
+     * @return the maximum message size
+     */
+    long getMaxMessageSize();
+    
+    /**
+     * Return wheter the mailserver will accept addresses without brackets enclosed.
+     * 
+     * @return true or false
+     */
+    boolean useAddressBracketsEnforcement();
+    
+    /**
+     * Returns whether Relaying is allowed or not
+     *
+     * @return the relaying status
+     */
+    boolean isRelayingAllowed();
+    
+    /**
+     * Set if reallying is allowed
+     * 
+     * @param relayingAllowed
+     */
+    void setRelayingAllowed(boolean relayingAllowed);
+
+    /**
+     * Returns whether Authentication is required or not
+     *
+     * @return authentication required or not
+     */
+    boolean isAuthSupported();
+
+
+    /**
+     * Returns the SMTP session id
+     *
+     * @return SMTP session id
+     */
+    String getSessionID();
+    
+    /**
+     * Returns the recipient count
+     * 
+     * @return recipient count
+     */
+    int getRcptCount();
+    
+    /**
+     * Returns Map that consists of the state of the SMTPSession per connection
+     *
+     * @return map of the current SMTPSession state per connection
+     */
+    Map<String,Object> getConnectionState();
+
+    /**
+     * Put a new line handler in the chain
+     * @param overrideCommandHandler
+     */
+    void pushLineHandler(LineHandler<SMTPSession> overrideCommandHandler);
+    
+    /**
+     * Pop the last command handler 
+     */
+    void popLineHandler();
+    
+    /**
+     * Sleep for the given ms 
+     * 
+     * @param ms the time to sleep in milliseconds
+     */
+    void sleep(long ms);
+    
+}
+

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/TemporaryResolutionException.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/TemporaryResolutionException.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/TemporaryResolutionException.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/TemporaryResolutionException.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.IOException;
+
+@SuppressWarnings("serial")
+public class TemporaryResolutionException extends IOException {
+
+    public TemporaryResolutionException() {
+        super();
+    }
+
+    public TemporaryResolutionException(String message) {
+        super(message);
+    }
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractAuthRequiredToRelayRcptHook.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractAuthRequiredToRelayRcptHook.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractAuthRequiredToRelayRcptHook.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractAuthRequiredToRelayRcptHook.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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 org.apache.james.dsn.DSNStatus;
+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;
+
+/**
+ * Handler which check for authenticated users
+ */
+public abstract class AbstractAuthRequiredToRelayRcptHook implements RcptHook {
+
+    
+    /**
+     * @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) {
+        if (!session.isRelayingAllowed()) {
+            String toDomain = rcpt.getDomain();
+            if (isLocalDomain(toDomain) == false) {
+                if (session.isAuthSupported()) {
+                    return new HookResult(HookReturnCode.DENY,
+                            SMTPRetCode.AUTH_REQUIRED, DSNStatus.getStatus(
+                                    DSNStatus.PERMANENT,
+                                    DSNStatus.SECURITY_AUTH)
+                                    + " Authentication Required");
+                } else {
+                    return new HookResult(
+                            HookReturnCode.DENY,
+                            // sendmail returns 554 (SMTPRetCode.TRANSACTION_FAILED).
+                            // it is not clear in RFC wether it is better to use 550 or 554.
+                            SMTPRetCode.MAILBOX_PERM_UNAVAILABLE,
+                            DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                    DSNStatus.SECURITY_AUTH)
+                                    + " Requested action not taken: relaying denied");
+                }
+            }
+
+        }
+        return new HookResult(HookReturnCode.DECLINED);
+    }
+
+    
+    /**
+     * Return true if the given domain is a local domain for this server
+     * 
+     * @param domain
+     * @return isLocal
+     */
+    protected abstract boolean isLocalDomain(String domain);
+    
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractHookableCmdHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractHookableCmdHandler.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractHookableCmdHandler.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractHookableCmdHandler.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,223 @@
+/****************************************************************
+ * 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.List;
+
+import org.apache.james.protocols.api.CommandHandler;
+import org.apache.james.protocols.api.ExtensibleHandler;
+import org.apache.james.protocols.api.Request;
+import org.apache.james.protocols.api.Response;
+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.HookReturnCode;
+
+/**
+ * Abstract class which Handle hook-aware CommanHandler.
+ * 
+ */
+public abstract class AbstractHookableCmdHandler<Hook> implements CommandHandler<SMTPSession>, ExtensibleHandler {
+
+
+    private List<Hook> hooks;
+    private List<HookResultHook> rHooks;
+
+    /**
+     * Handle command processing
+     * 
+     * @see org.apache.james.smtpserver.protocol.CommandHandler#onCommand(org.apache.james.smtpserver.protocol.SMTPSession,
+     *      java.lang.String, java.lang.String)
+     */
+    public Response onCommand(SMTPSession session, Request request) {
+        String command = request.getCommand();
+        String parameters = request.getArgument();
+        SMTPResponse response = doFilterChecks(session, command, parameters);
+
+        if (response == null) {
+
+            response = processHooks(session, command, parameters);
+            if (response == null) {
+                return doCoreCmd(session, command, parameters);
+            } else {
+                return response;
+            }
+        } else {
+            return response;
+        }
+
+    }
+
+    /**
+     * Process all hooks for the given command
+     * 
+     * @param session
+     *            the SMTPSession object
+     * @param command
+     *            the command
+     * @param parameters
+     *            the paramaters
+     * @return SMTPResponse
+     */
+    private SMTPResponse processHooks(SMTPSession session, String command,
+            String parameters) {
+        List<Hook> hooks = getHooks();
+        if (hooks != null) {
+            int count = hooks.size();
+            for (int i = 0; i < count; i++) {
+                Hook rawHook = hooks.get(i);
+                session.getLogger().debug("executing hook " + rawHook.getClass().getName());
+                HookResult hRes = callHook(rawHook, session, parameters);
+                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, rawHook);
+                    }
+                }
+                SMTPResponse res = calcDefaultSMTPResponse(hRes);
+                if (res != null) {
+                    return res;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Must be implemented by hookable cmd handlers to make the effective call to an hook.
+     * 
+     * @param rawHook the hook
+     * @param session the session
+     * @param parameters the parameters
+     * @return the HookResult, will be calculated using HookResultToSMTPResponse.
+     */
+    protected abstract HookResult callHook(Hook rawHook, SMTPSession session, String parameters);
+
+    /**
+     * Convert the HookResult to SMTPResponse using default values. Should be override for using own values
+     * 
+     * @param result HookResult
+     * @return SMTPResponse
+     */
+    public static SMTPResponse calcDefaultSMTPResponse(HookResult result) {
+        if (result != null) {
+            int rCode = result.getResult();
+            String smtpRetCode = result.getSmtpRetCode();
+            String smtpDesc = result.getSmtpDescription();
+    
+            if (rCode == HookReturnCode.DENY) {
+                if (smtpRetCode == null)
+                    smtpRetCode = SMTPRetCode.TRANSACTION_FAILED;
+                if (smtpDesc == null)
+                    smtpDesc = "Email rejected";
+    
+                return new SMTPResponse(smtpRetCode, smtpDesc);
+            } else if (rCode == HookReturnCode.DENYSOFT) {
+                if (smtpRetCode == null)
+                    smtpRetCode = SMTPRetCode.LOCAL_ERROR;
+                if (smtpDesc == null)
+                    smtpDesc = "Temporary problem. Please try again later";
+    
+                return new SMTPResponse(smtpRetCode, smtpDesc);
+            } else if (rCode == HookReturnCode.OK) {
+                if (smtpRetCode == null)
+                    smtpRetCode = SMTPRetCode.MAIL_OK;
+                if (smtpDesc == null)
+                    smtpDesc = "Command accepted";
+    
+                return new SMTPResponse(smtpRetCode, smtpDesc);
+            } else {
+                // Return null as default
+                return null;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Execute Syntax checks and return a SMTPResponse if a syntax error was
+     * detected, otherwise null.
+     * 
+     * @param session
+     * @param command
+     * @param parameters
+     * @return
+     */
+    protected abstract SMTPResponse doFilterChecks(SMTPSession session,
+            String command, String parameters);
+
+    /**
+     * Execute the core commandHandling.
+     * 
+     * @param session
+     * @param command
+     * @param parameters
+     * @return
+     */
+    protected abstract SMTPResponse doCoreCmd(SMTPSession session,
+            String command, String parameters);
+    
+
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#getMarkerInterfaces()
+     */
+    public List<Class<?>> getMarkerInterfaces() {
+        List<Class<?>> classes = new ArrayList<Class<?>>(2);
+        classes.add(getHookInterface());
+        classes.add(HookResultHook.class);
+        return classes;
+    }
+
+    /**
+     * Return the interface which hooks need to implement to hook in
+     * 
+     * @return interface
+     */
+    protected abstract Class<Hook> getHookInterface();
+
+    /**
+     * @see org.apache.james.api.protocol.ExtensibleHandler#wireExtensions(java.lang.Class,
+     *      java.util.List)
+     */
+    @SuppressWarnings("unchecked")
+    public void wireExtensions(Class interfaceName, List extension) {
+        if (getHookInterface().equals(interfaceName)) {
+            this.hooks = extension;
+        } else if (HookResultHook.class.equals(interfaceName)) {
+            this.rHooks = extension;
+        }
+
+    }
+
+    /**
+     * Return a list which holds all hooks for the cmdHandler
+     * 
+     * @return
+     */
+    protected List<Hook> getHooks() {
+        return hooks;
+    }
+
+}

Added: james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractSenderAuthIdentifyVerificationRcptHook.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractSenderAuthIdentifyVerificationRcptHook.java?rev=905220&view=auto
==============================================================================
--- james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractSenderAuthIdentifyVerificationRcptHook.java (added)
+++ james/protocols/trunk/smtp/src/main/java/org/apache/james/smtpserver/protocol/core/AbstractSenderAuthIdentifyVerificationRcptHook.java Mon Feb  1 09:29:55 2010
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.Locale;
+
+import org.apache.james.dsn.DSNStatus;
+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;
+
+/**
+ * Handler which check if the authenticated user is incorrect or correct
+ */
+public abstract class AbstractSenderAuthIdentifyVerificationRcptHook implements RcptHook {  
+    /**
+     * @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) {
+        if (session.getUser() != null) {
+            String authUser = (session.getUser()).toLowerCase(Locale.US);
+            MailAddress senderAddress = (MailAddress) session.getState().get(
+                    SMTPSession.SENDER);
+
+            if ((senderAddress == null)
+                    || (!authUser.equals(senderAddress.getLocalPart()))
+                    || (!isLocalDomain(senderAddress.getDomain()))) {
+                return new HookResult(HookReturnCode.DENY, 
+                        SMTPRetCode.BAD_SEQUENCE,
+                        DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                DSNStatus.SECURITY_AUTH)
+                                + " Incorrect Authentication for Specified Email Address");
+            }
+        }
+        return new HookResult(HookReturnCode.DECLINED);
+    }
+    
+    
+    /**
+     * Return true if the given domain is a local domain for this server
+     * 
+     * @param domain
+     * @return isLocal
+     */
+    protected abstract boolean isLocalDomain(String domain);
+
+}



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


Mime
View raw message