1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.james.jspf.executor;
22
23 import org.apache.james.jspf.core.SPF1Utils;
24 import org.apache.james.jspf.core.SPFSession;
25 import org.apache.james.jspf.core.exceptions.SPFErrorConstants;
26
27
28
29
30
31
32 public class SPFResult {
33
34 protected String headerTextAsString = "";
35
36 protected final static String HEADER_NAME = "Received-SPF";
37
38 protected String result = null;
39
40 protected String explanation = null;
41
42 protected SPFResult() {
43
44 }
45
46
47
48
49
50
51 public SPFResult(SPFSession spfSession) {
52 setSPFSession(spfSession);
53 }
54
55
56
57
58
59
60 protected void setSPFSession(SPFSession spfSession) {
61 this.explanation = spfSession.getExplanation();
62 this.result = spfSession.getCurrentResultExpanded();
63 this.headerTextAsString = generateHeader(result, spfSession);
64 }
65
66
67
68
69
70
71 public String getHeader() {
72 return HEADER_NAME+": "+getHeaderText();
73 }
74
75
76
77
78
79
80 public String getHeaderName() {
81 return HEADER_NAME;
82 }
83
84
85
86
87
88
89 public String getHeaderText() {
90 return headerTextAsString != null ? headerTextAsString : "";
91 }
92
93
94
95
96
97
98 private String generateHeader(String result, SPFSession spfData) {
99
100 StringBuffer headerText = new StringBuffer();
101
102 if (result.equals(SPFErrorConstants.PASS_CONV)) {
103 headerText.append(result + " (spfCheck: domain of "
104 + spfData.getCurrentDomain() + " designates "
105 + spfData.getIpAddress() + " as permitted sender) ");
106 } else if (result.equals(SPFErrorConstants.FAIL_CONV)) {
107 headerText.append(result + " (spfCheck: domain of "
108 + spfData.getCurrentDomain() + " does not designate "
109 + spfData.getIpAddress() + " as permitted sender) ");
110 } else if (result.equals(SPFErrorConstants.NEUTRAL_CONV)
111 || result.equals(SPFErrorConstants.NONE_CONV)) {
112 headerText.append(result + " (spfCheck: " + spfData.getIpAddress()
113 + " is neither permitted nor denied by domain of "
114 + spfData.getCurrentDomain() + ") ");
115
116 } else if (result.equals(SPFErrorConstants.SOFTFAIL_CONV)) {
117 headerText.append(result + " (spfCheck: transitioning domain of "
118 + spfData.getCurrentDomain() + " does not designate "
119 + spfData.getIpAddress() + " as permitted sender) ");
120 } else if (result.equals(SPFErrorConstants.PERM_ERROR_CONV)) {
121 headerText.append(result
122 + " (spfCheck: Error in processing SPF Record) ");
123
124 } else if (result.equals(SPFErrorConstants.TEMP_ERROR_CONV)) {
125 headerText.append(result
126 + " (spfCheck: Error in retrieving data from DNS) ");
127
128 }
129
130 String headerTextAsString;
131 if (headerText.length() > 0) {
132 headerText.append("client-ip=" + spfData.getIpAddress()
133 + "; envelope-from=" + spfData.getMailFrom() + "; helo="
134 + spfData.getHostName() + ";");
135 headerTextAsString = headerText.toString();
136 } else {
137 headerTextAsString = "";
138 }
139 return headerTextAsString;
140 }
141
142
143
144
145
146
147
148 public String getResult() {
149 return result;
150 }
151
152
153
154
155
156
157
158 public String getExplanation() {
159 return explanation != null ? explanation : "";
160 }
161
162
163 }