You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/08/07 16:11:33 UTC
svn commit: r802017 [1/3] - in
/james/server/sandbox/active/smtp_refactor/smtpserver-function/src:
main/java/org/apache/james/smtpserver/core/
main/java/org/apache/james/smtpserver/core/filter/
main/java/org/apache/james/smtpserver/core/filter/fastfail...
Author: norman
Date: Fri Aug 7 14:11:31 2009
New Revision: 802017
URL: http://svn.apache.org/viewvc?rev=802017&view=rev
Log:
First step for the smtp server refactoring
Added:
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostDataListener.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostEhloListener.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostHeloListener.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostMailListener.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostRcptListener.java
Removed:
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/CoreFilterCmdHandlerLoader.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/DataFilterCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/AbstractJunkHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/JunkHandlerData.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/JunkScoreHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/JunkScoreHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/junkscore/
Modified:
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/MailCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/MaxRcptHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ResolvableEhloHeloHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ReverseEqualsEhloHeloHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SpamAssassinHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SupressDuplicateRcptHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/TarpitHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/URIRBLHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptMX.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidSenderDomainHandler.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/DNSRBLHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/MaxRcptHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ResolvableEhloHeloHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SPFHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/SpamAssassinHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/URIRBLHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptMXTest.java
james/server/sandbox/active/smtp_refactor/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidSenderDomainHandlerTest.java
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractCmdHandler.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractCmdHandler.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/AbstractCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,21 @@
+package org.apache.james.smtpserver.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+
+public abstract class AbstractCmdHandler<Listener> extends AbstractLogEnabled {
+ protected List<Listener> listeners = new ArrayList<Listener>();
+
+ public AbstractCmdHandler() {
+ listeners.add(getLastListener());
+ }
+
+ public void setListener(List<Listener> listeners) {
+ listeners.addAll(this.listeners);
+ this.listeners = listeners;
+ }
+
+ protected abstract Listener getLastListener();
+}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/DataCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -34,6 +34,7 @@
import org.apache.james.util.stream.CharTerminatedInputStream;
import org.apache.james.util.stream.DotStuffingInputStream;
import org.apache.james.util.watchdog.BytesReadResetInputStream;
+import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.base.RFC2822Headers;
import org.apache.mailet.base.RFC822DateFormat;
@@ -103,8 +104,27 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private void doDATA(SMTPSession session, String argument) {
-
String responseString = null;
+ if ((argument != null) && (argument.length() > 0)) {
+ responseString = "500 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Unexpected argument provided with DATA command";
+ session.writeResponse(responseString);
+
+ //TODO: Check if this should been!
+ }
+ if (!session.getState().containsKey(SMTPSession.SENDER)) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No sender specified";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else if (!session.getState().containsKey(SMTPSession.RCPT_LIST)) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" No recipients specified";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+ } else {
responseString = "354 Ok Send data ending with <CRLF>.<CRLF>";
session.writeResponse(responseString);
InputStream msgIn = new CharTerminatedInputStream(session
@@ -180,6 +200,7 @@
msgIn = null;
}
}
+ }
}
@@ -320,8 +341,8 @@
if (session.isRelayingAllowed()) {
mail.setAttribute(SMTP_AUTH_NETWORK_NAME,"true");
}
-
session.setMail(mail);
+
} catch (MessagingException me) {
// if we get here, it means that we received a
// MessagingException, which would happen BEFORE we call
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/EhloCmdHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/EhloCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/EhloCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -24,15 +24,15 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
/**
* Handles EHLO command
*/
-public class EhloCmdHandler extends AbstractLogEnabled implements
- CommandHandler {
+public class EhloCmdHandler extends AbstractCmdHandler<PostEhloListener> implements
+ CommandHandler, PostEhloListener {
/**
* The name of the command handled by the command handler
@@ -57,14 +57,49 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private void doEHLO(SMTPSession session, String argument) {
- StringBuffer responseBuffer = session.getResponseBuffer();
+ String responseString = null;
+
+ session.resetState();
+
+ if (argument == null) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Domain address required: " + COMMAND_NAME;
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+ } else {
+ for (int i = 0; i < listeners.size(); i++) {
+ listeners.get(i).onEhlo(session, argument);
+ }
+ }
+
+
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection implCommands = new ArrayList();
+ implCommands.add("EHLO");
+
+ return implCommands;
+ }
+
+ @Override
+ protected PostEhloListener getLastListener() {
+ return this;
+ }
+
+ public String onEhlo(SMTPSession session, String heloName) {
+ StringBuffer responseBuffer = session.getResponseBuffer();
session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
ArrayList esmtpextensions = new ArrayList();
esmtpextensions.add(new StringBuffer(session.getConfigurationData()
- .getHelloName()).append(" Hello ").append(argument)
+ .getHelloName()).append(" Hello ").append(heloName)
.append(" (").append(session.getRemoteHost()).append(" [")
.append(session.getRemoteIPAddress()).append("])").toString());
@@ -90,23 +125,14 @@
if (i == esmtpextensions.size() - 1) {
responseBuffer.append("250 ");
responseBuffer.append((String) esmtpextensions.get(i));
- session.writeResponse(session.clearResponseBuffer());
} else {
responseBuffer.append("250-");
responseBuffer.append((String) esmtpextensions.get(i));
- session.writeResponse(session.clearResponseBuffer());
}
}
-
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
- public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("EHLO");
+ // store provided name
+ session.getState().put(SMTPSession.CURRENT_HELO_NAME, heloName);
- return implCommands;
- }
+ return responseBuffer.toString();
+ }
}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/HeloCmdHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/HeloCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/HeloCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -25,7 +25,7 @@
import java.util.ArrayList;
import java.util.Collection;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
@@ -33,13 +33,13 @@
/**
* Handles HELO command
*/
-public class HeloCmdHandler extends AbstractLogEnabled implements CommandHandler {
+public class HeloCmdHandler extends AbstractCmdHandler<PostHeloListener> implements CommandHandler, PostHeloListener {
/**
* The name of the command handled by the command handler
*/
- private final static String COMMAND_NAME = "HELO";
-
+ private final static String COMMAND_NAME = "HELO";
+
/**
* process HELO command
*
@@ -54,16 +54,28 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private void doHELO(SMTPSession session, String argument) {
- String responseString = null;
-
- session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
- session.getResponseBuffer().append("250 ").append(
- session.getConfigurationData().getHelloName())
- .append(" Hello ").append(argument).append(" (").append(
- session.getRemoteHost()).append(" [").append(
- session.getRemoteIPAddress()).append("])");
- responseString = session.clearResponseBuffer();
- session.writeResponse(responseString);
+ String responseString = null;
+ session.resetState();
+
+ if (argument == null) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Domain address required: " + COMMAND_NAME;
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+ } else {
+ session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
+
+ for (int i = 0; i < listeners.size(); i++) {
+ responseString = listeners.get(i).onHelo(session, argument);
+ if (responseString != null) {
+ session.setStopHandlerProcessing(true);
+ break;
+ }
+ }
+ session.writeResponse(responseString);
+ }
+
}
/**
@@ -74,5 +86,26 @@
implCommands.add("HELO");
return implCommands;
- }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.smtpserver.core.PostHeloListener#onHelo(org.apache.james.smtpserver.SMTPSession, java.lang.String)
+ */
+ public String onHelo(SMTPSession session, String heloName) {
+ // store provided name
+ session.getState().put(SMTPSession.CURRENT_HELO_NAME,heloName);
+ session.getResponseBuffer().append("250 ").append(
+ session.getConfigurationData().getHelloName())
+ .append(" Hello ").append(heloName).append(" (").append(
+ session.getRemoteHost()).append(" [").append(
+ session.getRemoteIPAddress()).append("])");
+ String responseString = session.clearResponseBuffer();
+ return responseString;
+ }
+
+ @Override
+ protected PostHeloListener getLastListener() {
+ return this;
+ }
}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/MailCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/MailCmdHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/MailCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/MailCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -23,8 +23,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Locale;
+import java.util.StringTokenizer;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
@@ -34,8 +35,14 @@
* Handles MAIL command
*/
public class MailCmdHandler
- extends AbstractLogEnabled
- implements CommandHandler {
+ extends AbstractCmdHandler<PostMailListener>
+ implements CommandHandler,PostMailListener {
+
+ private final static String MAIL_OPTION_SIZE = "SIZE";
+
+ private final static String MESG_SIZE = "MESG_SIZE"; // The size of the
+ // message
+
/**
@@ -56,21 +63,207 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private void doMAIL(SMTPSession session, String argument) {
-
- StringBuffer responseBuffer = session.getResponseBuffer();
- String responseString = null;
-
- MailAddress sender = (MailAddress) session.getState().get(
- SMTPSession.SENDER);
- responseBuffer.append(
- "250 "
- + DSNStatus.getStatus(DSNStatus.SUCCESS,
- DSNStatus.ADDRESS_OTHER) + " Sender <").append(
- sender).append("> OK");
- responseString = session.clearResponseBuffer();
- session.writeResponse(responseString);
-
- }
+ String responseString = null;
+ String sender = null;
+
+ if ((argument != null) && (argument.indexOf(":") > 0)) {
+ int colonIndex = argument.indexOf(":");
+ sender = argument.substring(colonIndex + 1);
+ argument = argument.substring(0, colonIndex);
+ }
+ if (session.getState().containsKey(SMTPSession.SENDER)) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Sender already specified";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else if (!session.getConnectionState().containsKey(SMTPSession.CURRENT_HELO_MODE) && session.useHeloEhloEnforcement()) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need HELO or EHLO before MAIL";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else if (argument == null || !argument.toUpperCase(Locale.US).equals("FROM")
+ || sender == null) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Usage: MAIL FROM:<sender>";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else {
+ sender = sender.trim();
+ // the next gt after the first lt ... AUTH may add more <>
+ int lastChar = sender.indexOf('>', sender.indexOf('<'));
+ // Check to see if any options are present and, if so, whether they are correctly formatted
+ // (separated from the closing angle bracket by a ' ').
+ if ((lastChar > 0) && (sender.length() > lastChar + 2) && (sender.charAt(lastChar + 1) == ' ')) {
+ String mailOptionString = sender.substring(lastChar + 2);
+
+ // Remove the options from the sender
+ sender = sender.substring(0, lastChar + 1);
+
+ StringTokenizer optionTokenizer = new StringTokenizer(mailOptionString, " ");
+ while (optionTokenizer.hasMoreElements()) {
+ String mailOption = optionTokenizer.nextToken();
+ int equalIndex = mailOption.indexOf('=');
+ String mailOptionName = mailOption;
+ String mailOptionValue = "";
+ if (equalIndex > 0) {
+ mailOptionName = mailOption.substring(0, equalIndex).toUpperCase(Locale.US);
+ mailOptionValue = mailOption.substring(equalIndex + 1);
+ }
+
+ // Handle the SIZE extension keyword
+
+ if (mailOptionName.startsWith(MAIL_OPTION_SIZE)) {
+ if (!(doMailSize(session, mailOptionValue, sender))) {
+ return;
+ }
+ } else {
+ // Unexpected option attached to the Mail command
+ if (getLogger().isDebugEnabled()) {
+ StringBuffer debugBuffer =
+ new StringBuffer(128)
+ .append("MAIL command had unrecognized/unexpected option ")
+ .append(mailOptionName)
+ .append(" with value ")
+ .append(mailOptionValue);
+ getLogger().debug(debugBuffer.toString());
+ }
+ }
+ }
+ }
+ if ( session.getConfigurationData().useAddressBracketsEnforcement() && (!sender.startsWith("<") || !sender.endsWith(">"))) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in MAIL command";
+ session.writeResponse(responseString);
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(128)
+ .append("Error parsing sender address: ")
+ .append(sender)
+ .append(": did not start and end with < >");
+ getLogger().error(errorBuffer.toString());
+ }
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ MailAddress senderAddress = null;
+
+ if (session.getConfigurationData().useAddressBracketsEnforcement() || (sender.startsWith("<") && sender.endsWith(">"))) {
+ //Remove < and >
+ sender = sender.substring(1, sender.length() - 1);
+ }
+
+ if (sender.length() == 0) {
+ //This is the <> case. Let senderAddress == null
+ } else {
+
+ if (sender.indexOf("@") < 0) {
+ sender = sender + "@" + session.getConfigurationData().getMailServer().getDefaultDomain();
+ }
+
+ try {
+ senderAddress = new MailAddress(sender);
+ } catch (Exception pe) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER)+" Syntax error in sender address";
+ session.writeResponse(responseString);
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(256)
+ .append("Error parsing sender address: ")
+ .append(sender)
+ .append(": ")
+ .append(pe.getMessage());
+ getLogger().error(errorBuffer.toString());
+ }
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ }
+
+ for (int i = 0; i < listeners.size();i++) {
+ responseString = listeners.get(i).onMail(session, senderAddress);
+ if (responseString != null) {
+ session.writeResponse(responseString);
+ session.setStopHandlerProcessing(true);
+ break;
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Handles the SIZE MAIL option.
+ *
+ * @param session SMTP session object
+ * @param mailOptionValue the option string passed in with the SIZE option
+ * @param tempSender the sender specified in this mail command (for logging purpose)
+ * @return true if further options should be processed, false otherwise
+ */
+ private boolean doMailSize(SMTPSession session, String mailOptionValue, String tempSender) {
+ int size = 0;
+ try {
+ size = Integer.parseInt(mailOptionValue);
+ } catch (NumberFormatException pe) {
+ // This is a malformed option value. We return an error
+ String responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+" Syntactically incorrect value for SIZE parameter";
+ session.writeResponse(responseString);
+ getLogger().error("Rejected syntactically incorrect value for SIZE parameter.");
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return false;
+ }
+ if (getLogger().isDebugEnabled()) {
+ StringBuffer debugBuffer =
+ new StringBuffer(128)
+ .append("MAIL command option SIZE received with value ")
+ .append(size)
+ .append(".");
+ getLogger().debug(debugBuffer.toString());
+ }
+ long maxMessageSize = session.getConfigurationData().getMaxMessageSize();
+ if ((maxMessageSize > 0) && (size > maxMessageSize)) {
+ // Let the client know that the size limit has been hit.
+ String responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Message size exceeds fixed maximum message size";
+ session.writeResponse(responseString);
+ StringBuffer errorBuffer =
+ new StringBuffer(256)
+ .append("Rejected message from ")
+ .append(tempSender != null ? tempSender : null)
+ .append(" from host ")
+ .append(session.getRemoteHost())
+ .append(" (")
+ .append(session.getRemoteIPAddress())
+ .append(") of size ")
+ .append(size)
+ .append(" exceeding system maximum message size of ")
+ .append(maxMessageSize)
+ .append("based on SIZE option.");
+ getLogger().error(errorBuffer.toString());
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return false;
+ } else {
+ // put the message size in the message state so it can be used
+ // later to restrict messages for user quotas, etc.
+ session.getState().put(MESG_SIZE, new Integer(size));
+ }
+ return true;
+ }
+
/**
* @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
@@ -81,4 +274,29 @@
return implCommands;
}
+
+
+ public String onMail(SMTPSession session, String mailFrom) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ @Override
+ protected PostMailListener getLastListener() {
+ return this;
+ }
+
+
+ public String onMail(SMTPSession session, MailAddress sender) {
+
+ // Store the senderAddress in session map
+ session.getState().put(SMTPSession.SENDER, sender);
+
+ StringBuffer responseBuffer = session.getResponseBuffer();
+ String responseString = null;
+ responseBuffer.append("250 "+ DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.ADDRESS_OTHER) + " Sender <").append(sender).append("> OK");
+ responseString = session.clearResponseBuffer();
+ return responseString;
+ }
}
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostDataListener.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostDataListener.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostDataListener.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostDataListener.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,30 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.core;
+
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.mailet.Mail;
+
+public interface PostDataListener {
+
+ public String onData(SMTPSession session, Mail mail);
+
+}
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostEhloListener.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostEhloListener.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostEhloListener.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostEhloListener.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.core;
+
+import org.apache.james.smtpserver.SMTPSession;
+
+public interface PostEhloListener {
+
+ public String onEhlo(SMTPSession session, String heloName);
+}
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostHeloListener.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostHeloListener.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostHeloListener.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostHeloListener.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,28 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.core;
+
+import org.apache.james.smtpserver.SMTPSession;
+
+public interface PostHeloListener {
+
+ public String onHelo(SMTPSession session, String heloName);
+}
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostMailListener.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostMailListener.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostMailListener.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostMailListener.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,31 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.core;
+
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.mailet.MailAddress;
+
+public interface PostMailListener {
+
+ public String onMail(SMTPSession session, MailAddress sender);
+
+
+}
Added: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostRcptListener.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostRcptListener.java?rev=802017&view=auto
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostRcptListener.java (added)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/PostRcptListener.java Fri Aug 7 14:11:31 2009
@@ -0,0 +1,29 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.smtpserver.core;
+
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.mailet.MailAddress;
+
+public interface PostRcptListener {
+
+ public String onRcpt(SMTPSession session, MailAddress rcpt);
+}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/RcptCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/RcptCmdHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/RcptCmdHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/RcptCmdHandler.java Fri Aug 7 14:11:31 2009
@@ -23,8 +23,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Locale;
+import java.util.StringTokenizer;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
@@ -33,8 +34,8 @@
/**
* Handles RCPT command
*/
-public class RcptCmdHandler extends AbstractLogEnabled implements
- CommandHandler {
+public class RcptCmdHandler extends AbstractCmdHandler<PostRcptListener> implements
+ CommandHandler, PostRcptListener {
/**
* handles RCPT command
@@ -55,17 +56,253 @@
* @param argument the argument passed in with the command by the SMTP client
*/
private void doRCPT(SMTPSession session, String argument) {
-
- String responseString = null;
- StringBuffer responseBuffer = session.getResponseBuffer();
+ String responseString = null;
+
+ String recipient = null;
+ if ((argument != null) && (argument.indexOf(":") > 0)) {
+ int colonIndex = argument.indexOf(":");
+ recipient = argument.substring(colonIndex + 1);
+ argument = argument.substring(0, colonIndex);
+ }
+ if (!session.getState().containsKey(SMTPSession.SENDER)) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_OTHER)+" Need MAIL before RCPT";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else if (argument == null || !argument.toUpperCase(Locale.US).equals("TO")
+ || recipient == null) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Usage: RCPT TO:<recipient>";
+ session.writeResponse(responseString);
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ } else {
+ Collection rcptColl = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
+ if (rcptColl == null) {
+ rcptColl = new ArrayList();
+ }
+ recipient = recipient.trim();
+ int lastChar = recipient.lastIndexOf('>');
+ // Check to see if any options are present and, if so, whether they are correctly formatted
+ // (separated from the closing angle bracket by a ' ').
+ String rcptOptionString = null;
+ if ((lastChar > 0) && (recipient.length() > lastChar + 2) && (recipient.charAt(lastChar + 1) == ' ')) {
+ rcptOptionString = recipient.substring(lastChar + 2);
+
+ // Remove the options from the recipient
+ recipient = recipient.substring(0, lastChar + 1);
+ }
+ if (session.getConfigurationData().useAddressBracketsEnforcement() && (!recipient.startsWith("<") || !recipient.endsWith(">"))) {
+ responseString = "501 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_SYNTAX)+" Syntax error in parameters or arguments";
+ session.writeResponse(responseString);
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(192)
+ .append("Error parsing recipient address: ")
+ .append("Address did not start and end with < >")
+ .append(getContext(session,null,recipient));
+ getLogger().error(errorBuffer.toString());
+ }
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ MailAddress recipientAddress = null;
+ //Remove < and >
+ if (session.getConfigurationData().useAddressBracketsEnforcement() || (recipient.startsWith("<") && recipient.endsWith(">"))) {
+ recipient = recipient.substring(1, recipient.length() - 1);
+ }
+
+ if (recipient.indexOf("@") < 0) {
+ // set the default domain
+ recipient = recipient + "@" + session.getConfigurationData().getMailServer().getDefaultDomain();
+ }
+
+ try {
+ recipientAddress = new MailAddress(recipient);
+ } catch (Exception pe) {
+ /*
+ * from RFC2822;
+ * 553 Requested action not taken: mailbox name not allowed
+ * (e.g., mailbox syntax incorrect)
+ */
+ responseString = "553 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX)+" Syntax error in recipient address";
+ session.writeResponse(responseString);
+
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(192)
+ .append("Error parsing recipient address: ")
+ .append(getContext(session,recipientAddress,recipient))
+ .append(pe.getMessage());
+ getLogger().error(errorBuffer.toString());
+ }
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+
+
+
+ if (session.isAuthRequired() && !session.isRelayingAllowed()) {
+ // Make sure the mail is being sent locally if not
+ // authenticated else reject.
+ if (session.getUser() == null) {
+ String toDomain = recipientAddress.getHost();
+ if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
+ responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Authentication Required";
+ session.writeResponse(responseString);
+ StringBuffer sb = new StringBuffer(128);
+ sb.append("Rejected message - authentication is required for mail request");
+ sb.append(getContext(session,recipientAddress,recipient));
+ getLogger().error(sb.toString());
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ } else {
+ // Identity verification checking
+ if (session.getConfigurationData().isVerifyIdentity()) {
+ String authUser = (session.getUser()).toLowerCase(Locale.US);
+ MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
+
+ if ((senderAddress == null) || (!authUser.equals(senderAddress.getUser())) ||
+ (!session.getConfigurationData().getMailServer().isLocalServer(senderAddress.getHost()))) {
+ responseString = "503 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Incorrect Authentication for Specified Email Address";
+ session.writeResponse(responseString);
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(128)
+ .append("User ")
+ .append(authUser)
+ .append(" authenticated, however tried sending email as ")
+ .append(senderAddress)
+ .append(getContext(session,recipientAddress,recipient));
+ getLogger().error(errorBuffer.toString());
+ }
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ }
+ }
+ } else if (!session.isRelayingAllowed()) {
+ String toDomain = recipientAddress.getHost();
+ if (!session.getConfigurationData().getMailServer().isLocalServer(toDomain)) {
+ responseString = "550 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Requested action not taken: relaying denied";
+ session.writeResponse(responseString);
+ StringBuffer errorBuffer = new StringBuffer(128)
+ .append("Rejected message - ")
+ .append(session.getRemoteIPAddress())
+ .append(" not authorized to relay to ")
+ .append(toDomain)
+ .append(getContext(session,recipientAddress,recipient));
+ getLogger().error(errorBuffer.toString());
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ return;
+ }
+ }
+ if (rcptOptionString != null) {
+
+ StringTokenizer optionTokenizer = new StringTokenizer(rcptOptionString, " ");
+ while (optionTokenizer.hasMoreElements()) {
+ String rcptOption = optionTokenizer.nextToken();
+ int equalIndex = rcptOption.indexOf('=');
+ String rcptOptionName = rcptOption;
+ String rcptOptionValue = "";
+ if (equalIndex > 0) {
+ rcptOptionName = rcptOption.substring(0, equalIndex).toUpperCase(Locale.US);
+ rcptOptionValue = rcptOption.substring(equalIndex + 1);
+ }
+ // Unexpected option attached to the RCPT command
+ if (getLogger().isDebugEnabled()) {
+ StringBuffer debugBuffer =
+ new StringBuffer(128)
+ .append("RCPT command had unrecognized/unexpected option ")
+ .append(rcptOptionName)
+ .append(" with value ")
+ .append(rcptOptionValue)
+ .append(getContext(session,recipientAddress,recipient));
+ getLogger().debug(debugBuffer.toString());
+ }
+
+ // After this filter match we should not call any other handler!
+ session.setStopHandlerProcessing(true);
+
+ }
+ optionTokenizer = null;
+ }
+
+ for (int i = 0; i < listeners.size(); i++) {
+ String response = listeners.get(i).onRcpt(session, recipientAddress);
+ if (response != null) {
+ session.writeResponse(response);
+ session.setStopHandlerProcessing(true);
+ break;
+ }
+ }
+ }
+ }
+
+
+ private String getContext(SMTPSession session, MailAddress recipientAddress, String recipient){
+ StringBuffer sb = new StringBuffer(128);
+ if(null!=recipientAddress) {
+ sb.append(" [to:" + (recipientAddress).toInternetAddress().getAddress() + "]");
+ } else if(null!=recipient) {
+ sb.append(" [to:" + recipient + "]");
+ }
+ if (null!=session.getState().get(SMTPSession.SENDER)) {
+ sb.append(" [from:" + ((MailAddress)session.getState().get(SMTPSession.SENDER)).toInternetAddress().getAddress() + "]");
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection implCommands = new ArrayList();
+ implCommands.add("RCPT");
+
+ return implCommands;
+ }
+
+
+ @Override
+ protected PostRcptListener getLastListener() {
+ return this;
+ }
+
+
+ public String onRcpt(SMTPSession session, MailAddress recipientAddress) {
+ String responseString = null;
+
+ session.getState().put(SMTPSession.CURRENT_RECIPIENT,recipientAddress);
+
+ StringBuffer responseBuffer = session.getResponseBuffer();
Collection rcptColl = (Collection) session.getState().get(
SMTPSession.RCPT_LIST);
if (rcptColl == null) {
rcptColl = new ArrayList();
}
- MailAddress recipientAddress = (MailAddress) session.getState().get(
- SMTPSession.CURRENT_RECIPIENT);
+
rcptColl.add(recipientAddress);
session.getState().put(SMTPSession.RCPT_LIST, rcptColl);
responseBuffer.append(
@@ -74,18 +311,7 @@
DSNStatus.ADDRESS_VALID) + " Recipient <")
.append(recipientAddress).append("> OK");
responseString = session.clearResponseBuffer();
- session.writeResponse(responseString);
-
- }
-
- /**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
- */
- public Collection getImplCommands() {
- Collection implCommands = new ArrayList();
- implCommands.add("RCPT");
-
- return implCommands;
- }
+ return responseString;
+ }
}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/SendMailHandler.java Fri Aug 7 14:11:31 2009
@@ -21,6 +21,7 @@
package org.apache.james.smtpserver.core;
+import org.apache.activemq.transport.stomp.Stomp.Responses;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -41,8 +42,8 @@
* Adds the header to the message
*/
public class SendMailHandler
- extends AbstractLogEnabled
- implements MessageHandler, Serviceable {
+ extends AbstractCmdHandler<PostDataListener>
+ implements MessageHandler, Serviceable,PostDataListener {
private MailServer mailServer;
@@ -58,67 +59,86 @@
* @see org.apache.james.smtpserver#onMessage(SMTPSession)
*/
public void onMessage(SMTPSession session) {
- getLogger().debug("sending mail");
-
+ String responseString = null;
+
Mail mail = session.getMail();
- String responseString = null;
- try {
- mailServer.sendMail(mail);
- Collection theRecipients = mail.getRecipients();
- String recipientString = "";
- if (theRecipients != null) {
- recipientString = theRecipients.toString();
- }
- if (getLogger().isInfoEnabled()) {
- StringBuffer infoBuffer =
- new StringBuffer(256)
- .append("Successfully spooled mail ")
- .append(mail.getName())
- .append(" from ")
- .append(mail.getSender())
- .append(" on ")
- .append(session.getRemoteIPAddress())
- .append(" for ")
- .append(recipientString);
- getLogger().info(infoBuffer.toString());
- }
- } catch (MessagingException me) {
- // Grab any exception attached to this one.
- Exception e = me.getNextException();
- // If there was an attached exception, and it's a
- // MessageSizeException
- if (e != null && e instanceof MessageSizeException) {
- // Add an item to the state to suppress
- // logging of extra lines of data
- // that are sent after the size limit has
- // been hit.
- session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
- // then let the client know that the size
- // limit has been hit.
- responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error processing message.";
- StringBuffer errorBuffer =
- new StringBuffer(256)
- .append("Rejected message from ")
- .append(session.getState().get(SMTPSession.SENDER).toString())
- .append(" from host ")
- .append(session.getRemoteHost())
- .append(" (")
- .append(session.getRemoteIPAddress())
- .append(") exceeding system maximum message size of ")
- .append(session.getConfigurationData().getMaxMessageSize());
- getLogger().error(errorBuffer.toString());
- } else {
- responseString = "451 "+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.";
- getLogger().error("Unknown error occurred while processing DATA.", me);
- }
- session.writeResponse(responseString);
- return;
- }
- responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received";
- session.writeResponse(responseString);
+ for (int i = 0; i < listeners.size(); i++) {
+ responseString = listeners.get(i).onData(session, mail);
+ if (responseString != null) {
+ session.abortMessage();
+ session.writeResponse(responseString);
+ session.setStopHandlerProcessing(true);
+ break;
+ }
+ }
}
+ @Override
+ protected PostDataListener getLastListener() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String onData(SMTPSession session, Mail mail) {
+ getLogger().debug("sending mail");
+
+ String responseString = null;
+ try {
+ mailServer.sendMail(mail);
+ Collection theRecipients = mail.getRecipients();
+ String recipientString = "";
+ if (theRecipients != null) {
+ recipientString = theRecipients.toString();
+ }
+ if (getLogger().isInfoEnabled()) {
+ StringBuffer infoBuffer =
+ new StringBuffer(256)
+ .append("Successfully spooled mail ")
+ .append(mail.getName())
+ .append(" from ")
+ .append(mail.getSender())
+ .append(" on ")
+ .append(session.getRemoteIPAddress())
+ .append(" for ")
+ .append(recipientString);
+ getLogger().info(infoBuffer.toString());
+ }
+ } catch (MessagingException me) {
+ // Grab any exception attached to this one.
+ Exception e = me.getNextException();
+ // If there was an attached exception, and it's a
+ // MessageSizeException
+ if (e != null && e instanceof MessageSizeException) {
+ // Add an item to the state to suppress
+ // logging of extra lines of data
+ // that are sent after the size limit has
+ // been hit.
+ session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
+ // then let the client know that the size
+ // limit has been hit.
+ responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error processing message.";
+ StringBuffer errorBuffer =
+ new StringBuffer(256)
+ .append("Rejected message from ")
+ .append(session.getState().get(SMTPSession.SENDER).toString())
+ .append(" from host ")
+ .append(session.getRemoteHost())
+ .append(" (")
+ .append(session.getRemoteIPAddress())
+ .append(") exceeding system maximum message size of ")
+ .append(session.getConfigurationData().getMaxMessageSize());
+ getLogger().error(errorBuffer.toString());
+ } else {
+ responseString = "451 "+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.";
+ getLogger().error("Unknown error occurred while processing DATA.", me);
+ }
+ return responseString;
+ }
+ responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received";
+ return responseString;
+ }
+
}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/DNSRBLHandler.java Fri Aug 7 14:11:31 2009
@@ -21,6 +21,7 @@
package org.apache.james.smtpserver.core.filter.fastfail;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
@@ -29,10 +30,9 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.dsn.DSNStatus;
-import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.ConnectHandler;
import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.smtpserver.junkscore.JunkScore;
+import org.apache.james.smtpserver.core.PostRcptListener;
import org.apache.mailet.MailAddress;
import java.util.ArrayList;
@@ -43,8 +43,8 @@
* Connect handler for DNSRBL processing
*/
public class DNSRBLHandler
- extends AbstractJunkHandler
- implements ConnectHandler, CommandHandler, Configurable, Serviceable {
+ extends AbstractLogEnabled
+ implements ConnectHandler, PostRcptListener, Configurable, Serviceable {
/**
* The lists of rbl servers to be checked to limit spam
*/
@@ -111,9 +111,7 @@
if(configuration != null) {
getDetail = configuration.getValueAsBoolean();
}
-
- super.configure(handlerConfiguration);
-
+
}
/**
@@ -129,55 +127,7 @@
* @see org.apache.james.smtpserver.ConnectHandler#onConnect(SMTPSession)
**/
public void onConnect(SMTPSession session) {
- checkDNSRBL(session, session.getRemoteIPAddress());
- }
-
- /**
- * Set the whitelist array
- *
- * @param whitelist The array which contains the whitelist
- */
- public void setWhitelist(String[] whitelist) {
- this.whitelist = whitelist;
- }
-
- /**
- * Set the blacklist array
- *
- * @param blacklist The array which contains the blacklist
- */
- public void setBlacklist(String[] blacklist) {
- this.blacklist = blacklist;
- }
-
- /**
- * Set the DNSService
- *
- * @param dnsServer The DNSService
- */
- public void setDNSServer(DNSService dnsServer) {
- this.dnsServer = dnsServer;
- }
-
- /**
- * Set for try to get a TXT record for the blocked record.
- *
- * @param getDetail Set to ture for enable
- */
- public void setGetDetail(boolean getDetail) {
- this.getDetail = getDetail;
- }
-
- /**
- *
- * This checks DNSRBL whitelists and blacklists. If the remote IP is whitelisted
- * it will be permitted to send e-mail, otherwise if the remote IP is blacklisted,
- * the sender will only be permitted to send e-mail to postmaster (RFC 2821) or
- * abuse (RFC 2142), unless authenticated.
- */
-
- public void checkDNSRBL(SMTPSession session, String ipAddress) {
-
+ String ipAddress = session.getRemoteIPAddress();
/*
* don't check against rbllists if the client is allowed to relay..
* This whould make no sense.
@@ -241,62 +191,64 @@
}
}
}
- }
- }
-
+ } }
+
/**
- * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ * Set the whitelist array
+ *
+ * @param whitelist The array which contains the whitelist
*/
- public Collection getImplCommands() {
- Collection commands = new ArrayList();
- commands.add("RCPT");
- return commands;
+ public void setWhitelist(String[] whitelist) {
+ this.whitelist = whitelist;
}
-
+
/**
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ * Set the blacklist array
+ *
+ * @param blacklist The array which contains the blacklist
*/
- public void onCommand(SMTPSession session) {
- doProcessing(session);
+ public void setBlacklist(String[] blacklist) {
+ this.blacklist = blacklist;
}
-
+
/**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#check(org.apache.james.smtpserver.SMTPSession)
+ * Set the DNSService
+ *
+ * @param dnsServer The DNSService
*/
- protected boolean check(SMTPSession session) {
- String blocklisted = (String) session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
- MailAddress recipientAddress = (MailAddress) session.getState().get(
- SMTPSession.CURRENT_RECIPIENT);
-
- return (blocklisted != null && // was found in the RBL
- !(session.isAuthRequired() && session.getUser() != null) && // Not (SMTP AUTH is enabled and not authenticated)
- !(recipientAddress.getUser().equalsIgnoreCase("postmaster") || recipientAddress.getUser().equalsIgnoreCase("abuse")));
+ public void setDNSServer(DNSService dnsServer) {
+ this.dnsServer = dnsServer;
}
/**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkScore(org.apache.james.smtpserver.SMTPSession)
+ * Set for try to get a TXT record for the blocked record.
+ *
+ * @param getDetail Set to ture for enable
*/
- protected JunkScore getJunkScore(SMTPSession session) {
- return (JunkScore) session.getConnectionState().get(JunkScore.JUNK_SCORE_SESSION);
+ public void setGetDetail(boolean getDetail) {
+ this.getDetail = getDetail;
}
+
- /**
- * @see org.apache.james.smtpserver.core.filter.fastfail.AbstractJunkHandler#getJunkHandlerData(org.apache.james.smtpserver.SMTPSession)
- */
- public JunkHandlerData getJunkHandlerData(SMTPSession session) {
- JunkHandlerData data = new JunkHandlerData();
-
- data.setJunkScoreLogString("Ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Add junkScore: " + getScore());
- data.setRejectLogString("ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Reject email");
-
- if (blocklistedDetail != null) {
- data.setRejectResponseString("530 "+ DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail);
- } else {
- data.setRejectResponseString("530 "+ DSNStatus.getStatus(DSNStatus.PERMANENT,
- DSNStatus.SECURITY_AUTH) + " Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress()
- + " is restricted. Contact the postmaster for details.");
- }
- data.setScoreName("DNSRBLCheck");
- return data;
- }
+ /*
+ * *(non-Javadoc)
+ * @see org.apache.james.smtpserver.core.PostRcptListener#onRcpt(org.apache.james.smtpserver.SMTPSession, org.apache.mailet.MailAddress)
+ */
+ public String onRcpt(SMTPSession session, MailAddress recipientAddress) {
+ String blocklisted = (String) session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
+
+ if (blocklisted != null && // was found in the RBL
+ !(session.isAuthRequired() && session.getUser() != null) && // Not (SMTP AUTH is enabled and not authenticated)
+ !(recipientAddress.getLocalPart().equalsIgnoreCase("postmaster") || recipientAddress.getLocalPart().equalsIgnoreCase("abuse"))) {
+ getLogger().info("ipaddress " + session.getRemoteIPAddress() + " listed on RBL. Reject email");
+ if (blocklistedDetail != null) {
+ return "530 "+ DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH) + " " + blocklistedDetail;
+ } else {
+ return "530 "+ DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.SECURITY_AUTH) + " Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress()
+ + " is restricted. Contact the postmaster for details.";
+ }
+ }
+ return null;
+ }
}
Modified: james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java?rev=802017&r1=802016&r2=802017&view=diff
==============================================================================
--- james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java (original)
+++ james/server/sandbox/active/smtp_refactor/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java Fri Aug 7 14:11:31 2009
@@ -48,8 +48,8 @@
import org.apache.james.api.dnsservice.util.NetMatcher;
import org.apache.james.dsn.DSNStatus;
import org.apache.james.services.FileSystem;
-import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.smtpserver.core.PostRcptListener;
import org.apache.james.util.TimeConverter;
import org.apache.james.util.sql.JDBCUtil;
import org.apache.james.util.sql.SqlResources;
@@ -59,7 +59,7 @@
* GreylistHandler which can be used to activate Greylisting
*/
public class GreylistHandler extends AbstractLogEnabled implements
- CommandHandler, Configurable, Serviceable, Initializable {
+ PostRcptListener, Configurable, Serviceable, Initializable {
private DataSourceSelector datasources = null;
@@ -285,108 +285,6 @@
}
/**
- * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
- */
- public void onCommand(SMTPSession session) {
- if (!session.isRelayingAllowed() && !(session.isAuthRequired() && session.getUser() != null)) {
-
- if ((wNetworks == null) || (!wNetworks.matchInetNetwork(session.getRemoteIPAddress()))) {
- doGreyListCheck(session, session.getCommandArgument());
- } else {
- getLogger().info("IpAddress " + session.getRemoteIPAddress() + " is whitelisted. Skip greylisting.");
- }
- } else {
- getLogger().info("IpAddress " + session.getRemoteIPAddress() + " is allowed to send. Skip greylisting.");
- }
- }
-
- /**
- * Handler method called upon receipt of a RCPT command. Calls a greylist
- * check
- *
- *
- * @param session
- * SMTP session object
- * @param argument
- */
- private void doGreyListCheck(SMTPSession session, String argument) {
- String recip = "";
- String sender = "";
- MailAddress recipAddress = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
- MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
-
- if (recipAddress != null) recip = recipAddress.toString();
- if (senderAddress != null) sender = senderAddress.toString();
-
- long time = System.currentTimeMillis();
- String ipAddress = session.getRemoteIPAddress();
-
- try {
- long createTimeStamp = 0;
- int count = 0;
-
- // get the timestamp when he triplet was last seen
- Iterator data = getGreyListData(datasource.getConnection(), ipAddress, sender, recip);
-
- if (data.hasNext()) {
- createTimeStamp = Long.parseLong(data.next().toString());
- count = Integer.parseInt(data.next().toString());
- }
-
- getLogger().debug("Triplet " + ipAddress + " | " + sender + " | " + recip +" -> TimeStamp: " + createTimeStamp);
-
-
- // if the timestamp is bigger as 0 we have allready a triplet stored
- if (createTimeStamp > 0) {
- long acceptTime = createTimeStamp + tempBlockTime;
-
- if ((time < acceptTime) && (count == 0)) {
- String responseString = "451 " + DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER)
- + " Temporary rejected: Reconnect to fast. Please try again later";
-
- // reconnect to fast block it again
- session.writeResponse(responseString);
- session.setStopHandlerProcessing(true);
-
- } else {
-
- getLogger().debug("Update triplet " + ipAddress + " | " + sender + " | " + recip + " -> timestamp: " + time);
-
- // update the triplet..
- updateTriplet(datasource.getConnection(), ipAddress, sender, recip, count, time);
-
- }
- } else {
- getLogger().debug("New triplet " + ipAddress + " | " + sender + " | " + recip );
-
- // insert a new triplet
- insertTriplet(datasource.getConnection(), ipAddress, sender, recip, count, time);
-
- // Tempory block on new triplet!
- String responseString = "451 " + DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER)
- + " Temporary rejected: Please try again later";
-
- session.writeResponse(responseString);
- session.setStopHandlerProcessing(true);
- }
-
- // some kind of random cleanup process
- if (Math.random() > 0.99) {
- // cleanup old entries
-
- getLogger().debug("Delete old entries");
-
- cleanupAutoWhiteListGreyList(datasource.getConnection(),(time - autoWhiteListLifeTime));
- cleanupGreyList(datasource.getConnection(), (time - unseenLifeTime));
- }
-
- } catch (SQLException e) {
- // just log the exception
- getLogger().error("Error on SQLquery: " + e.getMessage());
- }
- }
-
- /**
* Get all necessary data for greylisting based on provided triplet
*
* @param conn
@@ -678,9 +576,82 @@
return wNetworks;
}
- public Collection getImplCommands() {
- Collection c = new ArrayList();
- c.add("RCPT");
- return c;
- }
+ public String onRcpt(SMTPSession session, MailAddress recipAddress) {
+
+ //whitelisted
+ if ((wNetworks != null) &&!wNetworks.matchInetNetwork(session.getRemoteIPAddress())) {
+ return null;
+ }
+
+ String responseString = null;
+ String recip = "";
+ String sender = "";
+ MailAddress senderAddress = (MailAddress) session.getState().get(SMTPSession.SENDER);
+
+ if (recipAddress != null) recip = recipAddress.toString();
+ if (senderAddress != null) sender = senderAddress.toString();
+
+ long time = System.currentTimeMillis();
+ String ipAddress = session.getRemoteIPAddress();
+
+ try {
+ long createTimeStamp = 0;
+ int count = 0;
+
+ // get the timestamp when he triplet was last seen
+ Iterator data = getGreyListData(datasource.getConnection(), ipAddress, sender, recip);
+
+ if (data.hasNext()) {
+ createTimeStamp = Long.parseLong(data.next().toString());
+ count = Integer.parseInt(data.next().toString());
+ }
+
+ getLogger().debug("Triplet " + ipAddress + " | " + sender + " | " + recip +" -> TimeStamp: " + createTimeStamp);
+
+
+ // if the timestamp is bigger as 0 we have allready a triplet stored
+ if (createTimeStamp > 0) {
+ long acceptTime = createTimeStamp + tempBlockTime;
+
+ if ((time < acceptTime) && (count == 0)) {
+ responseString = "451 " + DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.NETWORK_DIR_SERVER)
+ + " Temporary rejected: Reconnect to fast. Please try again later";
+
+ // reconnect to fast block it again
+
+ } else {
+
+ getLogger().debug("Update triplet " + ipAddress + " | " + sender + " | " + recip + " -> timestamp: " + time);
+
+ // update the triplet..
+ updateTriplet(datasource.getConnection(), ipAddress, sender, recip, count, time);
+
+ }
+ } else {
+ getLogger().debug("New triplet " + ipAddress + " | " + sender + " | " + recip );
+
+ // insert a new triplet
+ insertTriplet(datasource.getConnection(), ipAddress, sender, recip, count, time);
+
+ // Tempory block on new triplet!
+
+ }
+
+ // some kind of random cleanup process
+ if (Math.random() > 0.99) {
+ // cleanup old entries
+
+ getLogger().debug("Delete old entries");
+
+ cleanupAutoWhiteListGreyList(datasource.getConnection(),(time - autoWhiteListLifeTime));
+ cleanupGreyList(datasource.getConnection(), (time - unseenLifeTime));
+ }
+ return responseString;
+
+ } catch (SQLException e) {
+ // just log the exception
+ getLogger().error("Error on SQLquery: " + e.getMessage());
+ }
+ return null;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org