org.subethamail.smtp.command.ReceiptCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of subethasmtp Show documentation
Show all versions of subethasmtp Show documentation
SubEtha SMTP is an easy-to-use server-side SMTP library for Java.
package org.subethamail.smtp.command;
import java.io.IOException;
import java.util.Locale;
import org.subethamail.smtp.RejectException;
import org.subethamail.smtp.server.BaseCommand;
import org.subethamail.smtp.server.Session;
import org.subethamail.smtp.util.EmailUtils;
/**
* @author Ian McFarland <[email protected]>
* @author Jon Stevens
* @author Jeff Schnitzer
*/
public class ReceiptCommand extends BaseCommand
{
/** */
public ReceiptCommand()
{
super("RCPT",
"Specifies the recipient. Can be used any number of times.",
"TO: [ ]");
}
/** */
@Override
public void execute(String commandString, Session sess) throws IOException
{
if (!sess.getHasMailFrom())
{
sess.sendResponse("503 Error: need MAIL command");
return;
}
else if (sess.getServer().getMaxRecipients() >= 0 &&
sess.getRecipientCount() >= sess.getServer().getMaxRecipients())
{
sess.sendResponse("452 Error: too many recipients");
return;
}
String args = this.getArgPredicate(commandString);
if (!args.toUpperCase(Locale.ENGLISH).startsWith("TO:"))
{
sess.sendResponse(
"501 Syntax: RCPT TO: Error in parameters: \""
+ args + "\"");
return;
}
else
{
String recipientAddress = EmailUtils.extractEmailAddress(args, 3);
try
{
sess.getMessageHandler().recipient(recipientAddress);
sess.addRecipient();
sess.sendResponse("250 Ok");
}
catch (RejectException ex)
{
sess.sendResponse(ex.getMessage());
}
}
}
}