--- /james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java 2006-09-24 16:43:59.000000000 +0200 +++ /james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java 2006-09-24 17:17:19.000000000 +0200 @@ -90,6 +90,23 @@ * @return result The SPFResult */ public SPFResult checkSPF(String ipAddress, String mailFrom, String hostName) { + return checkSPF(ipAddress, mailFrom, hostName, null); + } + + /** + * Run check for SPF with the given values. + * + * @param ipAddress + * The ipAddress the connection is comming from + * @param mailFrom + * The mailFrom which was provided + * @param hostName + * The hostname which was provided as HELO/EHLO + * @param spfRecord + * The spf record to check + * @return result The SPFResult + */ + public SPFResult checkSPF(String ipAddress, String mailFrom, String hostName, String spfRecord) { SPF1Data spfData = null; String result = null; String resultChar = null; @@ -98,7 +115,7 @@ try { // Setup the data spfData = new SPF1Data(mailFrom, hostName, ipAddress, dnsProbe); - SPFInternalResult res = checkSPF(spfData); + SPFInternalResult res = checkSPF(spfData, spfRecord); resultChar = res.getResultChar(); result = SPF1Utils.resultToName(resultChar); explanation = res.getExplanation(); @@ -134,6 +151,8 @@ * * @param spfData * The SPF1Data which should be used to run the check + * @param spfRecord + * The spf record to check * @return result * The SPFInternalResult * @throws PermErrorException @@ -147,15 +166,42 @@ */ public SPFInternalResult checkSPF(SPF1Data spfData) throws PermErrorException, NoneException, TempErrorException, NeutralException { + return checkSPF(spfData, null); + } + + /** + * Run check for SPF with the given values. + * + * @param spfData + * The SPF1Data which should be used to run the check + * @return result + * The SPFInternalResult + * @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 + * Get thrown if the result should be neutral + */ + public SPFInternalResult checkSPF(SPF1Data spfData, String spfDnsEntry) throws PermErrorException, + NoneException, TempErrorException, NeutralException { String result = SPF1Constants.NEUTRAL; String explanation = null; - // Get the raw dns txt entry which contains a spf entry - String spfDnsEntry = dnsProbe.getSpfRecord(spfData.getCurrentDomain(), - SPF1Constants.SPF_VERSION); + if (spfDnsEntry == null) { + // Get the raw dns txt entry which contains a spf entry + spfDnsEntry = dnsProbe.getSpfRecord(spfData.getCurrentDomain(), + SPF1Constants.SPF_VERSION); - // logging - log.debug("Start parsing SPF-Record:" + spfDnsEntry); + // logging + log.debug("Start parsing DNS SPF-Record: " + spfDnsEntry); + } + else { + // logging + log.debug("Start parsing Forced SPF-Record: " + spfDnsEntry); + } SPF1Record spfRecord = parser.parse(spfDnsEntry);