EhloCmdHandlerpublic class EhloCmdHandler extends org.apache.avalon.framework.logger.AbstractLogEnabled implements CommandHandler, org.apache.avalon.framework.configuration.Configurable
Fields Summary |
---|
private static final String | COMMAND_NAMEThe name of the command handled by the command handler | private boolean | checkResolvableEhloset checkResolvableEhlo to false as default value | private boolean | checkAuthNetworks |
Methods Summary |
---|
public void | configure(org.apache.avalon.framework.configuration.Configuration handlerConfiguration)
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 void | doEHLO(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.
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 void | onCommand(SMTPSession session)
doEHLO(session, session.getCommandArgument());
|
|