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 ) ) {
out.println("Can't set forwarding for this user type.");
return true;
}
JamesUser user = (JamesUser)baseuser;
// Veriy acceptable email address
MailAddress forwardAddr;
try {
forwardAddr = new MailAddress(forward);
} catch(ParseException pe) {
out.println("Parse exception with that email address: "
+ pe.getMessage());
out.println("Forwarding address not added for " + username);
return true;
}
boolean success;
success = user.setForwardingDestination(forwardAddr);
if (success){
user.setForwarding(true);
users.updateUser(user);
out.println("Forwarding destination for " + username
+ " set to:" + forwardAddr.toString());
getLogger().info("Forwarding destination for " + username
+ " set to:" + forwardAddr.toString());
} else {
out.println("Error setting forwarding");
getLogger().info("Error setting forwarding");
}
out.flush();
return true;
} else if (command.equalsIgnoreCase("UNSETALIAS")) {
if (argument == null) {
out.println("usage: unsetalias [username]");
return true;
}
String username = argument;
if (username.equals("")) {
out.println("usage: adduser [username]");
return true;
}
JamesUser user = (JamesUser) users.getUserByName(username);
if (user == null) {
out.println("No such user");
return true;
}
if (user.getAliasing()){
user.setAliasing(false);
users.updateUser(user);
out.println("Alias for " + username + " unset");
getLogger().info("Alias for " + username + " unset");
} else {
out.println("Aliasing not active for" + username);