* @param session SMTP session
* @param argument the argument passed in with the command by the SMTP client
*/
private SMTPResponse doAUTH(SMTPSession session, String argument) {
if (session.getUser() != null) {
return new SMTPResponse(SMTPRetCode.BAD_SEQUENCE, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" User has previously authenticated. "
+ " Further authentication is not required!");
} else if (argument == null) {
return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Usage: AUTH (authentication type) <challenge>");
} else {
String initialResponse = null;
if ((argument != null) && (argument.indexOf(" ") > 0)) {
initialResponse = argument.substring(argument.indexOf(" ") + 1);
argument = argument.substring(0,argument.indexOf(" "));
}
String authType = argument.toUpperCase(Locale.US);
if (authType.equals(AUTH_TYPE_PLAIN)) {
String userpass;
if (initialResponse == null) {
session.pushLineHandler(new AbstractSMTPLineHandler() {
protected SMTPResponse onCommand(SMTPSession session, String l) {
return doPlainAuthPass(session, l);
}
});
return new SMTPResponse(SMTPRetCode.AUTH_READY, "OK. Continue authentication");
} else {
userpass = initialResponse.trim();
return doPlainAuthPass(session, userpass);
}
} else if (authType.equals(AUTH_TYPE_LOGIN)) {
if (initialResponse == null) {
session.pushLineHandler(new AbstractSMTPLineHandler() {
protected SMTPResponse onCommand(SMTPSession session, String l) {
return doLoginAuthPass(session, l);
}
});
return new SMTPResponse(SMTPRetCode.AUTH_READY, "VXNlcm5hbWU6"); // base64 encoded "Username:"
} else {
String user = initialResponse.trim();
return doLoginAuthPass(session, user);
}
} else {