/*
* (non-Javadoc)
* @see org.apache.james.protocols.api.CommandHandler#onCommand(org.apache.james.protocols.api.ProtocolSession, org.apache.james.protocols.api.Request)
*/
public Response onCommand(RemoteManagerSession session, Request request) {
RemoteManagerResponse response = null;
String parameters = request.getArgument();
int breakIndex = -1;
if ((parameters == null) ||
(parameters.equals("")) ||
((breakIndex = parameters.indexOf(" ")) < 0)) {
response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
return response;
}
String username = parameters.substring(0,breakIndex);
String passwd = parameters.substring(breakIndex + 1);
if (username.equals("") || passwd.equals("")) {
response = new RemoteManagerResponse("Usage: " + getHelp().getSyntax());
return response;
}
UsersRepository users = uStore.getRepository((String)session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
boolean success = false;
if (users.contains(username)) {
StringBuilder responseBuffer =
new StringBuilder(64)
.append("User ")
.append(username)
.append(" already exists");
response = new RemoteManagerResponse(responseBuffer.toString());
return response;
} else {
if((username.indexOf("@") < 0) == false) {
if(mailServer.supportVirtualHosting() == false) {
response = new RemoteManagerResponse("Virtualhosting not supported");
return response;
}
String domain = username.split("@")[1];
if (domList.containsDomain(domain) == false) {
response = new RemoteManagerResponse("Domain not exists: " + domain);
return response;
}
}
success = users.addUser(username, passwd);
}
if ( success ) {
StringBuilder responseBuffer =
new StringBuilder(64)
.append("User ")
.append(username)
.append(" added");
session.getLogger().info(responseBuffer);
response = new RemoteManagerResponse(responseBuffer.toString());
return response;
} else {
session.getLogger().error("Error adding user " + username);
response = new RemoteManagerResponse("Error adding user " + username);
return response;
}
}