FileDocCategorySizeDatePackage
EhloCmdHandler.javaAPI DocApache James 2.3.16495Fri Jan 12 12:56:26 GMT 2007org.apache.james.smtpserver

EhloCmdHandler

public class EhloCmdHandler extends org.apache.avalon.framework.logger.AbstractLogEnabled implements CommandHandler, org.apache.avalon.framework.configuration.Configurable
Handles EHLO command

Fields Summary
private static final String
COMMAND_NAME
The name of the command handled by the command handler
private boolean
checkResolvableEhlo
set checkResolvableEhlo to false as default value
private boolean
checkAuthNetworks
Constructors Summary
Methods Summary
public voidconfigure(org.apache.avalon.framework.configuration.Configuration handlerConfiguration)

see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)

    
           
          
        Configuration configuration = handlerConfiguration.getChild("checkResolvableEhlo",false);
        if(configuration != null) {
            checkResolvableEhlo = configuration.getValueAsBoolean();
        }
        
        Configuration configRelay = handlerConfiguration.getChild("checkAuthNetworks",false);
        if(configRelay != null) {
            checkAuthNetworks = configRelay.getValueAsBoolean();
        }
    
private voiddoEHLO(SMTPSession session, java.lang.String argument)
Handler method called upon receipt of a EHLO command. Responds with a greeting and informs the client whether client authentication is required.

param
session SMTP session object
param
argument the argument passed in with the command by the SMTP client

        String responseString = null;
        StringBuffer responseBuffer = session.getResponseBuffer();
        boolean badEhlo = false;
        
        // check for resolvabe helo if its set in config
        if (checkResolvableEhlo) {
            
            /**
             * don't check if the ip address is allowed to relay. Only check if it is set in the config. ed.
             */
            if (!session.isRelayingAllowed() || checkAuthNetworks) {

             
                // try to resolv the provided helo. If it can not resolved do not accept it.
                try {
                    org.apache.james.dnsserver.DNSServer.getByName(argument);
                } catch (UnknownHostException e) {
                    badEhlo = true;
                    responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Provided EHLO " + argument + " can not resolved";
                    session.writeResponse(responseString);
                    getLogger().info(responseString);
                }
            }
        }
        
        if (argument == null) {
            responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Domain address required: " + COMMAND_NAME;
            session.writeResponse(responseString);
        } else if (!badEhlo){
            session.resetState();
            session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);

            ArrayList esmtpextensions = new ArrayList();

            esmtpextensions.add(new StringBuffer(session.getConfigurationData().getHelloName())
                .append(" Hello ")
                .append(argument)
                .append(" (")
                .append(session.getRemoteHost())
                .append(" [")
                .append(session.getRemoteIPAddress())
                .append("])").toString());

            // Extension defined in RFC 1870
            long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
            if (maxMessageSize > 0) {
                esmtpextensions.add("SIZE " + maxMessageSize);
            }

            if (session.isAuthRequired()) {
                esmtpextensions.add("AUTH LOGIN PLAIN");
                esmtpextensions.add("AUTH=LOGIN PLAIN");
            }

            esmtpextensions.add("PIPELINING");
            esmtpextensions.add("ENHANCEDSTATUSCODES");
            // see http://issues.apache.org/jira/browse/JAMES-419 
            //esmtpextensions.add("8BITMIME");


            // Iterator i = esmtpextensions.iterator();
            for (int i = 0; i < esmtpextensions.size(); i++) {
                if (i == esmtpextensions.size() - 1) {
                    responseBuffer.append("250 ");
                    responseBuffer.append((String) esmtpextensions.get(i));
                    session.writeResponse(session.clearResponseBuffer());
                } else {
                    responseBuffer.append("250-");
                    responseBuffer.append((String) esmtpextensions.get(i));
                    session.writeResponse(session.clearResponseBuffer());
                }
            }
        }
    
public voidonCommand(SMTPSession session)

        doEHLO(session, session.getCommandArgument());