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

HeloCmdHandler

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

Fields Summary
private static final String
COMMAND_NAME
The name of the command handled by the command handler
private boolean
checkResolvableHelo
set checkValidHelo 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("checkResolvableHelo",false);
        if(configuration != null) {
            checkResolvableHelo = configuration.getValueAsBoolean();
        }
        
        Configuration configRelay = handlerConfiguration.getChild("checkAuthNetworks",false);
        if(configRelay != null) {
            checkAuthNetworks = configRelay.getValueAsBoolean();
        }
        
    
private voiddoHELO(SMTPSession session, java.lang.String argument)
Handler method called upon receipt of a HELO 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;
        boolean badHelo = false;
                
        
        // check for resolvable helo if its set in config
        if (checkResolvableHelo) {
            
            /**
             * 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) {
                    badHelo = true;
                    responseString = "501 Provided HELO " + argument + " can not resolved";
                    session.writeResponse(responseString);
                    getLogger().info(responseString);
                } 

            }
        }
        
        if (argument == null) {
            responseString = "501 Domain address required: " + COMMAND_NAME;
            session.writeResponse(responseString);
            getLogger().info(responseString);
        } else if (!badHelo) {
            session.resetState();
            session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
            session.getResponseBuffer().append("250 ")
                          .append(session.getConfigurationData().getHelloName())
                          .append(" Hello ")
                          .append(argument)
                          .append(" (")
                          .append(session.getRemoteHost())
                          .append(" [")
                          .append(session.getRemoteIPAddress())
                          .append("])");
            responseString = session.clearResponseBuffer();
            session.writeResponse(responseString);
        }
    
public voidonCommand(SMTPSession session)

        doHELO(session, session.getCommandArgument());