All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.subethamail.smtp.internal.command.HelpCommand Maven / Gradle / Ivy

Go to download

A fork of a fork (!) of SubEtha, an easy-to-use server-side SMTP library for Java.

There is a newer version: 7.1.3
Show newest version
package org.subethamail.smtp.internal.command;

import java.io.IOException;

import org.subethamail.smtp.internal.server.BaseCommand;
import org.subethamail.smtp.internal.server.CommandException;
import org.subethamail.smtp.server.SMTPServer;
import org.subethamail.smtp.server.Session;

/**
 * Provides a help  system for people to interact with.
 *
 * @author Ian McFarland <[email protected]>
 * @author Jon Stevens
 * @author Scott Hernandez
 */
public final class HelpCommand extends BaseCommand
{

	public HelpCommand()
	{
		super("HELP",
				"The HELP command gives help info about the topic specified.\n"
					+ "For a list of topics, type HELP by itself.",
				"[  ]");
	}

	@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 String getCommandMessage(SMTPServer server)
	{
		return "214-"
				+ server.getSoftwareName()
				+ " on "
				+ server.getHostName()
				+ "\r\n"
				+ "214-Topics:\r\n"
				+ this.getFormattedTopicList(server)
				+ "214-For more info use \"HELP \".\r\n"
				+ "214 End of HELP info";
	}

	protected String getFormattedTopicList(SMTPServer server)
	{
		StringBuilder sb = new StringBuilder();
		for (String key : server.getCommandHandler().getVerbs())
	    {
	    	sb.append("214-     " + key + "\r\n");
	    }
		return sb.toString();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy