/** * The primary constructor. */ public SMTPServer(MessageHandlerFactory handlerFactory) { this.messageHandlerFactory = handlerFactory; try { this.hostName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { this.hostName = "localhost"; } this.commandHandler = new CommandHandler(); this.connectionHanderGroup = new ThreadGroup(SMTPServer.class.getName() + " ConnectionHandler Group"); }
public CommandHandler(Collection<Command> availableCommands) { for(Command command :availableCommands ) { addCommand(command); } }
/** * @return the HelpMessage object for the given command name (verb) * @throws CommandException */ public HelpMessage getHelp(String command) throws CommandException { return this.getCommandFromString(command).getHelp(); }
private Command getCommandFromString(String commandString) throws UnknownCommandException, InvalidCommandNameException { Command command = null; String key = toKey(commandString); if (key != null) { command = this.commandMap.get(key); } if (command == null) { // some commands have a verb longer than 4 letters String verb = toVerb(commandString); if (verb != null) { command = this.commandMap.get(verb); } } if (command == null) { throw new UnknownCommandException("Error: command not implemented"); } return command; }
log.debug("Client: " + line); this.server.getCommandHandler().handleCommand(this, line);
/** */ protected String getFormattedTopicList(SMTPServer server) { StringBuilder sb = new StringBuilder(); for (String key : server.getCommandHandler().getVerbs()) { sb.append("214- " + key + "\r\n"); } return sb.toString(); } }
/** */ @Override public void execute(String commandString, Session context) throws IOException { String args = this.getArgPredicate(commandString); if ("".equals(args)) { context.sendResponse(this.getCommandMessage(context.getServer())); return; } try { context.sendResponse(context.getServer().getCommandHandler().getHelp(args).toOutputString()); } catch (CommandException e) { context.sendResponse("504 HELP topic \"" + args + "\" unknown."); } }
/** */ private Command getCommandFromString(String commandString) throws UnknownCommandException, InvalidCommandNameException { Command command = null; String key = this.toKey(commandString); if (key != null) { command = this.commandMap.get(key); } if (command == null) { // some commands have a verb longer than 4 letters String verb = this.toVerb(commandString); if (verb != null) { command = this.commandMap.get(verb); } } if (command == null) { throw new UnknownCommandException("Error: command not implemented"); } return command; }
log.debug("Client: " + line); this.server.getCommandHandler().handleCommand(this, line); lastActiveTime = System.currentTimeMillis();
/** */ protected String getFormattedTopicList(SMTPServer server) { StringBuilder sb = new StringBuilder(); for (String key : server.getCommandHandler().getVerbs()) { sb.append("214- " + key + "\r\n"); } return sb.toString(); } }
/** */ @Override public void execute(String commandString, Session context) throws IOException { String args = this.getArgPredicate(commandString); if ("".equals(args)) { context.sendResponse(this.getCommandMessage(context.getServer())); return; } try { context.sendResponse(context.getServer().getCommandHandler().getHelp(args).toOutputString()); } catch (CommandException e) { context.sendResponse("504 HELP topic \"" + args + "\" unknown."); } }
MessageHandler mh = new MessageHandler(this); CommandHandler ch = new CommandHandler(this);
/** */ private Command getCommandFromString(String commandString) throws UnknownCommandException, InvalidCommandNameException { Command command = null; String key = this.toKey(commandString); if (key != null) { command = this.commandMap.get(key); } if (command == null) { // some commands have a verb longer than 4 letters String verb = this.toVerb(commandString); if (verb != null) { command = this.commandMap.get(verb); } } if (command == null) { throw new UnknownCommandException("Error: command not implemented"); } return command; }
/** * Create a command handler with a specific set of commands. * * @param availableCommands the available commands (not null) * TLS note: wrap commands with {@link RequireTLSCommandWrapper} when appropriate. */ public CommandHandler(Collection<Command> availableCommands) { for (Command command: availableCommands) { this.addCommand(command); } }
/** * @return the HelpMessage object for the given command name (verb) * @throws CommandException */ public HelpMessage getHelp(String command) throws CommandException { return this.getCommandFromString(command).getHelp(); }
log.debug("Client: " + line); this.server.getCommandHandler().handleCommand(this, line);
this.commandHandler = new CommandHandler();
/** * Create a command handler with a specific set of commands. * * @param availableCommands the available commands (not null) * TLS note: wrap commands with {@link RequireTLSCommandWrapper} when appropriate. */ public CommandHandler(Collection<Command> availableCommands) { for (Command command: availableCommands) { this.addCommand(command); } }
public void handleCommand(ConnectionContext context, String commandString) throws SocketTimeoutException, IOException { try { Command command = getCommandFromString(commandString); command.execute(commandString, context); } catch (CommandException e) { context.sendResponse("500 " + e.getMessage()); } }
this.commandHandler = new CommandHandler();