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/07/17 13:04:34 UTC

svn commit: r422677 - in /james/server/trunk/src: conf/ java/org/apache/james/smtpserver/ java/org/apache/james/smtpserver/core/ java/org/apache/james/smtpserver/core/filter/ test/org/apache/james/smtpserver/

Author: norman
Date: Mon Jul 17 04:04:34 2006
New Revision: 422677

URL: http://svn.apache.org/viewvc?rev=422677&view=rev
Log:
Change DNSRBLServer to use the new smtp-api. See JAMES-567

Modified:
    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/filter/RcptFilterCmdHandler.java
    james/server/trunk/src/test/org/apache/james/smtpserver/DNSRBLHandlerTest.java
    james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java

Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?rev=422677&r1=422676&r2=422677&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Mon Jul 17 04:04:34 2006
@@ -912,15 +912,16 @@
          <!-- The configuration handler chain -->
          <!-- The configuration handler chain -->
          <handlerchain>
-            
-            <!-- The connect handler configuration -->
+
+            <!-- Load the core filter command handlers-->
+            <handler class="org.apache.james.smtpserver.core.filter.CoreFilterCmdHandlerLoader"></handler>        
 
             <!-- This command handler check against RBL-Lists -->
             <!-- If getDetail is set to true it try to retrieve information from TXT Record -->
             <!-- why the ip was blocked. Default to false -->            
             <!--
             
-            <handler class="org.apache.james.smtpserver.core.DNSRBLHandler">
+            <handler class="org.apache.james.smtpserver.core.DNSRBLHandler" command="RCPT">
                <getDetail> false </getDetail>
                <rblservers>
                   <whitelist> query.bondedsender.org </whitelist>
@@ -932,8 +933,6 @@
             </handler>            
             -->    
             
-            <!-- Load the core filter command handlers-->
-            <handler class="org.apache.james.smtpserver.core.filter.CoreFilterCmdHandlerLoader"></handler>        
 
             <!-- The filter handler configuration -->
 

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=422677&r1=422676&r2=422677&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 Mon Jul 17 04:04:34 2006
@@ -433,35 +433,6 @@
     public SMTPHandlerConfigurationData getConfigurationData() {
         return theConfigData;
     }
-
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#isBlockListed()
-     */
-    public boolean isBlockListed() {
-        return blocklisted;
-    }
-
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#setBlockListed(boolean)
-     */
-    public void setBlockListed(boolean blocklisted ) {
-        this.blocklisted = blocklisted;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#getBlockListedDetail()
-     */
-    public String getBlockListedDetail() {
-        return blocklistedDetail;
-    }
-    
-    /**
-     * @see org.apache.james.smtpserver.SMTPSession#setBlockListedDetail(String)
-     */
-    public void setBlockListedDetail(String blocklistedDetail) {
-        this.blocklistedDetail = blocklistedDetail;
-    }
-
     /**
      * @see org.apache.james.smtpserver.SMTPSession#isRelayingAllowed()
      */

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=422677&r1=422676&r2=422677&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 Mon Jul 17 04:04:34 2006
@@ -159,34 +159,6 @@
     SMTPHandlerConfigurationData getConfigurationData();
 
     /**
-     * Sets the blocklisted value
-     *
-     * @param blocklisted
-     */
-    void setBlockListed(boolean blocklisted);
-
-    /**
-     * Returns the blocklisted status
-     *
-     * @return blocklisted
-     */
-    boolean isBlockListed();
-
-    /**
-     * Set the BlockListedDetail which will be used in responseString
-     * 
-     * @param detail The detail 
-     */
-    void setBlockListedDetail(String detail);
-    
-    /**
-     * Returns the BlockListedDetail
-     * 
-     * @return The BlockListedDetail
-     */
-    String getBlockListedDetail();
-    
-    /**
      * Returns whether Relaying is allowed or not
      *
      * @return the relaying status

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=422677&r1=422676&r2=422677&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 Mon Jul 17 04:04:34 2006
@@ -25,8 +25,11 @@
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.james.services.DNSServer;
+import org.apache.james.smtpserver.CommandHandler;
 import org.apache.james.smtpserver.ConnectHandler;
 import org.apache.james.smtpserver.SMTPSession;
+import org.apache.james.util.mail.dsn.DSNStatus;
+import org.apache.mailet.MailAddress;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -37,7 +40,7 @@
   */
 public class DNSRBLHandler
     extends AbstractLogEnabled
-    implements ConnectHandler, Configurable, Serviceable {
+    implements ConnectHandler, CommandHandler, Configurable, Serviceable {
     /**
      * The lists of rbl servers to be checked to limit spam
      */
@@ -47,6 +50,10 @@
     private DNSServer dnsServer = null;
     
     private boolean getDetail = false;
+    
+    private boolean blocklisted = false;
+    
+    private String blocklistedDetail = null;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -106,8 +113,7 @@
      * @see org.apache.james.smtpserver.ConnectHandler#onConnect(SMTPSession)
     **/
     public void onConnect(SMTPSession session) {
-        boolean blocklisted = checkDNSRBL(session, session.getRemoteIPAddress());
-        session.setBlockListed(blocklisted);
+        blocklisted = checkDNSRBL(session, session.getRemoteIPAddress());
     }
     
     /**
@@ -145,6 +151,24 @@
     public void setGetDetail(boolean getDetail) {
         this.getDetail = getDetail;
     }
+    
+    /**
+     * Return true if the ip is blocklisted
+     * 
+     * @return true uf blocklisted
+     */
+    public boolean isBlocklisted() {
+        return blocklisted;
+    }
+    
+    /**
+     * Return the details
+     * 
+     * @return blocklistDetail
+     */
+    public String getBlocklistedDetail() {
+        return blocklistedDetail;
+    }
 
     /**
      * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#checkDNSRBL(Socket)
@@ -205,7 +229,7 @@
                         // Check if we found a txt record
                         if (!txt.isEmpty()) {
                             // Set the detail
-                            session.setBlockListedDetail(txt.iterator().next().toString());
+                            blocklistedDetail = txt.iterator().next().toString();
                         }
                     }
                     return true;
@@ -220,4 +244,49 @@
         return false;
     }
 
+    /**
+     * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
+     */
+    public Collection getImplCommands() {
+        Collection commands = new ArrayList();
+        commands.add("RCPT");
+        return commands;
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
+     */
+    public void onCommand(SMTPSession session) {
+        String responseString = null;
+        MailAddress recipientAddress = (MailAddress) session.getState().get(
+                SMTPSession.CURRENT_RECIPIENT);
+
+        if (blocklisted && // was found in the RBL
+                !(session.isRelayingAllowed() || (session.isAuthRequired() && session
+                        .getUser() != null)) && // Not (either an authorized IP
+                                                // or (SMTP AUTH is enabled and
+                                                // not authenticated))
+                !(recipientAddress.getUser().equalsIgnoreCase("postmaster") || recipientAddress
+                        .getUser().equalsIgnoreCase("abuse"))) {
+
+            // trying to send e-mail to other than postmaster or abuse
+            if (blocklistedDetail != null) {
+                responseString = "530 "
+                        + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                DSNStatus.SECURITY_AUTH) + " "
+                        + blocklistedDetail;
+            } else {
+                responseString = "530 "
+                        + DSNStatus.getStatus(DSNStatus.PERMANENT,
+                                DSNStatus.SECURITY_AUTH)
+                        + " Rejected: unauthenticated e-mail from "
+                        + session.getRemoteIPAddress()
+                        + " is restricted.  Contact the postmaster for details.";
+            }
+            session.writeResponse(responseString);
+
+            // After this filter match we should not call any other handler!
+            session.setStopHandlerProcessing(true);
+        }
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java?rev=422677&r1=422676&r2=422677&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/RcptFilterCmdHandler.java Mon Jul 17 04:04:34 2006
@@ -140,23 +140,7 @@
                 return;
             }
 
-            if (session.isBlockListed() &&                                                // was found in the RBL
-                !(session.isRelayingAllowed() || (session.isAuthRequired() && session.getUser() != null)) &&  // Not (either an authorized IP or (SMTP AUTH is enabled and not authenticated))
-                !(recipientAddress.getUser().equalsIgnoreCase("postmaster") || recipientAddress.getUser().equalsIgnoreCase("abuse"))) {
-                
-                // trying to send e-mail to other than postmaster or abuse
-                if (session.getBlockListedDetail() != null) {
-                    responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" " + session.getBlockListedDetail();
-                } else {
-                    responseString = "530 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SECURITY_AUTH)+" Rejected: unauthenticated e-mail from " + session.getRemoteIPAddress() + " is restricted.  Contact the postmaster for details.";
-                }
-                session.writeResponse(responseString);
-                
-                // 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

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=422677&r1=422676&r2=422677&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 Mon Jul 17 04:04:34 2006
@@ -290,8 +290,8 @@
         rbl.setGetDetail(true);
         rbl.onConnect(mockedSMTPSession);
         assertEquals("Blocked - see http://www.spamcop.net/bl.shtml?127.0.0.2",
-                mockedSMTPSession.getBlockListedDetail());
-        assertTrue(mockedSMTPSession.isBlockListed());
+               rbl.getBlocklistedDetail());
+        assertTrue(rbl.isBlocklisted());
     }
 
     // ip is blacklisted and has txt details but we don'T want to retrieve the txt record
@@ -306,8 +306,8 @@
         rbl.setBlacklist(new String[] { "bl.spamcop.net" });
         rbl.setGetDetail(false);
         rbl.onConnect(mockedSMTPSession);
-        assertNull(mockedSMTPSession.getBlockListedDetail());
-        assertTrue(mockedSMTPSession.isBlockListed());
+        assertNull(rbl.getBlocklistedDetail());
+        assertTrue(rbl.isBlocklisted());
     }
 
     // ip is allowed to relay
@@ -324,8 +324,8 @@
         rbl.setBlacklist(new String[] { "bl.spamcop.net" });
         rbl.setGetDetail(true);
         rbl.onConnect(mockedSMTPSession);
-        assertNull(mockedSMTPSession.getBlockListedDetail());
-        assertFalse(mockedSMTPSession.isBlockListed());
+        assertNull(rbl.getBlocklistedDetail());
+        assertFalse(rbl.isBlocklisted());
     }
 
     // ip not on blacklist
@@ -341,8 +341,8 @@
         rbl.setBlacklist(new String[] { "bl.spamcop.net" });
         rbl.setGetDetail(true);
         rbl.onConnect(mockedSMTPSession);
-        assertNull(mockedSMTPSession.getBlockListedDetail());
-        assertFalse(mockedSMTPSession.isBlockListed());
+        assertNull(rbl.getBlocklistedDetail());
+        assertFalse(rbl.isBlocklisted());
     }
 
     // ip on blacklist without txt details
@@ -358,8 +358,8 @@
         rbl.setBlacklist(new String[] { "bl.spamcop.net" });
         rbl.setGetDetail(true);
         rbl.onConnect(mockedSMTPSession);
-        assertNull(mockedSMTPSession.getBlockListedDetail());
-        assertTrue(mockedSMTPSession.isBlockListed());
+        assertNull(rbl.getBlocklistedDetail());
+        assertTrue(rbl.isBlocklisted());
     }
 
     // ip on whitelist
@@ -375,8 +375,8 @@
         rbl.setWhitelist(new String[] { "bl.spamcop.net" });
         rbl.setGetDetail(true);
         rbl.onConnect(mockedSMTPSession);
-        assertNull(mockedSMTPSession.getBlockListedDetail());
-        assertFalse(mockedSMTPSession.isBlockListed());
+        assertNull(rbl.getBlocklistedDetail());
+        assertFalse(rbl.isBlocklisted());
     }
 
 }

Modified: james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java?rev=422677&r1=422676&r2=422677&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SMTPTestConfiguration.java Mon Jul 17 04:04:34 2006
@@ -156,6 +156,7 @@
                     .getChild("handlerchain");
             DefaultConfiguration handler = new DefaultConfiguration("handler");
             handler.setAttribute("class", DNSRBLHandler.class.getName());
+            handler.setAttribute("command", "RCPT");
             handlerChain.addChild(handler);
         }
         // Add Configuration for Helo checks and Ehlo checks



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