String passwd = argument1;
if (username.equals("") || passwd.equals("")) {
out.println("usage: adduser [username] [password]");
return true;
}
User user = users.getUserByName(username);
if (user == null) {
out.println("No such user");
return true;
}
boolean success;
success = user.setPassword(passwd);
if (success){
users.updateUser(user);
out.println("Password for " + username + " reset");
getLogger().info("Password for " + username + " reset");
} else {
out.println("Error resetting password");
getLogger().info("Error resetting password");
}
out.flush();
return true;
} else if (command.equalsIgnoreCase("DELUSER")) {
String user = argument;
if (user.equals("")) {
out.println("usage: deluser [username]");
return true;
}
try {
users.removeUser(user);
} catch (Exception e) {
out.println("Error deleting user " + user + " : " + e.getMessage());
return true;
}
out.println("User " + user + " deleted");
getLogger().info("User " + user + " deleted");
} else if (command.equalsIgnoreCase("LISTUSERS")) {
out.println("Existing accounts " + users.countUsers());
for (Iterator it = users.list(); it.hasNext();) {
out.println("user: " + (String) it.next());
}
} else if (command.equalsIgnoreCase("COUNTUSERS")) {
out.println("Existing accounts " + users.countUsers());
} else if (command.equalsIgnoreCase("VERIFY")) {
String user = argument;
if (user.equals("")) {
out.println("usage: verify [username]");
return true;
}
if (users.contains(user)) {
out.println("User " + user + " exist");
} else {
out.println("User " + user + " does not exist");
}
} else if (command.equalsIgnoreCase("HELP")) {
out.println("Currently implemented commans:");
out.println("help display this help");
out.println("listusers display existing accounts");
out.println("countusers display the number of existing accounts");
out.println("adduser [username] [password] add a new user");
out.println("verify [username] verify if specified user exist");
out.println("deluser [username] delete existing user");
out.println("setpassword [username] [password] sets a user's password");
out.println("setalias [username] [alias] sets a user's alias");
out.println("unsetalias [username] removes a user's alias");
out.println("setforwarding [username] [emailaddress] forwards a user's email to another account");
out.println("user [repositoryname] change to another user repository");
out.println("shutdown kills the current JVM (convenient when James is run as a daemon)");
out.println("quit close connection");
out.flush();
} else if (command.equalsIgnoreCase("SETALIAS")) {
if (argument == null || argument1 == null) {
out.println("usage: setalias [username] [alias]");
return true;
}
String username = argument;
String alias = argument1;
if (username.equals("") || alias.equals("")) {
out.println("usage: adduser [username] [alias]");
return true;
}
JamesUser user = (JamesUser) users.getUserByName(username);
if (user == null) {
out.println("No such user");
return true;
}
JamesUser aliasUser = (JamesUser) users.getUserByName(alias);
if (aliasUser == null) {
out.println("Alias unknown to server"
+ " - create that user first.");
return true;
}
boolean success;
success = user.setAlias(alias);
if (success){
user.setAliasing(true);
users.updateUser(user);
out.println("Alias for " + username + " set to:" + alias);
getLogger().info("Alias for " + username + " set to:" + alias);
} else {
out.println("Error setting alias");
getLogger().info("Error setting alias");
}
out.flush();
return true;
} else if (command.equalsIgnoreCase("SETFORWARDING")) {
if (argument == null || argument1 == null) {
out.println("usage: setforwarding [username] [emailaddress]");
return true;
}
String username = argument;
String forward = argument1;
if (username.equals("") || forward.equals("")) {
out.println("usage: adduser [username] [emailaddress]");
return true;
}
// Verify user exists
User baseuser = users.getUserByName(username);
if (baseuser == null) {
out.println("No such user");
return true;
}
else if (! (baseuser instanceof JamesUser ) ) {