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 ba...@apache.org on 2007/04/30 18:36:42 UTC

svn commit: r533792 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: SPF.java policies/InitialChecksPolicy.java

Author: bago
Date: Mon Apr 30 09:36:41 2007
New Revision: 533792

URL: http://svn.apache.org/viewvc?view=rev&rev=533792
Log:
Removed log of the result before returning the SPFResult. In case of asynchronous processing the getResult from the log statement will make the thread to wait for the result to be completed (join the resolver thread), invalidating the asynchronous behaviour.
Moved the InitialChecks before the retriever, and added some check to the checker (to avoid relying on specific dnsservice implementation behaviours).

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/policies/InitialChecksPolicy.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=533792&r1=533791&r2=533792
==============================================================================
--- 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 Mon Apr 30 09:36:41 2007
@@ -323,8 +323,9 @@
         
         executor.execute(spfData, ret);
 
-        log.info("[ipAddress=" + ipAddress + "] [mailFrom=" + mailFrom
-                + "] [helo=" + hostName + "] => " + ret.getResult());
+        // if we call ret.getResult it waits the result ;-)
+//        log.info("[ipAddress=" + ipAddress + "] [mailFrom=" + mailFrom
+//                + "] [helo=" + hostName + "] => " + ret.getResult());
 
         return ret;
 
@@ -356,14 +357,14 @@
         if (override != null) {
             policies.add(new SPFPolicyChecker(override));
         }
-        
+
+        policies.add(new InitialChecksPolicy());
+
         if (mustEquals) {
             policies.add(new SPFStrictCheckerRetriever());
         } else {
             policies.add(new SPFRetriever());
         }
-
-        policies.add(new SPFPolicyChecker(new InitialChecksPolicy()));
 
         if (useBestGuess) {
             policies.add(new SPFPolicyPostFilterChecker(new BestGuessPolicy()));

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java?view=diff&rev=533792&r1=533791&r2=533792
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java (original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/InitialChecksPolicy.java Mon Apr 30 09:36:41 2007
@@ -19,30 +19,50 @@
 
 package org.apache.james.jspf.policies;
 
+import org.apache.james.jspf.SPF;
+import org.apache.james.jspf.core.DNSLookupContinuation;
 import org.apache.james.jspf.core.SPF1Record;
+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.xbill.DNS.Name;
+import org.xbill.DNS.TextParseException;
 
 /**
  * Run the checks on the validity of the domain
  * This is an override filter to be executed as the first 
  * so it should be added as the last filter.
  */
-public final class InitialChecksPolicy implements Policy {
+public final class InitialChecksPolicy implements SPFChecker {
     
-    /**
-     * @see org.apache.james.jspf.policies.Policy#getSPFRecord(java.lang.String)
-     */
-    public SPF1Record getSPFRecord(String currentDomain) throws PermErrorException, TempErrorException, NoneException, NeutralException {
-        // Initial checks (spec 4.3)
-        if (currentDomain != null) {
-            String[] labels = currentDomain.split("\\.");
-            for (int i = 0; i < labels.length; i++) {
-                if (labels[i] != null && labels[i].length() > 63) {
-                    throw new NoneException("Domain "+currentDomain+" is malformed (label longer than 63 characters)");
+    public DNSLookupContinuation checkSPF(SPFSession spfData)
+            throws PermErrorException, TempErrorException, NeutralException,
+            NoneException {
+        SPF1Record res = (SPF1Record) spfData.getAttribute(SPF.ATTRIBUTE_SPF1_RECORD);
+        if (res == null) {
+
+            // Initial checks (spec 4.3)
+            String currentDomain = spfData.getCurrentDomain();
+            if (currentDomain != null) {
+                String[] labels = currentDomain.split("\\.");
+                for (int i = 0; i < labels.length; i++) {
+                    if (labels[i] != null && labels[i].length() > 63) {
+                        throw new NoneException("Domain "+currentDomain+" is malformed (label longer than 63 characters)");
+                    }
                 }
+            }
+            
+            if (spfData.getSenderDomain().indexOf('.') < 0) {
+                throw new NoneException("Sender domain "+spfData.getSenderDomain()+" is not an FQDN.");
+            }
+            
+            try {
+                Name.fromString(spfData.getSenderDomain());
+            } catch (TextParseException e) {
+                throw new NoneException("Invalid sender domain: "+e.getMessage());
             }
         }
         return null;



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


Re: svn commit: r533792 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: SPF.java policies/InitialChecksPolicy.java

Posted by Norman Maurer <no...@apache.org>.
Stefano Bagnara schrieb:
> Norman Maurer ha scritto:
>   
>> bago@apache.org schrieb:
>>     
>>> +            if (spfData.getSenderDomain().indexOf('.') < 0) {
>>> +                throw new NoneException("Sender domain "+spfData.getSenderDomain()+" is not an FQDN.");
>>> +            }
>>> +           
>>>   
>>>       
>> Should we use a "better" regex for FQDN detection ?
>>     
>
> Just after that test I also added a dnsjava "Name.fromString(domain)"
> that should take care of a better "check".
> We currently pass all the tests: if you can write a test we don't pass
> then we can try to fix it by improving the code ;-) (not to say that the
> code is good that way, but to say that we should prove it by creating a
> test, so we are sure we fix it correctly).
>
> Stefano
>   

Ok, I will take a deeper look tomorrow. Now I have to get ready for
party :-P

bye
Norman



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


Re: svn commit: r533792 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: SPF.java policies/InitialChecksPolicy.java

Posted by Stefano Bagnara <ap...@bago.org>.
Norman Maurer ha scritto:
> 
> bago@apache.org schrieb:
>> +            if (spfData.getSenderDomain().indexOf('.') < 0) {
>> +                throw new NoneException("Sender domain "+spfData.getSenderDomain()+" is not an FQDN.");
>> +            }
>> +           
>>   
> Should we use a "better" regex for FQDN detection ?

Just after that test I also added a dnsjava "Name.fromString(domain)"
that should take care of a better "check".
We currently pass all the tests: if you can write a test we don't pass
then we can try to fix it by improving the code ;-) (not to say that the
code is good that way, but to say that we should prove it by creating a
test, so we are sure we fix it correctly).

Stefano


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


Re: svn commit: r533792 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: SPF.java policies/InitialChecksPolicy.java

Posted by Norman Maurer <no...@apache.org>.

bago@apache.org schrieb:
> +            if (spfData.getSenderDomain().indexOf('.') < 0) {
> +                throw new NoneException("Sender domain "+spfData.getSenderDomain()+" is not an FQDN.");
> +            }
> +           
>   
Should we use a "better" regex for FQDN detection ?

bye
Norman


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