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 2006/09/07 23:47:41 UTC

svn commit: r441244 - in /james/server/trunk/src: conf/james-smtphandlerchain.xml java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java test/org/apache/james/smtpserver/SPFHandlerTest.java

Author: norman
Date: Thu Sep  7 14:47:40 2006
New Revision: 441244

URL: http://svn.apache.org/viewvc?view=rev&rev=441244
Log:
Allow to configure to not block on PermError and just add the header, so the user can react on the header later. See JAMES-604

Modified:
    james/server/trunk/src/conf/james-smtphandlerchain.xml
    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/src/conf/james-smtphandlerchain.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-smtphandlerchain.xml?view=diff&rev=441244&r1=441243&r2=441244
==============================================================================
--- james/server/trunk/src/conf/james-smtphandlerchain.xml (original)
+++ james/server/trunk/src/conf/james-smtphandlerchain.xml Thu Sep  7 14:47:40 2006
@@ -60,6 +60,7 @@
      <handler class="org.apache.james.smtpserver.core.filter.fastfail.SPFHandler" command="MAIL,RCPT">
          <checkAuthNetworks> false </checkAuthNetworks>
          <blockSoftFail> false </blockSoftFail>
+         <blockPermError> true </blockPermError>
      </handler>
      -->    
             

Modified: 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?view=diff&rev=441244&r1=441243&r2=441244
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java Thu Sep  7 14:47:40 2006
@@ -69,6 +69,8 @@
      * If set to true the mail will also be rejected on a softfail
      */
     private boolean blockSoftFail = false;
+    
+    private boolean blockPermError = true;
 
     private DNSService dnsService = null;
 
@@ -88,6 +90,12 @@
         if (configuration != null) {
             setBlockSoftFail(configuration.getValueAsBoolean(false));
         }
+        
+        Configuration configPermError = handlerConfiguration.getChild(
+                "blockPermError", false);
+        if (configuration != null) {
+            setBlockPermError(configPermError.getValueAsBoolean(true));
+        }
         Configuration configRelay = handlerConfiguration.getChild(
                 "checkAuthNetworks", false);
         if (configRelay != null) {
@@ -117,6 +125,16 @@
     public void setBlockSoftFail(boolean blockSoftFail) {
         this.blockSoftFail = blockSoftFail;
     }
+    
+    /**
+     * block the email on a permerror
+     * 
+     * @param blockPermError
+     *            true or false
+     */
+    public void setBlockPermError(boolean blockPermError) {
+        this.blockPermError = blockPermError;
+    }
 
     /**
      * DNSService to use
@@ -195,7 +213,7 @@
                 // Check if we should block!
                 if ((spfResult.equals(SPF1Utils.FAIL_CONV))
                         || (spfResult.equals(SPF1Utils.SOFTFAIL_CONV) && blockSoftFail)
-                        || spfResult.equals(SPF1Utils.PERM_ERROR_CONV)) {
+                        || (spfResult.equals(SPF1Utils.PERM_ERROR_CONV) && blockPermError)) {
 
                     if (spfResult.equals(SPF1Utils.PERM_ERROR)) {
                         explanation = "Blocked caused by an invalid SPF record";

Modified: 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?view=diff&rev=441244&r1=441243&r2=441244
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java Thu Sep  7 14:47:40 2006
@@ -466,4 +466,31 @@
                 .get(SPFHandler.SPF_HEADER));
         assertFalse(mockedSMTPSession.getStopHandlerProcessing());
     }
+    
+    public void testSPFpermErrorRejectDisabled() throws Exception {
+        setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
+                new MailAddress("test@spf4.james.apache.org"), new MailAddress(
+                        "test@localhost"));
+        SPFHandler spf = new SPFHandler();
+
+        ContainerUtil.enableLogging(spf, new MockLogger());
+        
+        spf.setDNSService(mockedDnsService);
+        
+        spf.initialize();
+        
+        spf.setBlockPermError(false);
+
+        runHandlers(spf, mockedSMTPSession);
+
+        assertNull("not reject", mockedSMTPSession.getState().get(
+                SPFHandler.SPF_BLOCKLISTED));
+        assertNull("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));
+        assertFalse(mockedSMTPSession.getStopHandlerProcessing());
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org