james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r531130 - in /james/jspf/branches/asynch-jspf/src: main/java/org/apache/james/jspf/ main/java/org/apache/james/jspf/core/ main/java/org/apache/james/jspf/macro/ main/java/org/apache/james/jspf/policies/ main/java/org/apache/james/jspf/polic...
Date Sun, 22 Apr 2007 00:34:25 GMT
Author: bago
Date: Sat Apr 21 17:34:24 2007
New Revision: 531130

URL: http://svn.apache.org/viewvc?view=rev&rev=531130
Log:
Another step toward event based flow.
macroExpand.expand now will return null if the clientDomain is needed to be resolved and it has not been resolved yet, so the client can do the dns lookup and try again.

Modified:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
    james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/SPF1ParserTest.java

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/SPF.java Sat Apr 21 17:34:24 2007
@@ -229,7 +229,7 @@
 
         policyFilters.add(new NeutralIfNotMatchPolicy());
 
-        policyFilters.add(new DefaultExplanationPolicy(log, defaultExplanation, macroExpand));
+        policyFilters.add(new DefaultExplanationPolicy(log, defaultExplanation, macroExpand, dnsProbe));
         
         policies.add(new InitialChecksPolicy());
         

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Directive.java Sat Apr 21 17:34:24 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.core;
 
+import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.exceptions.TempErrorException;
@@ -46,9 +47,10 @@
             throws PermErrorException {
         super();
         this.log = logger;
-        if (qualifier != null && qualifier.length() > 0) {
-            this.qualifier = qualifier;
+        if (qualifier == null) {
+            throw new PermErrorException("Qualifier cannot be null");
         }
+        this.qualifier = qualifier;
         if (mechanism == null) {
             throw new PermErrorException("Mechanism cannot be null");
         }
@@ -63,19 +65,18 @@
      * @throws PermErrorException get thrown if a PermError should returned
      * @throws TempErrorException get thrown if a TempError should returned
      * @throws NoneException get thrown if a NoneException should returned;
+     * @throws NeutralException 
      */
     public void checkSPF(SPFSession spfData) throws PermErrorException,
-            TempErrorException, NoneException {
+            TempErrorException, NoneException, NeutralException {
         // if already have a current result we don't run this
         if (spfData.getCurrentResult() == null) {
 
             if (mechanism.run(spfData)) {
-                if (qualifier != null) {
-                    if (qualifier.equals("")) {
-                        spfData.setCurrentResult(SPF1Constants.PASS);
-                    } else {
-                        spfData.setCurrentResult(qualifier);
-                    }
+                if (qualifier.equals("")) {
+                    spfData.setCurrentResult(SPF1Constants.PASS);
+                } else {
+                    spfData.setCurrentResult(qualifier);
                 }
                 
                 log.info("Processed directive matched: " + this + " returned " + spfData.getCurrentResult());
@@ -106,6 +107,12 @@
     
     public String toString() {
         return qualifier + mechanism;
+    }
+
+    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+            throws PermErrorException, NoneException, TempErrorException,
+            NeutralException {
+        throw new IllegalStateException("NOT USED YET");
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/Mechanism.java Sat Apr 21 17:34:24 2007
@@ -20,6 +20,7 @@
 
 package org.apache.james.jspf.core;
 
+import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.exceptions.TempErrorException;
@@ -40,16 +41,11 @@
      *             Get thrown if there are any errors in modifiers
      * @throws TempErrorException
      *             Get thrown if DNS problems detected
-     * @throws NoneException
+     * @throws NoneException 
      *             Get thrown if no valid records was found
+     * @throws NeutralException 
      */
     public boolean run(SPFSession spfData) throws PermErrorException,
-            TempErrorException, NoneException;
+            TempErrorException, NoneException, NeutralException;
     
-    /**
-     * Temporary, to evaluate impact on the redesign.
-     */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException,
-    TempErrorException, NoneException;
-
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFChecker.java Sat Apr 21 17:34:24 2007
@@ -33,18 +33,25 @@
      * Run check for SPF with the given values.
      * 
      * @param spfData
-     *             The SPF1Data which should be used to run the check
+     *            The SPF1Data which should be used to run the check
      * @throws PermErrorException
      *             Get thrown if an error was detected
      * @throws NoneException
      *             Get thrown if no Record was found
      * @throws TempErrorException
      *             Get thrown if a DNS problem was detected
-     * @throws NeutralException  
+     * @throws NeutralException
      *             Get thrown if the result should be neutral
+     * @throws NoneException 
      */
-    public void checkSPF(SPFSession spfData)
-            throws PermErrorException, NoneException, TempErrorException,
-            NeutralException;
+    public void checkSPF(SPFSession spfData) throws PermErrorException,
+            TempErrorException, NeutralException, NoneException;
 
+//    /**
+//     * Temporary, to evaluate impact on the redesign.
+//     */
+//    public void onDNSResponse(DNSResponse response, SPFSession spfSession)
+//            throws PermErrorException, NoneException, TempErrorException,
+//            NeutralException;
+//
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java Sat Apr 21 17:34:24 2007
@@ -28,17 +28,14 @@
 
 import org.apache.james.jspf.SPF1Utils;
 import org.apache.james.jspf.core.DNSService;
-import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPFSession;
-import org.apache.james.jspf.core.DNSService.TimeoutException;
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -62,6 +59,10 @@
     public static final boolean EXPLANATION = true;
     
     public static final boolean DOMAIN = false;
+    
+    public static class RequireClientDomain extends Exception {
+        
+    }
 
     /**
      * Construct MacroExpand
@@ -82,10 +83,14 @@
     }
     
     public String expand(String input, MacroData macroData, boolean isExplanation) throws PermErrorException {
-        if (isExplanation) {
-            return expandExplanation(input, macroData);
-        } else {
-            return expandDomain(input, macroData);
+        try {
+            if (isExplanation) {
+                return expandExplanation(input, macroData);
+            } else {
+                return expandDomain(input, macroData);
+            }
+        } catch (RequireClientDomain e) {
+            return null;
         }
     }
 
@@ -97,8 +102,9 @@
      * @return expanded The expanded explanation
      * @throws PermErrorException
      *             Get thrown if invalid macros are used
+     * @throws RequireClientDomain 
      */
-    private String expandExplanation(String input, MacroData macroData) throws PermErrorException {
+    private String expandExplanation(String input, MacroData macroData) throws PermErrorException, RequireClientDomain {
 
         log.debug("Start do expand explanation: " + input);
 
@@ -121,8 +127,9 @@
      * @return expanded The domain with replaced macros
      * @throws PermErrorException
      *             This get thrown if invalid macros are used
+     * @throws RequireClientDomain 
      */
-    private String expandDomain(String input, MacroData macroData) throws PermErrorException {
+    private String expandDomain(String input, MacroData macroData) throws PermErrorException, RequireClientDomain {
 
         log.debug("Start expand domain: " + input);
 
@@ -164,8 +171,9 @@
      * @return expanded The expanded given String
      * @throws PermErrorException
      *             This get thrown if invalid macros are used
+     * @throws RequireClientDomain 
      */
-    private String expandMacroString(String input, MacroData macroData, boolean isExplanation) throws PermErrorException {
+    private String expandMacroString(String input, MacroData macroData, boolean isExplanation) throws PermErrorException, RequireClientDomain {
 
         StringBuffer decodedValue = new StringBuffer();
         Matcher inputMatcher = macroStringPattern.matcher(input);
@@ -209,8 +217,9 @@
      * @return returnData The String with replaced macros
      * @throws PermErrorException
      *             Get thrown if an error in processing happen
+     * @throws RequireClientDomain 
      */
-    private String replaceCell(String replaceValue, MacroData macroData, boolean isExplanation) throws PermErrorException {
+    private String replaceCell(String replaceValue, MacroData macroData, boolean isExplanation) throws PermErrorException, RequireClientDomain {
 
         String variable = "";
         String domainNumber = "";
@@ -291,9 +300,10 @@
      * @return rValue The value for the given macro
      * @throws PermErrorException
      *             Get thrown if the given variable is an unknown macro
-     * 
+     * @throws RequireClientDomain requireClientDomain if the client domain is needed
+     *             and not yet resolved.
      */
-    private String matchMacro(String macro, MacroData macroData) throws PermErrorException {
+    private String matchMacro(String macro, MacroData macroData) throws PermErrorException, RequireClientDomain {
 
         String rValue = null;
 
@@ -317,34 +327,7 @@
         } else if (variable.equalsIgnoreCase("p")) {
             rValue = macroData.getClientDomain();
             if (rValue == null) {
-                rValue = "unknown";
-                if (macroData instanceof SPFSession) {
-                    SPFSession spf1data = (SPFSession) macroData;
-                    try {
-                        boolean ip6 = IPAddr.isIPV6(spf1data.getIpAddress());
-                        List records = dnsProbe.getRecords(IPAddr.getAddress(spf1data.getIpAddress()).getReverseIP(), DNSService.PTR);
-    
-                        if (records != null && records.size() > 0) {
-                            String record = (String) records.get(0);
-                            records = dnsProbe.getRecords(record, ip6 ? DNSService.AAAA : DNSService.A);
-                            if (records != null && records.size() > 0) {
-                                Iterator i = records.iterator();
-                                while (i.hasNext()) {
-                                    String next = (String) i.next();
-                                    if (IPAddr.getAddress(spf1data.getIpAddress()).toString().equals(IPAddr.getAddress(next).toString())) {
-                                        rValue = record;
-                                        break;
-                                    }
-                                }
-                            }
-                        }
-                    } catch (TimeoutException e) {
-                        // just return the default "unknown".
-                    } catch (PermErrorException e) {
-                        // just return the default "unknown".
-                    }
-                    spf1data.setClientDomain(rValue);
-                }
+                throw new RequireClientDomain();
             }
         } else if (variable.equalsIgnoreCase("o")) {
             rValue = macroData.getSenderDomain();

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/NeutralIfNotMatchPolicy.java Sat Apr 21 17:34:24 2007
@@ -42,7 +42,7 @@
         // Maybe we should simply append a "?all" at the end, as modifier
         if (spfRecord.getDirectives().size() > 0) {
             spfRecord.getModifiers().add(new SPFChecker() {
-                public void checkSPF(SPFSession spfData) throws PermErrorException, NoneException, TempErrorException, NeutralException {
+                public void checkSPF(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException {
                     // If no match was found set the result to neutral
                     if (spfData.getCurrentResult() == null) {
                         spfData.setCurrentResult(SPF1Constants.NEUTRAL);

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/local/DefaultExplanationPolicy.java Sat Apr 21 17:34:24 2007
@@ -20,6 +20,7 @@
 package org.apache.james.jspf.policies.local;
 
 import org.apache.james.jspf.SPF1Utils;
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.SPF1Constants;
 import org.apache.james.jspf.core.SPFSession;
@@ -31,11 +32,14 @@
 import org.apache.james.jspf.exceptions.TempErrorException;
 import org.apache.james.jspf.macro.MacroExpand;
 import org.apache.james.jspf.policies.PolicyPostFilter;
+import org.apache.james.jspf.util.DNSResolver;
 
 /**
  * Policy to add a default explanation
  */
 public final class DefaultExplanationPolicy implements PolicyPostFilter {
+    private static final String ATTRIBUTE_DEFAULT_EXPLANATION_POLICY_EXPLANATION = "DefaultExplanationPolicy.explanation";
+    
     /**
      * log
      */
@@ -46,15 +50,18 @@
     private String defExplanation;
     
     private MacroExpand macroExpand;
+    
+    private DNSService dnsService;
 
     /**
      * @param macroExpand 
      * @param spf
      */
-    public DefaultExplanationPolicy(Logger log, String explanation, MacroExpand macroExpand) {
+    public DefaultExplanationPolicy(Logger log, String explanation, MacroExpand macroExpand, DNSService dnsService) {
         this.log = log;
         this.defExplanation = explanation;
         this.macroExpand = macroExpand;
+        this.dnsService = dnsService;
     }
 
     /**
@@ -74,14 +81,25 @@
                         } else {
                             explanation = defExplanation;
                         }
-                        try {
-                            explanation = macroExpand.expand(explanation, spfData, MacroExpand.EXPLANATION);
+                        spfData.setAttribute(ATTRIBUTE_DEFAULT_EXPLANATION_POLICY_EXPLANATION, explanation);
+                        DNSResolver.hostExpand(dnsService, macroExpand, explanation, spfData, MacroExpand.EXPLANATION, new SPFChecker() {
+
+                            public void checkSPF(SPFSession spfData)
+                                    throws PermErrorException,
+                                    NoneException, TempErrorException,
+                                    NeutralException {
+                                String attExplanation = (String) spfData.getAttribute(ATTRIBUTE_DEFAULT_EXPLANATION_POLICY_EXPLANATION);
+                                try {
+                                    String explanation = macroExpand.expand(attExplanation, spfData, MacroExpand.EXPLANATION);
+                                    
+                                    spfData.setExplanation(explanation);
+                                } catch (PermErrorException e) {
+                                    // Should never happen !
+                                    log.debug("Invalid defaulfExplanation: " + attExplanation);
+                                }
+                            }
                             
-                            spfData.setExplanation(explanation);
-                        } catch (PermErrorException e) {
-                            // Should never happen !
-                            log.debug("Invalid defaulfExplanation: " + explanation);
-                        }
+                        });
                     }
                 }
             }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java Sat Apr 21 17:34:24 2007
@@ -25,10 +25,13 @@
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
 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.jspf.macro.MacroExpand;
 import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.Inet6Util;
 import org.apache.james.jspf.util.SPFTermsRegexps;
@@ -43,6 +46,8 @@
  */
 public class AMechanism extends GenericMechanism implements DNSServiceEnabled {
 
+    private static final String ATTRIBUTE_AMECHANISM_RESULT = "AMechanism.result";
+
     /**
      * ABNF: A = "a" [ ":" domain-spec ] [ dual-cidr-length ]
      */
@@ -58,46 +63,61 @@
 
     /**
      * 
+     * @throws NoneException 
+     * @throws NeutralException 
      * @see org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPFSession)
      */
     public boolean run(SPFSession spfData) throws PermErrorException,
-            TempErrorException {
+            TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
-        // Get the right host.
-        String host = expandHost(spfData);
+        SPFChecker checker = new SPFChecker() {
 
-        // get the ipAddress
-        try {
-            boolean validIPV4Address = Inet6Util.isValidIPV4Address(spfData.getIpAddress());
-            spfData.setAttribute("AMechanism.ipv4check", Boolean.valueOf(validIPV4Address));
-            if (validIPV4Address) {
-
-                List aRecords = getARecords(dnsService,host);
-                if (aRecords == null) {
-                    return onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.A)), spfData);
-                } else {
-                    return onDNSResponse(new DNSResponse(aRecords), spfData);
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    TempErrorException, NeutralException, NoneException {
+                // Get the right host.
+                String host = expandHost(spfData);
+
+                // get the ipAddress
+                try {
+                    boolean validIPV4Address = Inet6Util.isValidIPV4Address(spfData.getIpAddress());
+                    spfData.setAttribute("AMechanism.ipv4check", Boolean.valueOf(validIPV4Address));
+                    if (validIPV4Address) {
+
+                        List aRecords = getARecords(dnsService,host);
+                        if (aRecords == null) {
+                            onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.A)), spfData);
+                        } else {
+                            onDNSResponse(new DNSResponse(aRecords), spfData);
+                        }
+             
+                    } else {
+                        
+                        List aaaaRecords = getAAAARecords(dnsService, host);
+                        if (aaaaRecords == null) {
+                            onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.AAAA)), spfData);
+                        } else {
+                            onDNSResponse(new DNSResponse(aaaaRecords), spfData);
+                        }
+
+                    }
+                // PermError / TempError
+                // TODO: Should we replace this with the "right" Exceptions ?
+                } catch (Exception e) {
+                    log.debug("No valid ipAddress: ",e);
+                    throw new PermErrorException("No valid ipAddress: "
+                            + spfData.getIpAddress());
                 }
-     
-            } else {
                 
-                List aaaaRecords = getAAAARecords(dnsService, host);
-                if (aaaaRecords == null) {
-                    return onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.AAAA)), spfData);
-                } else {
-                    return onDNSResponse(new DNSResponse(aaaaRecords), spfData);
-                }
-
             }
-        // PermError / TempError
-        // TODO: Should we replace this with the "right" Exceptions ?
-        } catch (Exception e) {
-            log.debug("No valid ipAddress: ",e);
-            throw new PermErrorException("No valid ipAddress: "
-                    + spfData.getIpAddress());
-        }
+            
+        };
+        
+        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN, checker);
+        
+        Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_AMECHANISM_RESULT);
+        return res != null ? res.booleanValue() : false;
     }
 
     /**
@@ -235,10 +255,8 @@
         this.dnsService = service;
     }
 
-    /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
-     */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
+
+    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
         throws PermErrorException, TempErrorException, NoneException {
         List listAData = null;
         try {
@@ -248,7 +266,8 @@
         }
         // no a records just return null
         if (listAData == null) {
-            return false;
+            spfSession.setAttribute(ATTRIBUTE_AMECHANISM_RESULT, Boolean.FALSE);
+            return;
         }
 
         Boolean ipv4check = (Boolean) spfSession.getAttribute("AMechanism.ipv4check");
@@ -258,7 +277,8 @@
                     getIp4cidr());
 
             if (checkAddressList(checkAddress, listAData, getIp4cidr())) {
-                return true;
+                spfSession.setAttribute(ATTRIBUTE_AMECHANISM_RESULT, Boolean.TRUE);
+                return;
             }
 
         } else {
@@ -267,12 +287,14 @@
                     getIp6cidr());
             
             if (checkAddressList(checkAddress, listAData, getIp6cidr())) {
-                return true;
+                spfSession.setAttribute(ATTRIBUTE_AMECHANISM_RESULT, Boolean.TRUE);
+                return;
             }
 
         }
         
-        return false;
+        spfSession.setAttribute(ATTRIBUTE_AMECHANISM_RESULT, Boolean.FALSE);
+        return;
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AllMechanism.java Sat Apr 21 17:34:24 2007
@@ -22,12 +22,9 @@
 
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
-import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.Mechanism;
 import org.apache.james.jspf.core.SPFSession;
-import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.exceptions.TempErrorException;
 
 /**
  * This class represent the all mechanism
@@ -58,14 +55,5 @@
     public String toString() {
         return "all";
     }
-
-    /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
-     */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
-            throws PermErrorException, TempErrorException, NoneException {
-        // never called
-        return false;
-    }
-
+    
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java Sat Apr 21 17:34:24 2007
@@ -23,9 +23,13 @@
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
+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.jspf.macro.MacroExpand;
 import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 import org.apache.james.jspf.wiring.DNSServiceEnabled;
@@ -42,41 +46,59 @@
      */
     public static final String REGEX = "[eE][xX][iI][sS][tT][sS]" + "\\:"
             + SPFTermsRegexps.DOMAIN_SPEC_REGEX;
+
+    private static final String ATTRIBUTE_MECHANISM_RESULT = "ExistsMechanism.result";
     
     private DNSService dnsService;
 
     /**
      * 
+     * @throws NoneException 
+     * @throws NeutralException 
      * @see org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPFSession)
      */
     public boolean run(SPFSession spfData) throws PermErrorException,
-            TempErrorException {
+            TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
-        String host = expandHost(spfData);
+        SPFChecker checker = new SPFChecker() {
+
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    TempErrorException, NeutralException, NoneException {
+                String host = expandHost(spfData);
+                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host,DNSService.A)), spfData);
+            }
+            
+        };
+        
+        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN, checker);
+        
+        Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
+        return res != null ? res.booleanValue() : false;
 
-        return this.onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host,DNSService.A)), spfData);
     }
 
     /**
      * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
      */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException, TempErrorException {
+    private void onDNSResponse(DNSResponse response, SPFSession spfSession) throws PermErrorException, TempErrorException {
         List aRecords;
         
         try {
             aRecords = response.getResponse();
         } catch (DNSService.TimeoutException e) {
-            return false;
+            spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+            return;
         }
         
         if (aRecords != null && aRecords.size() > 0) {
-            return true;
+            spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
+            return;
         }
         
         // No match found
-        return false;
+        spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
     }
 
     /**

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java Sat Apr 21 17:34:24 2007
@@ -20,12 +20,18 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSRequest;
+import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.SPF1Constants;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
+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.jspf.macro.MacroExpand;
+import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
@@ -38,6 +44,8 @@
  */
 public class ExpModifier extends GenericModifier implements DNSServiceEnabled, MacroExpandEnabled {
 
+    private static final String ATTRIBUTE_EXPAND_EXPLANATION = "ExpModifier.ExpandExplanation";
+
     /**
      * ABNF: explanation = "exp" "=" domain-spec
      * 
@@ -59,9 +67,11 @@
      * @param spfData
      *            The SPF1Data which should used
      * @throws PermErrorException 
+     * @throws TempErrorException 
+     * @throws NoneException 
+     * @throws NeutralException 
      */
-    protected void checkSPFLogged(SPFSession spfData) throws PermErrorException {
-        String exp = null;
+    protected void checkSPFLogged(SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
         String host = getHost();
         
         // RFC4408 Errata: http://www.openspf.org/RFC_4408/Errata#empty-exp
@@ -78,29 +88,18 @@
         if (spfData.getCurrentResult()== null || !spfData.getCurrentResult().equals(SPF1Constants.FAIL))
             return;
 
-        host = macroExpand.expand(host, spfData, MacroExpand.DOMAIN);
+        DNSResolver.hostExpand(dnsService, macroExpand, host, spfData, MacroExpand.DOMAIN, new SPFChecker() {
 
-        try {
-            try {
-                exp = getTxtType(dnsService, host);
-            } catch (TempErrorException e) {
-                // Nothing todo here.. just return null
-                return;
-            }
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    NoneException, TempErrorException, NeutralException {
+                String host = macroExpand.expand(getHost(), spfData, MacroExpand.DOMAIN);
 
-            if ((exp != null) && (!exp.equals(""))) {
-                String expandedExplanation = macroExpand.expand(exp, spfData, MacroExpand.EXPLANATION);
-                spfData.setExplanation(expandedExplanation);
-            } 
-        } catch (PermErrorException e) {
-            // TODO add logging here!
-            // Only catch the error and return null
-            return;
-        }
-        return;
+                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.TXT)), spfData);
+            }
+            
+        });
     }
 
-
     /**
      * Get TXT records as a string
      * 
@@ -110,15 +109,18 @@
      * @return String which reflect the TXT-Record
      * @throws PermErrorException
      *             if more then one TXT-Record for explanation was found
+     * @throws NoneException 
+     * @throws NeutralException 
+     * @throws TempErrorException 
      * @throws TempErrorException
      *             if the lookup result was "TRY_AGAIN"
      */
-    public String getTxtType(DNSService dns, String strServer) throws TempErrorException, PermErrorException {
+    public void onDNSResponse(DNSResponse lookup, SPFSession spfData) throws PermErrorException, TempErrorException, NeutralException, NoneException {
         try {
-            List records = dns.getRecords(strServer, DNSService.TXT);
+            List records = lookup.getResponse();
         
             if (records == null) {
-                return null;
+                return;
             }
     
             // See SPF-Spec 6.2
@@ -127,13 +129,41 @@
             // or if no records are returned, or if more than one record is returned, or if there are syntax 
             // errors in the explanation string, then proceed as if no exp modifier was given.   
             if (records.size() > 1) {
+                
                 log.debug("More then one TXT-Record found for explanation");
-                throw new PermErrorException("More then one TXT-Record for explanation");
+                // Only catch the error and return null
+                
             } else {
-                return (String) records.get(0);
+                
+                String exp = (String) records.get(0);
+
+                spfData.setAttribute(ATTRIBUTE_EXPAND_EXPLANATION, exp);
+                
+                if ((exp != null) && (!exp.equals(""))) {
+                    
+                    try {
+                        DNSResolver.hostExpand(dnsService, macroExpand, exp, spfData, MacroExpand.EXPLANATION, new SPFChecker() {
+    
+                            public void checkSPF(SPFSession spfData)
+                                    throws PermErrorException, NoneException,
+                                    TempErrorException, NeutralException {
+                                String exp = (String) spfData.getAttribute(ATTRIBUTE_EXPAND_EXPLANATION);
+                                String expandedExplanation = macroExpand.expand(exp, spfData, MacroExpand.EXPLANATION);
+                                spfData.setExplanation(expandedExplanation);
+                            }
+                            
+                        });
+                    } catch (PermErrorException e) {
+                        // ignore syntax error on explanation expansion
+                    }
+                }
+                
             }
+            
+
         } catch (DNSService.TimeoutException e) {
-            throw new TempErrorException("Timeout querying dns server");
+            // Nothing todo here.. just return null
+            return;
         }
     }
     

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/GenericModifier.java Sat Apr 21 17:34:24 2007
@@ -25,6 +25,8 @@
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.Modifier;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
+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.jspf.wiring.LogEnabled;
@@ -40,11 +42,13 @@
     protected Logger log;
 
     /**
+     * @throws NoneException 
+     * @throws NeutralException 
      * @see org.apache.james.jspf.core.Modifier#run(SPFSession)
      * 
      */
     public void checkSPF(SPFSession spfData) throws PermErrorException,
-            TempErrorException {
+            TempErrorException, NeutralException, NoneException {
         log.debug("Processing modifier: " + this);
         checkSPFLogged(spfData);
         log.debug("Processed modifier: " + this + " resulted in "
@@ -52,7 +56,7 @@
     }
     
     protected abstract void checkSPFLogged(SPFSession spfData) throws PermErrorException,
-        TempErrorException;
+        TempErrorException, NeutralException, NoneException;
 
 
     /**

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IP4Mechanism.java Sat Apr 21 17:34:24 2007
@@ -21,12 +21,9 @@
 package org.apache.james.jspf.terms;
 
 import org.apache.james.jspf.core.Configuration;
-import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.SPFSession;
-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.jspf.util.Inet6Util;
 
 /**
@@ -118,12 +115,4 @@
         }
     }
 
-    /**
-     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
-     */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
-            throws PermErrorException, TempErrorException, NoneException {
-        // not needed, IP4Mechanism does not require further lookups
-        return false;
-    }
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java Sat Apr 21 17:34:24 2007
@@ -23,17 +23,20 @@
 import org.apache.james.jspf.core.Configurable;
 import org.apache.james.jspf.core.Configuration;
 import org.apache.james.jspf.core.DNSResponse;
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.Mechanism;
 import org.apache.james.jspf.core.SPF1Constants;
-import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.exceptions.NeutralException;
 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.jspf.macro.MacroExpand;
+import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.LogEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
 import org.apache.james.jspf.wiring.SPFCheckEnabled;
@@ -42,7 +45,7 @@
  * This class represent the incude mechanism
  * 
  */
-public class IncludeMechanism implements Mechanism, Configurable, LogEnabled, SPFCheckEnabled, MacroExpandEnabled {
+public class IncludeMechanism implements Mechanism, Configurable, LogEnabled, SPFCheckEnabled, MacroExpandEnabled, DNSServiceEnabled {
 
     /**
      * ABNF: include = "include" ":" domain-spec
@@ -58,6 +61,8 @@
 
     private MacroExpand macroExpand;
 
+    private DNSService dnsService;
+
     /**
      * Set the host which should be used for include
      * 
@@ -68,53 +73,78 @@
      *             if an error is in the redirect modifier
      * @throws TempErrorException 
      *             if the dns return a temp error
+     * @throws NoneException 
+     * @throws NeutralException 
      */
-    public boolean run(SPFSession spfData) throws PermErrorException, TempErrorException {
-        String host = getHost();
-
+    public boolean run(SPFSession spfData) throws PermErrorException, TempErrorException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();      
         
-        // throws a PermErrorException that we can pass through
-        host = macroExpand.expand(host, spfData, MacroExpand.DOMAIN);
+        SPFChecker checker = new SPFChecker() {
 
-        String prevRes = spfData.getCurrentResult();
-        String prevHost = spfData.getCurrentDomain();
-        
-        try {
-    
-            spfData.setCurrentDomain(host);
-            
-            // On includes we should not use the explanation of the included domain
-            spfData.setIgnoreExplanation(true);
-            // set a null current result
-            spfData.setCurrentResult(null);
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    TempErrorException {
+
+                // throws a PermErrorException that we can pass through
+                String host = macroExpand.expand(getHost(), spfData, MacroExpand.DOMAIN);
+
+                // TODO understand what exactly we have to do now that spfData is a session
+                // and contains much more than the input data.
+                // do we need to create a new session at all?
+                // do we need to backup the session attributes and restore them?
+                String prevRes = spfData.getCurrentResult();
+                String prevHost = spfData.getCurrentDomain();
+                
+                try {
             
-            try {
-                 spfChecker.checkSPF(spfData);
-              
-            } catch (NoneException e) {
-                throw new PermErrorException("included checkSPF returned NoneException");
-            } catch (NeutralException e) {
-                throw new PermErrorException("included checkSPF returned NeutralException");
+                    spfData.setCurrentDomain(host);
+                    
+                    // On includes we should not use the explanation of the included domain
+                    spfData.setIgnoreExplanation(true);
+                    // set a null current result
+                    spfData.setCurrentResult(null);
+                    
+                    try {
+                         spfChecker.checkSPF(spfData);
+                    } catch (NeutralException e) {
+                        throw new PermErrorException("included checkSPF returned NeutralException");
+                    } catch (NoneException e) {
+                        throw new PermErrorException("included checkSPF returned NoneException");
+                    }
+                    
+                    if (spfData.getCurrentResult() == null) {
+                        throw new TempErrorException("included checkSPF returned null");
+                    } else if (spfData.getCurrentResult().equals(SPF1Constants.PASS)) {
+                        // TODO this won't work asynchronously
+                        spfData.setAttribute("IncludeMechanism.result", Boolean.TRUE);
+                    } else if (spfData.getCurrentResult().equals(SPF1Constants.FAIL) || spfData.getCurrentResult().equals(SPF1Constants.SOFTFAIL) || spfData.getCurrentResult().equals(SPF1Constants.NEUTRAL)) {
+                        // TODO this won't work asynchronously
+                        spfData.setAttribute("IncludeMechanism.result", Boolean.FALSE);
+                    } else {
+                        throw new TempErrorException("included checkSPF returned an Illegal result");
+                    }
+                } finally {
+                    // Reset the ignore
+                    spfData.setIgnoreExplanation(false);
+                    spfData.setCurrentDomain(prevHost);
+                    spfData.setCurrentResult(prevRes);
+                }
+                    
+
             }
             
-            if (spfData.getCurrentResult() == null) {
-                throw new TempErrorException("included checkSPF returned null");
-            } else if (spfData.getCurrentResult().equals(SPF1Constants.PASS)) {
-                return true;
-            } else if (spfData.getCurrentResult().equals(SPF1Constants.FAIL) || spfData.getCurrentResult().equals(SPF1Constants.SOFTFAIL) || spfData.getCurrentResult().equals(SPF1Constants.NEUTRAL)) {
-                return false;
-            } else {
-                throw new TempErrorException("included checkSPF returned an Illegal result");
-            }
-        } finally {
-            // Reset the ignore
-            spfData.setIgnoreExplanation(false);
-            spfData.setCurrentDomain(prevHost);
-            spfData.setCurrentResult(prevRes);
+        };
+        
+        try {
+            DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData, MacroExpand.DOMAIN, checker);
+        } catch (NeutralException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
         }
-            
+        
+        // TODO this won't work asynchronously
+        Boolean res = (Boolean) spfData.getAttribute("IncludeMechanism.result");
+        return res != null ? res.booleanValue() : false;
     }
 
     /**
@@ -169,5 +199,12 @@
             throws PermErrorException, TempErrorException, NoneException {
         // not called yet.
         return false;
+    }
+
+    /**
+     * @see org.apache.james.jspf.wiring.DNSServiceEnabled#enableDNSService(org.apache.james.jspf.core.DNSService)
+     */
+    public void enableDNSService(DNSService service) {
+        this.dnsService = service;
     }
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java Sat Apr 21 17:34:24 2007
@@ -20,12 +20,18 @@
 
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSRequest;
+import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
 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.jspf.macro.MacroExpand;
+import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 
 import java.util.ArrayList;
@@ -37,85 +43,121 @@
  */
 public class MXMechanism extends AMechanism {
 
+    private static final String ATTRIBUTE_MX_RECORDS = "MXMechanism.mxRecords";
+    private static final String ATTRIBUTE_CHECK_RECORDS = "MXMechanism.checkRecords";
     /**
      * ABNF: MX = "mx" [ ":" domain-spec ] [ dual-cidr-length ]
      */
     public static final String REGEX = "[mM][xX]" + "(?:\\:"
             + SPFTermsRegexps.DOMAIN_SPEC_REGEX + ")?" + "(?:"
             + DUAL_CIDR_LENGTH_REGEX + ")?";
+    
+    private static final String ATTRIBUTE_MECHANISM_RESULT = "MXMechanism.result";
 
     /**
      * 
      * @throws NoneException 
+     * @throws NeutralException 
+     * @throws NoneException 
      * @see org.apache.james.jspf.core.GenericMechanism#run(org.apache.james.jspf.core.SPFSession)
      */
     public boolean run(SPFSession spfData) throws PermErrorException,
-            TempErrorException{
-        IPAddr checkAddress;
+            TempErrorException, NeutralException, NoneException{
 
         // update currentDepth
         spfData.increaseCurrentDepth();
 
-        // Get the right host.
-        String host = expandHost(spfData);
+        SPFChecker checker = new SPFChecker() {
 
-        // if the remote IP is an ipv6 we check ipv6 addresses, otherwise ip4
-        boolean isIPv6 = IPAddr.isIPV6(spfData.getIpAddress());
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    TempErrorException, NeutralException, NoneException {
+
+                // Get the right host.
+                String host = expandHost(spfData);
+                
+                onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(host, DNSService.MX)), spfData);
+            }
+            
+        };
         
-        // get the ipAddress
-        checkAddress = IPAddr.getAddress(spfData.getIpAddress(), isIPv6 ? getIp6cidr() : getIp4cidr());
+        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN, checker);
         
-        List mxRecords = getMXRecords(dnsService, host, isIPv6 ? DNSService.AAAA : DNSService.A);
-
-        // no mx record found
-        if (mxRecords == null) return false;
-          
-        if (checkAddressList(checkAddress, mxRecords, getIp4cidr())) {
-            return true;
-        }
-
-        // No match found
-        return false;
+        Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
+        return res != null ? res.booleanValue() : false;
     }
 
-
     /**
-     * @param type 
-     * @see org.apache.james.jspf.core.DNSService#getMXRecords(java.lang.String,
-     *      int)
+     * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.SPFSession)
      */
-    private List getMXRecords(DNSService dnsProbe, String domainName, int type)
-            throws PermErrorException, TempErrorException {
+    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
+        throws PermErrorException, TempErrorException {
         try {
-            List mxR = null;
-            List records = dnsProbe.getRecords(domainName, DNSService.MX);
-    
+            
+            List records = (List) spfSession.getAttribute(ATTRIBUTE_CHECK_RECORDS);
+            List mxR = (List) spfSession.getAttribute(ATTRIBUTE_MX_RECORDS);
+            
             if (records == null) {
-                return null;
-            }
             
-            for (int i = 0; i < records.size(); i++) {
-                String mx = (String) records.get(i);
+                records = response.getResponse();
                 
-                if (mx != null && mx.length() > 0) {
-                    log.debug("Add MX-Record " + mx + " to list");
-        
-                    List res = dnsProbe.getRecords(mx, type);
-                    if (res != null) {
-                        if (mxR == null) {
-                            mxR = new ArrayList();
-                        }
-                        mxR.addAll(res);
+                if (records == null) {
+                    // no mx record found
+                    spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+                    return;
+                }
+                
+                spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, records);
+                
+            } else {
+                
+                List res = response.getResponse();
+                
+                if (res != null) {
+                    if (mxR == null) {
+                        mxR = new ArrayList();
+                        spfSession.setAttribute(ATTRIBUTE_MX_RECORDS, mxR);
                     }
+                    System.out.println("ADDALL: "+res);
+                    mxR.addAll(res);
                 }
+                
+            }
+
+            // if the remote IP is an ipv6 we check ipv6 addresses, otherwise ip4
+            boolean isIPv6 = IPAddr.isIPV6(spfSession.getIpAddress());
+
+            String mx;
+            while (records.size() > 0 && (mx = (String) records.remove(0)) != null && mx.length() > 0) {
+                log.debug("Add MX-Record " + mx + " to list");
+    
+                this.onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(mx, isIPv6 ? DNSService.AAAA : DNSService.A)), spfSession);
+                return;
+                
+            }
+                
+            // no mx record found
+            if (mxR == null || mxR.size() == 0) {
+                spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+                return;
             }
             
-            return mxR != null && mxR.size() > 0 ? mxR : null;
+            // get the ipAddress
+            IPAddr checkAddress;
+            checkAddress = IPAddr.getAddress(spfSession.getIpAddress(), isIPv6 ? getIp6cidr() : getIp4cidr());
+            
+            // clean up attributes
+            spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, null);
+            spfSession.setAttribute(ATTRIBUTE_MX_RECORDS, null);
+            spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.valueOf(checkAddressList(checkAddress, mxR, getIp4cidr())));
+            return;
+            
         } catch (DNSService.TimeoutException e) {
+            spfSession.setAttribute(ATTRIBUTE_CHECK_RECORDS, null);
+            spfSession.setAttribute(ATTRIBUTE_MX_RECORDS, null);
             throw new TempErrorException("Timeout querying the dns server");
         }
     }
-    
+
     /**
      * @see org.apache.james.jspf.terms.AMechanism#toString()
      */

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java Sat Apr 21 17:34:24 2007
@@ -24,9 +24,13 @@
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
+import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.core.SPFSession;
+import org.apache.james.jspf.exceptions.NeutralException;
+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.jspf.macro.MacroExpand;
 import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
 import org.apache.james.jspf.wiring.DNSServiceEnabled;
@@ -50,22 +54,47 @@
      */
     public static final String REGEX = "[pP][tT][rR]" + "(?:\\:"
             + SPFTermsRegexps.DOMAIN_SPEC_REGEX + ")?";
+
+    private static final String ATTRIBUTE_MECHANISM_RESULT = "PTRMechanism.result";
     
     private DNSService dnsService;
 
     /**
+     * @throws NoneException 
+     * @throws NeutralException 
      * @see org.apache.james.jspf.core.Mechanism#run(org.apache.james.jspf.core.SPFSession)
      */
     public boolean run(SPFSession spfData) throws PermErrorException,
-            TempErrorException {
+            TempErrorException, NeutralException, NoneException {
         // update currentDepth
         spfData.increaseCurrentDepth();
 
-        // Get PTR Records for the ipAddress which is provided by SPF1Data
-        IPAddr ip = IPAddr.getAddress(spfData.getIpAddress());
         
-        DNSResponse response = DNSResolver.lookup(dnsService, new DNSRequest(ip.getReverseIP(), DNSService.PTR));
-        return this.onDNSResponse(response, spfData);
+        SPFChecker checker = new SPFChecker() {
+
+            public void checkSPF(SPFSession spfData) throws PermErrorException,
+                    TempErrorException, NeutralException, NoneException {
+
+                // Get PTR Records for the ipAddress which is provided by SPF1Data
+                IPAddr ip = IPAddr.getAddress(spfData.getIpAddress());
+
+                // Get the right host.
+                String host = expandHost(spfData);
+                
+                spfData.setAttribute(ATTRIBUTE_EXPANDED_HOST, host);
+
+                DNSResponse response = DNSResolver.lookup(dnsService, new DNSRequest(ip.getReverseIP(), DNSService.PTR));
+                onDNSResponse(response, spfData);
+            }
+            
+        };
+        
+        DNSResolver.hostExpand(dnsService, macroExpand, getDomain(), spfData, MacroExpand.DOMAIN, checker);
+        
+        Boolean res = (Boolean) spfData.getAttribute(ATTRIBUTE_MECHANISM_RESULT);
+        return res != null ? res.booleanValue() : false;
+
+        
     }
 
     /**
@@ -78,7 +107,7 @@
     /**
      * @see org.apache.james.jspf.core.Mechanism#onDNSResponse(org.apache.james.jspf.core.DNSResponse, org.apache.james.jspf.core.SPFSession)
      */
-    public boolean onDNSResponse(DNSResponse response, SPFSession spfSession)
+    private void onDNSResponse(DNSResponse response, SPFSession spfSession)
             throws PermErrorException, TempErrorException {
         
         List domainList = (List) spfSession.getAttribute(ATTRIBUTE_DOMAIN_LIST);
@@ -88,7 +117,10 @@
                 domainList = response.getResponse();
                 
                 // No PTR records found
-                if (domainList == null) return false;
+                if (domainList == null) {
+                    spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+                    return;
+                }
         
                 // check if the maximum lookup count is reached
                 if (dnsService.getRecordLimit() > 0 && domainList.size() > dnsService.getRecordLimit()) {
@@ -100,11 +132,6 @@
                 
                 spfSession.setAttribute(ATTRIBUTE_DOMAIN_LIST, domainList);
                 
-                // Get the right host.
-                String host = expandHost(spfSession);
-                
-                spfSession.setAttribute(ATTRIBUTE_EXPANDED_HOST, host);
-                
             } else {
 
                 String compareDomain = (String) spfSession.getAttribute(ATTRIBUTE_CURRENT_DOMAIN);
@@ -119,7 +146,8 @@
                             
                             if (compareDomain.equals(host)
                                     || compareDomain.endsWith("." + host)) {
-                                return true;
+                                spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.TRUE);
+                                return;
                             }
                             
                         }
@@ -149,10 +177,11 @@
                 
                 spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, currentDomain);
                 
-                return this.onDNSResponse(DNSResolver.lookup(dnsService, dnsRequest), spfSession);
-                
+                onDNSResponse(DNSResolver.lookup(dnsService, dnsRequest), spfSession);
+                return;
             } else {
-                return false;
+                spfSession.setAttribute(ATTRIBUTE_MECHANISM_RESULT, Boolean.FALSE);
+                return;
             }
 
         } finally {

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/RedirectModifier.java Sat Apr 21 17:34:24 2007
@@ -17,9 +17,9 @@
  * under the License.                                           *
  ****************************************************************/
 
-
 package org.apache.james.jspf.terms;
 
+import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.core.SPFChecker;
 import org.apache.james.jspf.exceptions.NeutralException;
@@ -27,7 +27,9 @@
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.exceptions.TempErrorException;
 import org.apache.james.jspf.macro.MacroExpand;
+import org.apache.james.jspf.util.DNSResolver;
 import org.apache.james.jspf.util.SPFTermsRegexps;
+import org.apache.james.jspf.wiring.DNSServiceEnabled;
 import org.apache.james.jspf.wiring.MacroExpandEnabled;
 import org.apache.james.jspf.wiring.SPFCheckEnabled;
 
@@ -35,18 +37,21 @@
  * This class represent the redirect modifier
  * 
  */
-public class RedirectModifier extends GenericModifier implements SPFCheckEnabled, MacroExpandEnabled {
+public class RedirectModifier extends GenericModifier implements
+        SPFCheckEnabled, MacroExpandEnabled, DNSServiceEnabled {
 
     /**
      * ABNF: redirect = "redirect" "=" domain-spec
      */
     public static final String REGEX = "[rR][eE][dD][iI][rR][eE][cC][tT]"
             + "\\=" + SPFTermsRegexps.DOMAIN_SPEC_REGEX;
-    
+
     private SPFChecker spfChecker;
 
     private MacroExpand macroExpand;
 
+    private DNSService dnsService;
+
     /**
      * Set the host which should be used for redirection and set it in SPF1Data
      * so it can be accessed easy later if needed
@@ -58,35 +63,52 @@
      *             if an error is in the redirect modifier
      * @throws TempErrorException
      *             if an DNS problem accurred
+     * @throws NoneException
+     * @throws NeutralException
      */
-    protected void checkSPFLogged(SPFSession spfData) throws PermErrorException,
-            TempErrorException {
+    protected void checkSPFLogged(SPFSession spfData)
+            throws PermErrorException, TempErrorException, NeutralException,
+            NoneException {
         // the redirect modifier is used only when we had no previous matches
         if (spfData.getCurrentResult() == null) {
 
-            String host = getHost();
-
             // update currentDepth
             spfData.increaseCurrentDepth();
 
-            // throws a PermErrorException that we can pass through
-            host = macroExpand.expand(host, spfData, MacroExpand.DOMAIN);
+            DNSResolver.hostExpand(dnsService, macroExpand, getHost(), spfData,
+                    MacroExpand.DOMAIN, new SPFChecker() {
 
-            spfData.setCurrentDomain(host);
+                        public void checkSPF(SPFSession spfData)
+                                throws PermErrorException, NoneException,
+                                TempErrorException, NeutralException {
+                            String host = getHost();
+
+                            // throws a PermErrorException that we can pass
+                            // through
+                            host = macroExpand.expand(host, spfData,
+                                    MacroExpand.DOMAIN);
+
+                            spfData.setCurrentDomain(host);
+
+                            // TODO change this to work asynchronously
+                            try {
+                                spfChecker.checkSPF(spfData);
+                            } catch (NoneException e) {
+                                // no spf record assigned to the redirect domain
+                                throw new PermErrorException(
+                                        "included checkSPF returned NoneException");
+                            } catch (NeutralException e) {
+                                throw new PermErrorException(
+                                        "included checkSPF returned NeutralException");
+
+                            } finally {
+                                // After the redirect we should not use the
+                                // explanation from the orginal record
+                                spfData.setIgnoreExplanation(true);
+                            }
+                        }
 
-            try {
-                spfChecker.checkSPF(spfData);
-            } catch (NoneException e) {
-                // no spf record assigned to the redirect domain
-                throw new PermErrorException(
-                        "included checkSPF returned NoneException");
-            } catch (NeutralException e) {
-                throw new PermErrorException("included checkSPF returned NeutralException");
-            
-            } finally {
-                //After the redirect we should not use the explanation from the orginal record
-                spfData.setIgnoreExplanation(true);
-            }
+                    });
 
         }
     }
@@ -95,9 +117,9 @@
      * @see java.lang.Object#toString()
      */
     public String toString() {
-        return "redirect="+getHost();
+        return "redirect=" + getHost();
     }
-    
+
     /**
      * @see org.apache.james.jspf.wiring.SPFCheckEnabled#enableSPFChecking(org.apache.james.jspf.core.SPFChecker)
      */
@@ -110,6 +132,10 @@
      */
     public void enableMacroExpand(MacroExpand macroExpand) {
         this.macroExpand = macroExpand;
+    }
+
+    public void enableDNSService(DNSService service) {
+        this.dnsService = service;
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/util/DNSResolver.java Sat Apr 21 17:34:24 2007
@@ -22,10 +22,24 @@
 import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSResponse;
 import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.IPAddr;
+import org.apache.james.jspf.core.SPFChecker;
+import org.apache.james.jspf.core.SPFCheckerDNSResponseListener;
+import org.apache.james.jspf.core.SPFSession;
 import org.apache.james.jspf.core.DNSService.TimeoutException;
+import org.apache.james.jspf.exceptions.NeutralException;
+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.jspf.macro.MacroExpand;
+
+import java.util.Iterator;
+import java.util.List;
 
 public class DNSResolver {
     
+    private static final String ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD = "MacroExpand.checkedRecord";
+
     /**
      * This is used temporarily to synchronously obtain a DNSResponse for a DNSRequest
      */
@@ -34,6 +48,85 @@
             return new DNSResponse(service.getRecords(request.getHostname(), request.getRecordType()));
         } catch (TimeoutException e) {
             return new DNSResponse(e);
+        }
+    }
+    
+    public static void hostExpand(DNSService dnsService, MacroExpand macroExpand, String input, final SPFSession spfSession, boolean isExplanation, final SPFChecker next) throws PermErrorException, TempErrorException, NeutralException, NoneException {
+        if (input != null) {
+            String host = macroExpand.expand(input, spfSession, isExplanation);
+            if (host == null) {
+                new SPFCheckerDNSResponseListener() {
+    
+                    private DNSService dnsService;
+    
+                    public void onDNSResponse(DNSResponse response,
+                            SPFSession session) throws PermErrorException,
+                            NoneException, TempErrorException, NeutralException {
+                        
+                        try {
+                            boolean ip6 = IPAddr.isIPV6(session.getIpAddress());
+                            List records = response.getResponse();
+        
+                            if (records != null && records.size() > 0) {
+                                String record = (String) records.get(0);
+                                spfSession.setAttribute(ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD, record);
+                                
+                                DNSResponse resp = DNSResolver.lookup(dnsService, new DNSRequest(record, ip6 ? DNSService.AAAA : DNSService.A));
+                                new SPFCheckerDNSResponseListener() {
+                                    
+                                    public void onDNSResponse(DNSResponse response,
+                                            SPFSession session) throws PermErrorException,
+                                            NoneException, TempErrorException, NeutralException {
+                                        // just return the default "unknown" if we cannot find anything later
+                                        spfSession.setClientDomain("unknown");
+                                        try {
+                                            List records = response.getResponse();
+                                            if (records != null && records.size() > 0) {
+                                                Iterator i = records.iterator();
+                                                while (i.hasNext()) {
+                                                    String next = (String) i.next();
+                                                    if (IPAddr.getAddress(session.getIpAddress()).toString().equals(IPAddr.getAddress(next).toString())) {
+                                                        spfSession.setClientDomain((String) spfSession.getAttribute(ATTRIBUTE_MACRO_EXPAND_CHECKED_RECORD));
+                                                        break;
+                                                    }
+                                                }
+                                            }
+                                        } catch (TimeoutException e) {
+                                            // just return the default "unknown".
+                                        } catch (PermErrorException e) {
+                                            // just return the default "unknown".
+                                        }
+                                        
+                                        next.checkSPF(spfSession);
+    
+                                    }
+                                }.onDNSResponse(resp, session);
+                                
+                            }
+                        } catch (TimeoutException e) {
+                            // just return the default "unknown".
+                            spfSession.setClientDomain("unknown");
+                            next.checkSPF(spfSession);
+                        } catch (PermErrorException e) {
+                            // just return the default "unknown".
+                            spfSession.setClientDomain("unknown");
+                            next.checkSPF(spfSession);
+                        }
+                        
+                    }
+    
+                    public SPFCheckerDNSResponseListener setDNSService(
+                            DNSService dnsService) {
+                        this.dnsService = dnsService;
+                        return this;
+                    }
+                    
+                }.setDNSService(dnsService).onDNSResponse(DNSResolver.lookup(dnsService, new DNSRequest(IPAddr.getAddress(spfSession.getIpAddress()).getReverseIP(), DNSService.PTR)), spfSession);
+            } else {
+                next.checkSPF(spfSession);
+            }
+        } else {
+            next.checkSPF(spfSession);
         }
     }
 

Modified: james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/SPF1ParserTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/SPF1ParserTest.java?view=diff&rev=531130&r1=531129&r2=531130
==============================================================================
--- james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/SPF1ParserTest.java (original)
+++ james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/SPF1ParserTest.java Sat Apr 21 17:34:24 2007
@@ -20,19 +20,19 @@
 
 package org.apache.james.jspf;
 
+import org.apache.james.jspf.core.SPFRecordParser;
+import org.apache.james.jspf.exceptions.NoneException;
+import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.parser.DefaultSPF1Parser;
+import org.apache.james.jspf.parser.DefaultTermsFactory;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
-import java.util.List;
 import java.util.Iterator;
+import java.util.List;
 import java.util.regex.Pattern;
-
-import org.apache.james.jspf.core.SPFRecordParser;
-import org.apache.james.jspf.exceptions.NoneException;
-import org.apache.james.jspf.exceptions.PermErrorException;
-import org.apache.james.jspf.parser.DefaultSPF1Parser;
-import org.apache.james.jspf.parser.DefaultTermsFactory;
 
 import junit.framework.Test;
 import junit.framework.TestCase;



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


Mime
View raw message