1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jspf.policies;
21
22 import org.apache.james.jspf.core.DNSLookupContinuation;
23 import org.apache.james.jspf.core.SPF1Record;
24 import org.apache.james.jspf.core.SPF1Utils;
25 import org.apache.james.jspf.core.SPFChecker;
26 import org.apache.james.jspf.core.SPFSession;
27 import org.apache.james.jspf.core.exceptions.NeutralException;
28 import org.apache.james.jspf.core.exceptions.NoneException;
29 import org.apache.james.jspf.core.exceptions.PermErrorException;
30 import org.apache.james.jspf.core.exceptions.TempErrorException;
31 import org.xbill.DNS.Name;
32 import org.xbill.DNS.TextParseException;
33
34
35
36
37
38
39 public final class InitialChecksPolicy implements SPFChecker {
40
41
42
43
44 public DNSLookupContinuation checkSPF(SPFSession spfData)
45 throws PermErrorException, TempErrorException, NeutralException,
46 NoneException {
47 SPF1Record res = (SPF1Record) spfData.getAttribute(SPF1Utils.ATTRIBUTE_SPF1_RECORD);
48 if (res == null) {
49
50
51 String currentDomain = spfData.getCurrentDomain();
52 if (currentDomain != null) {
53 String[] labels = currentDomain.split("\\.");
54 for (int i = 0; i < labels.length; i++) {
55 if (labels[i] != null && labels[i].length() > 63) {
56 throw new NoneException("Domain "+currentDomain+" is malformed (label longer than 63 characters)");
57 }
58 }
59 }
60
61 if (spfData.getSenderDomain().indexOf('.') < 0) {
62 throw new NoneException("Sender domain "+spfData.getSenderDomain()+" is not an FQDN.");
63 }
64
65 try {
66 Name.fromString(spfData.getSenderDomain());
67 } catch (TextParseException e) {
68 throw new NoneException("Invalid sender domain: "+e.getMessage());
69 }
70 }
71 return null;
72 }
73 }