/****************************************************************
 * 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.postage.smtpserver;

import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.james.smtpserver.HeloCmdHandler;
import org.apache.james.smtpserver.EhloCmdHandler;
import org.apache.james.smtpserver.AuthCmdHandler;
import org.apache.james.smtpserver.NoopCmdHandler;
import org.apache.james.smtpserver.SendMailHandler;
import org.apache.james.smtpserver.VrfyCmdHandler;
import org.apache.james.smtpserver.ExpnCmdHandler;
import org.apache.james.smtpserver.MailCmdHandler;
import org.apache.james.smtpserver.RcptCmdHandler;
import org.apache.james.smtpserver.DataCmdHandler;
import org.apache.james.smtpserver.RsetCmdHandler;
import org.apache.james.smtpserver.HelpCmdHandler;
import org.apache.james.smtpserver.QuitCmdHandler;

public class SimpleSMTPServerConfiguration extends DefaultConfiguration {
    private int m_smtpListenerPort;
    private String m_authorizedAddresses = "127.0.0.0/8";
    private String m_authorizingMode = "false";

    public static Configuration getValuedConfiguration(String name, String value) {
        DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);
        defaultConfiguration.setValue(value);
        return defaultConfiguration;
    }

    public static DefaultConfiguration createHandlerChainConfiguration() {
        DefaultConfiguration handlerChainConfig = new DefaultConfiguration("handlerchain");
        handlerChainConfig.addChild(createCommandHandlerConfiguration("HELO", HeloCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("EHLO", EhloCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("AUTH", AuthCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("VRFY", VrfyCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("EXPN", ExpnCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("MAIL", MailCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("RCPT", RcptCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("DATA", DataCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("RSET", RsetCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("HELP", HelpCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("QUIT", QuitCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("NOOP", NoopCmdHandler.class));
        handlerChainConfig.addChild(createCommandHandlerConfiguration("Default SendMailHandler", SendMailHandler.class));
        return handlerChainConfig;
    }

    private static DefaultConfiguration createCommandHandlerConfiguration(String command, Class commandClass) {
        DefaultConfiguration cmdHandlerConfig = new DefaultConfiguration("handler");
        cmdHandlerConfig.setAttribute("command", command);
        String classname = commandClass.getName();
        cmdHandlerConfig.setAttribute("class", classname);
        return cmdHandlerConfig;
    }
    public SimpleSMTPServerConfiguration(int smtpListenerPort) {
        super("smptserver");

        m_smtpListenerPort = smtpListenerPort;
    }

    public String getAuthorizedAddresses() {
        return m_authorizedAddresses;
    }

    public void setAuthorizedAddresses(String authorizedAddresses) {
        m_authorizedAddresses = authorizedAddresses;
    }

    public void setAuthorizingNotRequired() {
        m_authorizingMode = "false";
    }

    public void setAuthorizingRequired() {
        m_authorizingMode = "true";
        //m_verifyIdentity = true;
    }

    public void setAuthorizingAnnounce() {
        m_authorizingMode = "announce";
        //m_verifyIdentity = true;
    }

    public void init() {

        setAttribute("enabled", true);

        addChild(getValuedConfiguration("port", "" + m_smtpListenerPort));

        DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
        handlerConfig.addChild(getValuedConfiguration("helloName", "myMailServer"));
        handlerConfig.addChild(getValuedConfiguration("connectiontimeout", "360000"));
        handlerConfig.addChild(getValuedConfiguration("authorizedAddresses", m_authorizedAddresses));
        handlerConfig.addChild(getValuedConfiguration("maxmessagesize", "" + 0));
        handlerConfig.addChild(getValuedConfiguration("authRequired", m_authorizingMode));

        handlerConfig.addChild(createHandlerChainConfiguration());
        addChild(handlerConfig);
    }

}

@@ -585,20 +585,29 @@
         
+       
 *%0A *
+  
    http:
@@ -656,28 +656,40 @@
             
-*%0A *
+     *%0A *       
             
@@ -1390,3107 +1390,483 @@
 on;%0A
-import org.apache.james.smtpserver.HeloCmdHandler;%0Aimport org.apache.james.smtpserver.EhloCmdHandler;%0Aimport org.apache.james.smtpserver.AuthCmdHandler;%0Aimport org.apache.james.smtpserver.NoopCmdHandler;%0Aimport org.apache.james.smtpserver.SendMailHandler;%0Aimport org.apache.james.smtpserver.VrfyCmdHandler;%0Aimport org.apache.james.smtpserver.ExpnCmdHandler;%0Aimport org.apache.james.smtpserver.MailCmdHandler;%0Aimport org.apache.james.smtpserver.RcptCmdHandler;%0Aimport org.apache.james.smtpserver.DataCmdHandler;%0Aimport org.apache.james.smtpserver.RsetCmdHandler;%0Aimport org.apache.james.smtpserver.HelpCmdHandler;%0Aimport org.apache.james.smtpserver.QuitCmdHandler;%0A%0Apublic class SimpleSMTPServerConfiguration extends DefaultConfiguration %7B%0A    private int m_smtpListenerPort;%0A    private String m_authorizedAddresses = %22127.0.0.0/8%22;%0A    private String m_authorizingMode = %22false%22;%0A%0A    public static Configuration getValuedConfiguration(String name, String value) %7B%0A        DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);%0A        defaultConfiguration.setValue(value);%0A        return defaultConfiguration;%0A    %7D%0A%0A    public static DefaultConfiguration createHandlerChainConfiguration() %7B%0A        DefaultConfiguration handlerChainConfig = new DefaultConfiguration(%22handlerchain%22);%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22HELO%22, HeloCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22EHLO%22, EhloCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22AUTH%22, AuthCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22VRFY%22, VrfyCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22EXPN%22, ExpnCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22MAIL%22, MailCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22RCPT%22, RcptCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22DATA%22, DataCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22RSET%22, RsetCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22HELP%22, HelpCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22QUIT%22, QuitCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22NOOP%22, NoopCmdHandler.class));%0A        handlerChainConfig.addChild(createCommandHandlerConfiguration(%22Default SendMailHandler%22, SendMailHandler.class));%0A        return handlerChainConfig;%0A    %7D%0A%0A    private static DefaultConfiguration createCommandHandlerConfiguration(String command, Class commandClass) %7B%0A        DefaultConfiguration cmdHandlerConfig = new DefaultConfiguration(%22handler%22);%0A        cmdHandlerConfig.setAttribute(%22command%22, command);%0A        String classname = commandClass.getName();%0A        cmdHandlerConfig.setAttribute(%22class%22, classname);%0A        return cmdHandlerConfig;%0A    %7D
+%0Apublic class SimpleSMTPServerConfiguration extends DefaultConfiguration %7B%0A    private int m_smtpListenerPort;%0A    private String m_authorizedAddresses = %22127.0.0.0/8%22;%0A    private String m_authorizingMode = %22false%22;%0A%0A    public static Configuration getValuedConfiguration(String name, String value) %7B%0A        DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);%0A        defaultConfiguration.setValue(value);%0A        return defaultConfiguration;%0A    %7D%0A
 %0A   
@@ -3242,75 +3242,8 @@
 );%0A%0A
-        handlerConfig.addChild(createHandlerChainConfiguration());%0A
     

Remove the hardcoded configuration of the smtphandler as SMTPHandler already define its own default handlerchain if no chain is specified.