Author: norman
Date: Tue Jul 18 06:41:43 2006
New Revision: 423084
URL: http://svn.apache.org/viewvc?rev=423084&view=rev
Log:
Add SPF support. See JAMES-481
Add new State map wich can be used to store object which should be valid till
the whole connection
Added:
james/server/trunk/lib/jspf-0.9b1.jar (with props)
james/server/trunk/lib/log4j-1.2.13.jar (with props)
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
Modified:
james/server/trunk/build.xml
james/server/trunk/include.properties
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/DNSRBLHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
james/server/trunk/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
Modified: james/server/trunk/build.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/build.xml?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
--- james/server/trunk/build.xml (original)
+++ james/server/trunk/build.xml Tue Jul 18 06:41:43 2006
@@ -90,6 +90,8 @@
<include name="${javax-activation.jar}"/>
<include name="${bcmail.jar}"/>
<include name="${bcmail-workaround.jar}"/>
+ <include name="${jspf.jar}"/>
+ <include name="${log4j.jar}"/>
</fileset>
<pathelement path="${java.class.path}" />
<pathelement path="${build.classes}" />
@@ -524,6 +526,8 @@
<include name="${cornerstone-datasources-api.jar}"/>
<include name="${cornerstone-datasources-impl.jar}"/>
<include name="${concurrent.jar}"/>
+ <include name="${jspf.jar}"/>
+ <include name="${log4j.jar}"/>
</lib>
<zipfileset dir="${conf.dir}" fullpath="conf/sqlResources.xml">
<include name="sqlResources.xml"/>
Modified: james/server/trunk/include.properties
URL:
http://svn.apache.org/viewvc/james/server/trunk/include.properties?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
--- james/server/trunk/include.properties (original)
+++ james/server/trunk/include.properties Tue Jul 18 06:41:43 2006
@@ -90,3 +90,11 @@
bcmail.jar=bcmail-jdk14-129.jar
bcmail-workaround.jar=bcmail-jdk14-129-workaround.jar
+
+# ----- jSPF -----
+jspf.jar=jspf-0.9b1.jar
+
+# ----- Log4J-----
+log4j.jar=log4j-1.2.13.jar
+
+
Added: james/server/trunk/lib/jspf-0.9b1.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/jspf-0.9b1.jar?rev=423084&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/jspf-0.9b1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: james/server/trunk/lib/log4j-1.2.13.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/lib/log4j-1.2.13.jar?rev=423084&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/log4j-1.2.13.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: james/server/trunk/src/conf/james-config.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Tue Jul 18 06:41:43 2006
@@ -931,6 +931,15 @@
<blacklist> relays.ordb.org </blacklist>
</rblservers>
</handler>
+ -->
+ <!-- This command handler can be used to reject emails with not
match the SPF record of the sender domain -->
+ <!-- If checkAuthNetworks is set to true sender domain will be
checked also for clients that -->
+ <!-- are allowed to relay. Default is false. -->
+ <!--
+ <handler class="org.apache.james.smtpserver.core.filter.fastfail"
command="MAIL,RCPT">
+ <checkAuthClients> false </checkAuthClients>
+ <blockSoftFail> false </blockSoftFail>
+ </handler>
-->
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPHandler.java
Tue Jul 18 06:41:43 2006
@@ -120,15 +120,6 @@
*/
private boolean heloEhloEnforcement;
- /**
- * TEMPORARY: is the sending address blocklisted
- */
- private boolean blocklisted;
-
- /**
- * The blocklisted detail
- */
- private String blocklistedDetail = null;
/**
* The SMTPGreeting
@@ -155,6 +146,11 @@
private HashMap state = new HashMap();
/**
+ * The hash map holds states which should be used in the whole connection
+ */
+ private HashMap connectionState = new HashMap();
+
+ /**
* The per-handler response buffer used to marshal responses.
*/
private StringBuffer responseBuffer = new StringBuffer(256);
@@ -185,6 +181,7 @@
sessionEnded = false;
smtpGreeting = theConfigData.getSMTPGreeting();
resetState();
+ resetConnectionState();
// if no greeting was configured use a default
if (smtpGreeting == null) {
@@ -323,6 +320,7 @@
*/
protected void resetHandler() {
resetState();
+ resetConnectionState();
clearResponseBuffer();
@@ -555,6 +553,14 @@
*/
public boolean getStopHandlerProcessing() {
return stopHandlerProcessing;
+ }
+
+ public void resetConnectionState() {
+ connectionState.clear();
+ }
+
+ public HashMap getConnectionState() {
+ return connectionState;
}
}
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
(original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/SMTPSession.java
Tue Jul 18 06:41:43 2006
@@ -37,6 +37,7 @@
public final static String SENDER = "SENDER_ADDRESS"; // Sender's
email address
public final static String RCPT_LIST = "RCPT_LIST"; // The message
recipients
public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; //
HELO or EHLO
+ public final static String CURRENT_HELO_NAME = "CURRENT_HELO_NAME";
public static final Object CURRENT_RECIPIENT = "CURRENT_RECIPIENT"; //
Current recipient
/**
@@ -139,9 +140,9 @@
boolean isSessionEnded();
/**
- * Returns Map that consists of the state of the SMTPSession
+ * Returns Map that consists of the state of the SMTPSession per mail
*
- * @return map of the current SMTPSession state
+ * @return map of the current SMTPSession state per mail
*/
HashMap getState();
@@ -227,6 +228,19 @@
* @return true or false
*/
boolean getStopHandlerProcessing();
+
+
+ /**
+ * Reset the Connection state
+ */
+ void resetConnectionState();
+
+ /**
+ * Returns Map that consists of the state of the SMTPSession per connection
+ *
+ * @return map of the current SMTPSession state per connection
+ */
+ HashMap getConnectionState();
}
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/DNSRBLHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/DNSRBLHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/DNSRBLHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/DNSRBLHandler.java
Tue Jul 18 06:41:43 2006
@@ -172,7 +172,7 @@
*/
if (session.isRelayingAllowed()) {
getLogger().info("Ipaddress " + session.getRemoteIPAddress() + "
is allowed to relay. Don't check it");
- session.getState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
"false");
+
session.getConnectionState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "false");
return;
}
@@ -192,7 +192,7 @@
getLogger().info("Connection from " + ipAddress + "
whitelisted by " + rblList[i]);
}
-
session.getState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "false");
+
session.getConnectionState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "false");
return;
} catch (java.net.UnknownHostException uhe) {
if (getLogger().isInfoEnabled()) {
@@ -218,11 +218,11 @@
// Set the detail
String blocklistedDetail =
txt.iterator().next().toString();
-
session.getState().put(RBL_DETAIL_MAIL_ATTRIBUTE_NAME, blocklistedDetail);
+
session.getConnectionState().put(RBL_DETAIL_MAIL_ATTRIBUTE_NAME,
blocklistedDetail);
}
}
-
session.getState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "true");
+
session.getConnectionState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "true");
return;
} catch (java.net.UnknownHostException uhe) {
// if it is unknown, it isn't blocked
@@ -233,7 +233,7 @@
}
}
// default state
- session.getState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME, "false");
+ session.getConnectionState().put(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME,
"false");
}
/**
@@ -250,12 +250,12 @@
*/
public void onCommand(SMTPSession session) {
String responseString = null;
- String blocklisted = (String)
session.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
+ String blocklisted = (String)
session.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME);
MailAddress recipientAddress = (MailAddress) session.getState().get(
SMTPSession.CURRENT_RECIPIENT);
if (blocklisted.equals("true") && // was found in the RBL
- !(session.isRelayingAllowed() || (session.isAuthRequired() &&
session
+ ((session.isAuthRequired() && session
.getUser() != null)) && // Not (either an authorized IP
// or (SMTP AUTH is enabled and
// not authenticated))
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/EhloCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -55,8 +55,7 @@
private void doEHLO(SMTPSession session, String argument) {
StringBuffer responseBuffer = session.getResponseBuffer();
- session.resetState();
- session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
+ session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE,
COMMAND_NAME);
ArrayList esmtpextensions = new ArrayList();
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/HeloCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -52,8 +52,7 @@
private void doHELO(SMTPSession session, String argument) {
String responseString = null;
- session.resetState();
- session.getState().put(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME);
+ session.getConnectionState().put(SMTPSession.CURRENT_HELO_MODE,
COMMAND_NAME);
session.getResponseBuffer().append("250 ").append(
session.getConfigurationData().getHelloName())
.append(" Hello ").append(argument).append(" (").append(
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/RsetCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -53,13 +53,9 @@
private void doRSET(SMTPSession session, String argument) {
String responseString = "";
if ((argument == null) || (argument.length() == 0)) {
- // remember the ehlo mode
- Object currentHeloMode =
session.getState().get(SMTPSession.CURRENT_HELO_MODE);
+
session.resetState();
- // start again with the old helo mode
- if (currentHeloMode != null) {
-
session.getState().put(SMTPSession.CURRENT_HELO_MODE,currentHeloMode);
- }
+
responseString = "250
"+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.UNDEFINED_STATUS)+" OK";
} else {
responseString = "500
"+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.DELIVERY_INVALID_ARG)+"
Unexpected argument provided with RSET command";
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/EhloFilterCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -51,12 +51,17 @@
private void doEHLO(SMTPSession session, String argument) {
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 {
+ // store provided name
+ session.getState().put(SMTPSession.CURRENT_HELO_NAME,argument);
}
}
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/HeloFilterCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -50,7 +50,9 @@
* @param argument the argument passed in with the command by the SMTP
client
*/
private void doHELO(SMTPSession session, String argument) {
- String responseString = null;
+ String responseString = null;
+
+ session.resetState();
if (argument == null) {
responseString = "501 Domain address required: " + COMMAND_NAME;
@@ -60,6 +62,9 @@
// After this filter match we should not call any other handler!
session.setStopHandlerProcessing(true);
+ } else {
+ // store provided name
+ session.getState().put(SMTPSession.CURRENT_HELO_NAME,argument);
}
}
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
(original)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/MailFilterCmdHandler.java
Tue Jul 18 06:41:43 2006
@@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
@@ -70,7 +69,7 @@
// After this filter match we should not call any other handler!
session.setStopHandlerProcessing(true);
- } else if
(!session.getState().containsKey(SMTPSession.CURRENT_HELO_MODE) &&
session.useHeloEhloEnforcement()) {
+ } 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);
Added:
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=423084&view=auto
==============================================================================
---
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
(added)
+++
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
Tue Jul 18 06:41:43 2006
@@ -0,0 +1,271 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.filter.fastfail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.jspf.SPF;
+import org.apache.james.jspf.SPF1Utils;
+import org.apache.james.jspf.SPFResult;
+import org.apache.james.jspf.core.DNSService;
+import org.apache.james.smtpserver.CommandHandler;
+import org.apache.james.smtpserver.MessageHandler;
+import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+/**
+ * SPFHandler which could be used to reject mail based on spf. The Following
attributes
+ *
+ * org.apache.james.smtpserver.spf.header - Holds the header which can be
attached later
+ *
+ * Sample Configuration: <br>
+ * <br>
+ * <handler class="org.apache.james.smtpserver.core.SPFHandler"
+ * command="MAIL,RCPT"> <blockSoftFail>false</blockSoftFail>
+ * </handler>
+ */
+public class SPFHandler extends AbstractLogEnabled implements CommandHandler,
+ MessageHandler, Configurable {
+
+ public static final String SPF_BLOCKLISTED = "SPF_BLOCKLISTED";
+
+ public static final String SPF_DETAIL = "SPF_DETAIL";
+
+ public static final String SPF_TEMPBLOCKLISTED = "SPF_TEMPBLOCKLISTED";
+
+ public final static String SPF_HEADER = "SPF_HEADER";
+
+ public final static String SPF_HEADER_MAIL_ATTRIBUTE_NAME =
"org.apache.james.spf.header";
+
+ /**
+ * If set to true the mail will also be rejected on a softfail
+ */
+ private boolean blockSoftFail = false;
+
+ private DNSService dnsService = null;
+
+ private boolean checkAuthNetworks = false;
+
+ /**
+ * @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure(Configuration handlerConfiguration)
+ throws ConfigurationException {
+ Configuration configuration = handlerConfiguration.getChild(
+ "blockSoftFail", false);
+ if (configuration != null) {
+ setBlockSoftFail(configuration.getValueAsBoolean(false));
+ }
+ Configuration configRelay = handlerConfiguration.getChild(
+ "checkAuthNetworks", false);
+ if (configRelay != null) {
+ setCheckAuthNetworks(configRelay.getValueAsBoolean(false));
+ }
+
+ }
+
+ /**
+ * block the email on a softfail
+ *
+ * @param blockSoftFail
+ * true or false
+ */
+ public void setBlockSoftFail(boolean blockSoftFail) {
+ this.blockSoftFail = blockSoftFail;
+ }
+
+ /**
+ * DNSService to use
+ *
+ * @param dnsService The DNSService
+ */
+ public void setDNSService(DNSService dnsService) {
+ this.dnsService = dnsService;
+ }
+
+ /**
+ * Set to true if AuthNetworks should be included in the EHLO check
+ *
+ * @param checkAuthNetworks
+ * Set to true to enable
+ */
+ public void setCheckAuthNetworks(boolean checkAuthNetworks) {
+ this.checkAuthNetworks = checkAuthNetworks;
+ }
+
+ /**
+ * Calls the SPFcheck
+ *
+ * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+ */
+ public void onCommand(SMTPSession session) {
+ if (session.getCommandName().equals("MAIL")) {
+ doSPFCheck(session);
+ } else if (session.getCommandName().equals("RCPT")) {
+ rejectSession(session);
+
+ }
+ }
+
+ /**
+ * Calls a SPF check
+ *
+ * @param session
+ * SMTP session object
+ */
+ private void doSPFCheck(SMTPSession session) {
+
+ MailAddress sender = (MailAddress) session.getState().get(
+ SMTPSession.SENDER);
+ String heloEhlo = (String) session.getState().get(
+ SMTPSession.CURRENT_HELO_NAME);
+
+ // We have no Sender or HELO/EHLO yet return false
+ if (sender == null || heloEhlo == null) {
+ getLogger().info("No Sender or HELO present");
+ System.out.println("sender: " + sender + " helo: " + heloEhlo);
+ } else {
+ // No checks for authorized cliends
+ if (session.isRelayingAllowed() && checkAuthNetworks == false) {
+ getLogger().info(
+ "Ipaddress " + session.getRemoteIPAddress()
+ + " is allowed to relay. Don't check it");
+ } else {
+
+ SPF spf;
+
+ String ip = session.getRemoteIPAddress();
+ if (dnsService == null) {
+ spf = new SPF();
+ } else {
+ spf = new SPF(dnsService);
+ }
+
+ SPFResult result = spf
+ .checkSPF(ip, sender.toString(), heloEhlo);
+
+ String spfResult = result.getResult();
+
+ String explanation = "Blocked - see: "
+ + result.getExplanation();
+
+ // Store the header
+ session.getState().put(SPF_HEADER, result.getHeaderText());
+
+ getLogger().info(
+ "Result for " + ip + " - " + sender + " - " + heloEhlo
+ + " = " + spfResult);
+
+ // Check if we should block!
+ if ((spfResult.equals(SPF1Utils.FAIL_CONV))
+ || (spfResult.equals(SPF1Utils.SOFTFAIL_CONV) &&
blockSoftFail)
+ || spfResult.equals(SPF1Utils.PERM_ERROR_CONV)) {
+
+ if (spfResult.equals(SPF1Utils.PERM_ERROR)) {
+ explanation = "Blocked caused by an invalid SPF
record";
+ }
+ session.getState().put(SPF_DETAIL, explanation);
+ session.getState().put(SPF_BLOCKLISTED, "true");
+
+ } else if (spfResult.equals(SPF1Utils.TEMP_ERROR_CONV)) {
+ session.getState().put(SPF_TEMPBLOCKLISTED, "true");
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Reject the session with the right responseCode
+ *
+ * @param session
+ * The SMTPSession
+ */
+ private void rejectSession(SMTPSession session) {
+ MailAddress recipientAddress = (MailAddress) session.getState().get(
+ SMTPSession.CURRENT_RECIPIENT);
+ String blocklisted = (String) session.getState().get(SPF_BLOCKLISTED);
+ String blocklistedDetail = (String) session.getState().get(SPF_DETAIL);
+ String tempBlocklisted = (String) session.getState().get(
+ SPF_TEMPBLOCKLISTED);
+
+ // Check if the recipient is postmaster or abuse..
+ if (recipientAddress != null
+ && (recipientAddress.getUser().equalsIgnoreCase("postmaster")
+ ||
recipientAddress.getUser().equalsIgnoreCase("abuse") || ((session
+ .isAuthRequired() && session.getUser() != null)))) {
+ System.out.println("HERE2 " + blocklisted);
+ //remove invalid data
+ session.getState().remove(SPF_BLOCKLISTED);
+ session.getState().remove(SPF_DETAIL);
+ session.getState().remove(SPF_TEMPBLOCKLISTED);
+ session.getState().remove(SPF_HEADER);
+ } else {
+ // Check if session is blocklisted
+ if (blocklisted != null && blocklisted.equals("true")) {
+
+ String responseString = "530 "
+ + DSNStatus.getStatus(DSNStatus.PERMANENT,
+ DSNStatus.SECURITY_AUTH) + " "
+ + blocklistedDetail;
+ session.writeResponse(responseString);
+
+ session.setStopHandlerProcessing(true);
+
+ } else if (tempBlocklisted != null
+ && tempBlocklisted.equals("true")) {
+ String responseString = "451 "
+ + DSNStatus.getStatus(DSNStatus.TRANSIENT,
+ DSNStatus.NETWORK_DIR_SERVER) + " "
+ + "Temporary rejected: Problem on SPF lookup";
+ session.writeResponse(responseString);
+ session.setStopHandlerProcessing(true);
+ }
+ }
+
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+ */
+ public Collection getImplCommands() {
+ Collection commands = new ArrayList();
+ commands.add("MAIL");
+ commands.add("RCPT");
+
+ return commands;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.MessageHandler#onMessage(SMTPSession)
+ */
+ public void onMessage(SMTPSession session) {
+ Mail mail = session.getMail();
+
+ // Store the spf header as attribute for later using
+ mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session
+ .getState().get(SPF_HEADER));
+ }
+}
Modified:
james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
(original)
+++
james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
Tue Jul 18 06:41:43 2006
@@ -126,6 +126,8 @@
private void setupMockedSMTPSession() {
mockedSMTPSession = new SMTPSession() {
HashMap state = new HashMap();
+ HashMap connectionState = new HashMap();
+ boolean stopHandler = false;
public void writeResponse(String respString) {
throw new UnsupportedOperationException(
@@ -249,13 +251,19 @@
}
public void setStopHandlerProcessing(boolean b) {
- // TODO Auto-generated method stub
-
+ stopHandler = b;
}
public boolean getStopHandlerProcessing() {
- // TODO Auto-generated method stub
- return false;
+ return stopHandler;
+ }
+
+ public HashMap getConnectionState() {
+ return connectionState;
+ }
+
+ public void resetConnectionState() {
+ connectionState.clear();
}
};
@@ -274,8 +282,8 @@
rbl.setGetDetail(true);
rbl.onConnect(mockedSMTPSession);
assertEquals("Blocked - see http://www.spamcop.net/bl.shtml?127.0.0.2",
-
mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("true",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("true",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
// ip is blacklisted and has txt details but we don'T want to retrieve the
txt record
@@ -290,8 +298,8 @@
rbl.setBlacklist(new String[] { "bl.spamcop.net" });
rbl.setGetDetail(false);
rbl.onConnect(mockedSMTPSession);
-
assertNull(mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("true",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
assertNull(mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("true",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
// ip is allowed to relay
@@ -308,8 +316,8 @@
rbl.setBlacklist(new String[] { "bl.spamcop.net" });
rbl.setGetDetail(true);
rbl.onConnect(mockedSMTPSession);
-
assertNull(mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("false",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
assertNull(mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("false",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
// ip not on blacklist
@@ -325,8 +333,8 @@
rbl.setBlacklist(new String[] { "bl.spamcop.net" });
rbl.setGetDetail(true);
rbl.onConnect(mockedSMTPSession);
-
assertNull(mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("false",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
assertNull(mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("false",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
// ip on blacklist without txt details
@@ -342,8 +350,8 @@
rbl.setBlacklist(new String[] { "bl.spamcop.net" });
rbl.setGetDetail(true);
rbl.onConnect(mockedSMTPSession);
-
assertNull(mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("true",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
assertNull(mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("true",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
// ip on whitelist
@@ -359,8 +367,8 @@
rbl.setWhitelist(new String[] { "bl.spamcop.net" });
rbl.setGetDetail(true);
rbl.onConnect(mockedSMTPSession);
-
assertNull(mockedSMTPSession.getState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
-
assertEquals("false",mockedSMTPSession.getState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
+
assertNull(mockedSMTPSession.getConnectionState().get(RBL_DETAIL_MAIL_ATTRIBUTE_NAME));
+
assertEquals("false",mockedSMTPSession.getConnectionState().get(RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME));
}
}
Added:
james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java?rev=423084&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
(added)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
Tue Jul 18 06:41:43 2006
@@ -0,0 +1,534 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.util.HashMap;
+
+import java.util.List;
+
+import javax.mail.internet.ParseException;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.exceptions.NoneException;
+import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.exceptions.TempErrorException;
+import org.apache.james.smtpserver.core.filter.fastfail.SPFHandler;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.james.util.watchdog.Watchdog;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+import junit.framework.TestCase;
+
+public class SPFHandlerTest extends TestCase {
+
+ private DNSService mockedDnsService;
+
+ private SMTPSession mockedSMTPSession;;
+
+ private boolean relaying = false;
+
+ private String command = "MAIL";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ setupMockedDnsService();
+ setRelayingAllowed(false);
+ }
+
+ /**
+ * Set relayingAllowed
+ *
+ * @param relaying
+ * true or false
+ */
+ private void setRelayingAllowed(boolean relaying) {
+ this.relaying = relaying;
+ }
+
+ /**
+ * Setup the mocked dnsserver
+ *
+ */
+ private void setupMockedDnsService() {
+ mockedDnsService = new DNSService() {
+
+ public List getAAAARecords(String arg0, int arg1)
+ throws NoneException, PermErrorException,
+ TempErrorException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public List getARecords(String arg0, int arg1)
+ throws NoneException, PermErrorException,
+ TempErrorException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public List getLocalDomainNames() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public List getMXRecords(String arg0, int arg1)
+ throws PermErrorException, NoneException,
+ TempErrorException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public List getPTRRecords(String arg0) throws PermErrorException,
+ NoneException, TempErrorException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getSpfRecord(String host, String version)
+ throws PermErrorException, NoneException,
+ TempErrorException {
+ if (host.equals("spf1.james.apache.org")) {
+ // pass
+ return "v=spf1 +all";
+ } else if (host.equals("spf2.james.apache.org")) {
+ // fail
+ return "v=spf1 -all";
+ } else if (host.equals("spf3.james.apache.org")) {
+ // softfail
+ return "v=spf1 ~all";
+ } else if (host.equals("spf4.james.apache.org")) {
+ // permerror
+ throw new PermErrorException("junit permerror test");
+ } else if (host.equals("spf5.james.apache.org")) {
+ throw new TempErrorException("junit temperror test");
+ } else {
+ throw new NoneException("junit noneerror test");
+ }
+ }
+
+ public String getTxtCatType(String arg0) throws NoneException,
+ PermErrorException, TempErrorException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void setTimeOut(int arg0) {
+ // do nothing
+ }
+
+ };
+ }
+
+ private void setCommand(String command) {
+ this.command = command;
+ }
+
+ /**
+ * Setup mocked smtpsession
+ */
+ private void setupMockedSMTPSession(final String ip, final String helo,
+ final MailAddress sender, final MailAddress recipient) {
+ mockedSMTPSession = new SMTPSession() {
+ HashMap state = new HashMap();
+
+ HashMap connectionState = new HashMap();
+
+ Mail mail = new MockMail();
+
+ boolean stopHandler = false;
+
+ public void writeResponse(String respString) {
+ // Do nothing
+ }
+
+ public String readCommandLine() throws IOException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public StringBuffer getResponseBuffer() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String clearResponseBuffer() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public InputStream getInputStream() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getCommandName() {
+ return command;
+ }
+
+ public String getCommandArgument() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public Mail getMail() {
+ return mail;
+ }
+
+ public void setMail(Mail mail) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getRemoteHost() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getRemoteIPAddress() {
+ return ip;
+ }
+
+ public void abortMessage() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void endSession() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean isSessionEnded() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public HashMap getState() {
+ state.put(SMTPSession.CURRENT_HELO_NAME, helo);
+ state.put(SMTPSession.SENDER, sender);
+ state.put(SMTPSession.CURRENT_RECIPIENT, recipient);
+ return state;
+ }
+
+ public void resetState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public SMTPHandlerConfigurationData getConfigurationData() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean isRelayingAllowed() {
+ return relaying;
+ }
+
+ public boolean isAuthRequired() {
+ return false;
+ }
+
+ public boolean useHeloEhloEnforcement() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getUser() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void setUser(String user) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public Watchdog getWatchdog() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getSessionID() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public int getRcptCount() {
+ return 0;
+ }
+
+ public void setStopHandlerProcessing(boolean b) {
+ stopHandler = b;
+ }
+
+ public boolean getStopHandlerProcessing() {
+ return stopHandler;
+ }
+
+ public HashMap getConnectionState() {
+ return connectionState;
+ }
+
+ public void resetConnectionState() {
+ connectionState.clear();
+ }
+
+ };
+ }
+
+ private void runHandlers(SPFHandler spf, SMTPSession mockedSMTPSession) {
+
+ setCommand("MAIL");
+ spf.onCommand(mockedSMTPSession);
+
+ setCommand("RCPT");
+ spf.onCommand(mockedSMTPSession);
+
+ spf.onMessage(mockedSMTPSession);
+ }
+
+ public void testSPFpass() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("Not reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("Not blocked so no details", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertEquals("header", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
+ .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
+ assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFfail() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNotNull("reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNotNull("blocked", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertTrue(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFsoftFail() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("not reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("no details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertEquals("header", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
+ .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
+ assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFsoftFailRejectEnabled() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+ spf.setBlockSoftFail(true);
+
+ setCommand("MAIL");
+ spf.onCommand(mockedSMTPSession);
+
+ setCommand("RCPT");
+ spf.onCommand(mockedSMTPSession);
+
+ assertNotNull("reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNotNull("details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertTrue(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFpermError() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+ spf.setBlockSoftFail(true);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNotNull("reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNotNull("details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertTrue(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFtempError() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("no reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("no details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNotNull("tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertTrue(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFNoRecord() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("no reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("no details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("no tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNotNull("Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertEquals("header", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_HEADER), mockedSMTPSession.getMail()
+ .getAttribute(SPFHandler.SPF_HEADER_MAIL_ATTRIBUTE_NAME));
+ assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFpermErrorNotRejectPostmaster() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+ spf.setBlockSoftFail(true);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("not reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("no details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNull("no Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+ }
+
+ public void testSPFpermErrorNotRejectAbuse() throws ParseException {
+ setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
+ new MailAddress("[EMAIL PROTECTED]"), new MailAddress(
+ "[EMAIL PROTECTED]"));
+ SPFHandler spf = new SPFHandler();
+
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.setDNSService(mockedDnsService);
+ spf.setBlockSoftFail(true);
+
+ runHandlers(spf, mockedSMTPSession);
+
+ assertNull("not reject", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_BLOCKLISTED));
+ assertNull("no details ", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_DETAIL));
+ assertNull("No tempError", mockedSMTPSession.getState().get(
+ SPFHandler.SPF_TEMPBLOCKLISTED));
+ assertNull("no Header should present", mockedSMTPSession.getState()
+ .get(SPFHandler.SPF_HEADER));
+ assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+ }
+}
Modified:
james/server/trunk/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java?rev=423084&r1=423083&r2=423084&view=diff
==============================================================================
---
james/server/trunk/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
(original)
+++
james/server/trunk/src/test/org/apache/james/smtpserver/SetMimeHeaderHandlerTest.java
Tue Jul 18 06:41:43 2006
@@ -212,13 +212,23 @@
}
public void setStopHandlerProcessing(boolean b) {
- // TODO Auto-generated method stub
-
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
}
public boolean getStopHandlerProcessing() {
- // TODO Auto-generated method stub
- return false;
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public HashMap getConnectionState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void resetConnectionState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
}
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]