Author: bago
Date: Thu Oct 5 09:43:45 2006
New Revision: 453285
URL: http://svn.apache.org/viewvc?view=rev&rev=453285
Log:
Removed unused methods constants to reach 76.5% coverage (ok this is cheating
;-) )
Moved service implementations with dependencies in the impl package (we could
even move this to a different module)
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java
(with props)
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java
(with props)
Removed:
james/jspf/trunk/src/main/java/org/apache/james/jspf/DNSServiceXBillImpl.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/Log4JLogger.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/SPFQuery.java
Modified:
james/jspf/trunk/pom.xml
james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF1Utils.java
james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
Modified: james/jspf/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/pom.xml?view=diff&rev=453285&r1=453284&r2=453285
==============================================================================
--- james/jspf/trunk/pom.xml (original)
+++ james/jspf/trunk/pom.xml Thu Oct 5 09:43:45 2006
@@ -223,7 +223,7 @@
<configuration>
<archive>
<manifest>
- <mainClass>org.apache.james.jspf.SPFQuery</mainClass>
+ <mainClass>org.apache.james.jspf.impl.SPFQuery</mainClass>
<packageName>org.apache.james.jspf</packageName>
<addClasspath>true</addClasspath>
</manifest>
Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=453285&r1=453284&r2=453285
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java Thu Oct 5
09:43:45 2006
@@ -77,22 +77,6 @@
private FallbackPolicy fallBack;
private boolean useTrustedForwarder = false;
-
- /**
- * Uses default Log4JLogger and DNSJava based dns resolver
- */
- public SPF() {
- this(new Log4JLogger(org.apache.log4j.Logger.getLogger(SPF.class)));
- }
-
- /**
- * Uses passed logger and DNSJava based dns resolver
- *
- * @param logger the logger to use
- */
- public SPF(Logger logger) {
- this(new DNSServiceXBillImpl(logger), logger);
- }
/**
* Uses passed logger and passed dnsServicer
Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF1Utils.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF1Utils.java?view=diff&rev=453285&r1=453284&r2=453285
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF1Utils.java
(original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF1Utils.java Thu Oct
5 09:43:45 2006
@@ -65,42 +65,8 @@
return NEUTRAL_CONV;
} else if (result.equals(SPF1Constants.SOFTFAIL)) {
return SOFTFAIL_CONV;
- } else if (result.equals(PERM_ERROR_CONV)) {
- return PERM_ERROR_CONV;
- } else if (result.equals(TEMP_ERROR_CONV)) {
- return TEMP_ERROR_CONV;
- } else if (result.equals(NONE_CONV)) {
- return NONE_CONV;
} else {
return NEUTRAL_CONV;
- }
-
- }
-
- /**
- * Covert SPF names to raw SPF results
- *
- * @param result The result which should converted
- * @return coverted result
- */
- protected static String nameToResult(String result) {
-
- if (result.equals(PASS_CONV)) {
- return SPF1Constants.PASS;
- } else if (result.equals(FAIL_CONV)) {
- return SPF1Constants.FAIL;
- } else if (result.equals(NEUTRAL_CONV)) {
- return SPF1Constants.NEUTRAL;
- } else if (result.equals(SOFTFAIL_CONV)) {
- return SPF1Constants.SOFTFAIL;
- } else if (result.equals(PERM_ERROR_CONV)) {
- return PERM_ERROR_CONV;
- } else if (result.equals(TEMP_ERROR_CONV)) {
- return TEMP_ERROR_CONV;
- } else if (result.equals(NONE_CONV)) {
- return NONE_CONV;
- } else {
- return SPF1Constants.NEUTRAL;
}
}
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java?view=auto&rev=453285
==============================================================================
---
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
(added)
+++
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
Thu Oct 5 09:43:45 2006
@@ -0,0 +1,187 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.impl;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.IPAddr;
+import org.apache.james.jspf.core.Logger;
+import org.xbill.DNS.AAAARecord;
+import org.xbill.DNS.ARecord;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.MXRecord;
+import org.xbill.DNS.PTRRecord;
+import org.xbill.DNS.Record;
+import org.xbill.DNS.TXTRecord;
+import org.xbill.DNS.TextParseException;
+import org.xbill.DNS.Type;
+
+/**
+ * This class contains helper to get all neccassary DNS infos that are needed
+ * for SPF
+ */
+public class DNSServiceXBillImpl implements DNSService {
+
+ // Set seconds after which we return and TempError
+ private static int timeOut = 20;
+
+ // The logger
+ private Logger log;
+
+ // The record limit for lookups
+ private int recordLimit;
+
+ /**
+ * Default Constructor
+ */
+ public DNSServiceXBillImpl(Logger logger) {
+ this.log = logger;
+ // Default record limit is 10
+ this.recordLimit = 10;
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.DNSService#setTimeOut(int)
+ */
+ public synchronized void setTimeOut(int timeOut) {
+ DNSServiceXBillImpl.timeOut = timeOut;
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.DNSService#getLocalDomainNames();
+ */
+ public List getLocalDomainNames() {
+ List names = new ArrayList();
+
+ log.debug("Start Local ipaddress lookup");
+ try {
+ InetAddress ia[] = InetAddress.getAllByName(InetAddress
+ .getLocalHost().getHostName());
+
+ for (int i = 0; i < ia.length; i++) {
+ String host = ia[i].getHostName();
+ names.add(host);
+
+ log.debug("Add hostname " + host + " to list");
+ }
+ } catch (UnknownHostException e) {
+ // just ignore this..
+ }
+ return names;
+
+ }
+
+ /**
+ * @return the current record limit
+ */
+ public int getRecordLimit() {
+ return recordLimit;
+ }
+
+ /**
+ * Set a new limit for the number of records for MX and PTR lookups.
+ * @param recordLimit
+ */
+ public void setRecordLimit(int recordLimit) {
+ this.recordLimit = recordLimit;
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.DNSService#getRecords(java.lang.String,
int)
+ */
+ public List getRecords(String hostname, int recordType)
+ throws TimeoutException {
+ String recordTypeDescription;
+ int dnsJavaType;
+ int recordCount = 0;
+ switch (recordType) {
+ case A: recordTypeDescription = "A"; dnsJavaType = Type.A; break;
+ case AAAA: recordTypeDescription = "AAAA"; dnsJavaType =
Type.AAAA; break;
+ case MX: recordTypeDescription = "MX"; dnsJavaType = Type.MX;
break;
+ case PTR: recordTypeDescription = "PTR"; dnsJavaType = Type.PTR;
break;
+ case TXT: recordTypeDescription = "TXT"; dnsJavaType = Type.TXT;
break;
+ // case SPF: recordTypeDescString = "SPF"; dnsJavaType = Type.SPF;
break;
+ default: // TODO fail!
+ return null;
+ }
+ List records;
+ try {
+
+ log.debug("Start "+recordTypeDescription+"-Record lookup for : " +
hostname);
+
+ Lookup.getDefaultResolver().setTimeout(timeOut);
+ Lookup query = new Lookup(hostname, dnsJavaType);
+
+ Record[] rr = query.run();
+ int queryResult = query.getResult();
+
+ if (queryResult == Lookup.TRY_AGAIN) {
+ throw new TimeoutException();
+ }
+
+ if (rr != null && rr.length > 0) {
+ records = new ArrayList();
+ for (int i = 0; i < rr.length; i++) {
+ String res;
+ switch (recordType) {
+ case A:
+ ARecord a = (ARecord) rr[i];
+ res = a.getAddress().getHostAddress();
+ break;
+ case AAAA:
+ AAAARecord aaaa = (AAAARecord) rr[i];
+ res = aaaa.getAddress().getHostAddress();
+ break;
+ case MX:
+ MXRecord mx = (MXRecord) rr[i];
+ res = mx.getTarget().toString();
+ break;
+ case PTR:
+ PTRRecord ptr = (PTRRecord) rr[i];
+ res = IPAddr.stripDot(ptr.getTarget().toString());
+ break;
+ case TXT:
+ TXTRecord txt = (TXTRecord) rr[i];
+ res = txt.rdataToString();
+ break;
+ default:
+ return null;
+ }
+ records.add(res);
+ }
+ recordCount = rr.length;
+ } else {
+ records = null;
+ }
+
+ log.debug("Found " + recordCount + "
"+recordTypeDescription+"-Records");
+ } catch (TextParseException e) {
+ // i think this is the best we could do
+ log.debug("No "+recordTypeDescription+" Record found for host: " +
hostname);
+ records = null;
+ }
+ return records;
+ }
+
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java?view=auto&rev=453285
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java
(added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java
Thu Oct 5 09:43:45 2006
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.impl;
+
+import org.apache.james.jspf.SPF;
+import org.apache.james.jspf.core.Logger;
+
+public class DefaultSPF extends SPF {
+
+
+ /**
+ * Uses default Log4JLogger and DNSJava based dns resolver
+ */
+ public DefaultSPF() {
+ this(new Log4JLogger(org.apache.log4j.Logger.getLogger(SPF.class)));
+ }
+
+ /**
+ * Uses passed logger and DNSJava based dns resolver
+ *
+ * @param logger the logger to use
+ */
+ public DefaultSPF(Logger logger) {
+ super(new DNSServiceXBillImpl(logger), logger);
+ }
+
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/DefaultSPF.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java?view=auto&rev=453285
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java
(added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java
Thu Oct 5 09:43:45 2006
@@ -0,0 +1,207 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.impl;
+
+import org.apache.james.jspf.core.Logger;
+import org.apache.log4j.Level;
+
+/**
+ * Implementation of the Logger interface using the Log4J implementation
+ * strategy.
+ */
+public class Log4JLogger implements Logger {
+ private org.apache.log4j.Logger m_Logger;
+
+ public Log4JLogger(org.apache.log4j.Logger log4jLogger) {
+ m_Logger = log4jLogger;
+ }
+
+ /**
+ * Log a debug message.
+ *
+ * @param message
+ * the message
+ */
+ public void debug(String message) {
+ m_Logger.debug(message);
+ }
+
+ /**
+ * Log a debug message.
+ *
+ * @param message
+ * the message
+ * @param throwable
+ * the throwable
+ */
+ public void debug(String message, Throwable throwable) {
+ m_Logger.debug(message, throwable);
+ }
+
+ /**
+ * Determine if messages of priority "debug" will be logged.
+ *
+ * @return true if "debug" messages will be logged
+ */
+ public boolean isDebugEnabled() {
+ return m_Logger.isDebugEnabled();
+ }
+
+ /**
+ * Log a info message.
+ *
+ * @param message
+ * the message
+ */
+ public void info(String message) {
+ m_Logger.info(message);
+ }
+
+ /**
+ * Log a info message.
+ *
+ * @param message
+ * the message
+ * @param throwable
+ * the throwable
+ */
+ public void info(String message, Throwable throwable) {
+ m_Logger.info(message, throwable);
+ }
+
+ /**
+ * Determine if messages of priority "info" will be logged.
+ *
+ * @return true if "info" messages will be logged
+ */
+ public boolean isInfoEnabled() {
+ return m_Logger.isInfoEnabled();
+ }
+
+ /**
+ * Log a warn message.
+ *
+ * @param message
+ * the message
+ */
+ public void warn(String message) {
+ m_Logger.warn(message);
+ }
+
+ /**
+ * Log a warn message.
+ *
+ * @param message
+ * the message
+ * @param throwable
+ * the throwable
+ */
+ public void warn(String message, Throwable throwable) {
+ m_Logger.warn(message, throwable);
+ }
+
+ /**
+ * Determine if messages of priority "warn" will be logged.
+ *
+ * @return true if "warn" messages will be logged
+ */
+ public boolean isWarnEnabled() {
+ return m_Logger.isEnabledFor(Level.WARN);
+ }
+
+ /**
+ * Log a error message.
+ *
+ * @param message
+ * the message
+ */
+ public void error(String message) {
+ m_Logger.error(message);
+ }
+
+ /**
+ * Log a error message.
+ *
+ * @param message
+ * the message
+ * @param throwable
+ * the throwable
+ */
+ public void error(String message, Throwable throwable) {
+ m_Logger.error(message, throwable);
+ }
+
+ /**
+ * Determine if messages of priority "error" will be logged.
+ *
+ * @return true if "error" messages will be logged
+ */
+ public boolean isErrorEnabled() {
+ return m_Logger.isEnabledFor(Level.ERROR);
+ }
+
+ /**
+ * Log a fatalError message.
+ *
+ * @param message
+ * the message
+ */
+ public void fatalError(String message) {
+ m_Logger.fatal(message);
+ }
+
+ /**
+ * Log a fatalError message.
+ *
+ * @param message
+ * the message
+ * @param throwable
+ * the throwable
+ */
+ public void fatalError(String message, Throwable throwable) {
+ m_Logger.fatal(message, throwable);
+ }
+
+ /**
+ * Determine if messages of priority "fatalError" will be logged.
+ *
+ * @return true if "fatalError" messages will be logged
+ */
+ public boolean isFatalErrorEnabled() {
+ return m_Logger.isEnabledFor(Level.FATAL);
+ }
+
+ /**
+ * Create a new child logger. The name of the child logger is
+ * [current-loggers-name].[passed-in-name] Throws
+ * <code>IllegalArgumentException</code> if name has an empty element name
+ *
+ * @param name
+ * the subname of this logger
+ * @return the new logger
+ */
+ public Logger getChildLogger(String name) {
+ String newName = m_Logger.getName() + "." + name;
+ org.apache.log4j.Logger childLog4JLogger = org.apache.log4j.Logger
+ .getLogger(newName);
+ Log4JLogger child = new Log4JLogger(childLog4JLogger);
+ return child;
+ }
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/Log4JLogger.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java?view=auto&rev=453285
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java
(added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java Thu
Oct 5 09:43:45 2006
@@ -0,0 +1,207 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf.impl;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.james.jspf.SPF;
+import org.apache.james.jspf.SPF1Utils;
+import org.apache.james.jspf.SPFResult;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+
+/**
+ * This class is used for commandline usage of JSPF
+ *
+ */
+public class SPFQuery {
+
+ private final static int PASS_RCODE = 0;
+
+ private final static int FAIL_RCODE = 1;
+
+ private final static int SOFTFAIL_RCODE = 2;
+
+ private final static int NEUTRAL_RCODE = 3;
+
+ private final static int TEMP_ERROR_RCODE = 4;
+
+ private final static int PERM_ERROR_RCODE = 5;
+
+ private final static int NONE_RCODE = 6;
+
+ private final static int UNKNOWN_RCODE = 255;
+
+ private final static String CMD_IP = "ip";
+
+ private final static String CMD_SENDER = "sender";
+
+ private final static String CMD_HELO = "helo";
+
+ private final static String CMD_DEBUG = "debug";
+
+ private final static String CMD_VERBOSE = "verbose";
+
+ private final static String CMD_DEFAULT_EXP = "defaultexplanation";
+
+ private final static String CMD_BEST_GUESS = "usebestguess";
+
+ private final static String CMD_TRUSTED_FORWARDER = "usetrusted";
+
+ private static Logger logger = Logger.getRootLogger();
+
+ /**
+ * @param args
+ * The commandline arguments to parse
+ */
+ public static void main(String[] args) {
+
+ String ip = null;
+ String sender = null;
+ String helo = null;
+ String defaultExplanation = null;
+ boolean useBestGuess = false;
+ boolean useTrustedForwarder = false;
+
+ SimpleLayout layout = new SimpleLayout();
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ logger.addAppender(consoleAppender);
+
+ logger.setLevel(Level.ERROR);
+
+ Options options = generateOptions();
+ CommandLineParser parser = new PosixParser();
+
+ try {
+ CommandLine line = parser.parse(options, args);
+
+ ip = line.getOptionValue(CMD_IP);
+ sender = line.getOptionValue(CMD_SENDER);
+ helo = line.getOptionValue(CMD_HELO);
+ defaultExplanation = line.getOptionValue(CMD_DEFAULT_EXP);
+ useBestGuess = line.hasOption(CMD_BEST_GUESS);
+ useTrustedForwarder = line.hasOption(CMD_TRUSTED_FORWARDER);
+ // check if all needed values was set
+ if (ip != null && sender != null && helo != null) {
+
+ if (line.hasOption(CMD_DEBUG))
+ logger.setLevel(Level.DEBUG);
+ if (line.hasOption(CMD_VERBOSE))
+ logger.setLevel(Level.TRACE);
+
+ SPF spf = new DefaultSPF(new Log4JLogger(logger));
+
+ // Check if we should set a costum default explanation
+ if (defaultExplanation != null) {
+ spf.setDefaultExplanation(defaultExplanation);
+ }
+
+ // Check if we should use best guess
+ if (useBestGuess == true) {
+ spf.setUseBestGuess(true);
+ }
+
+ if (useTrustedForwarder == true) {
+ spf.setUseTrustedForwarder(true);
+ }
+
+ SPFResult result = spf.checkSPF(ip, sender, helo);
+ System.out.println(result.getResult());
+ System.out.println(result.getHeader());
+ System.exit(getReturnCode(result.getResult()));
+
+ } else {
+ usage();
+ }
+ } catch (ParseException e) {
+ usage();
+ }
+ }
+
+ /**
+ * Return the generated Options
+ *
+ * @return options
+ */
+ private static Options generateOptions() {
+ Options options = new Options();
+ options.addOption(OptionBuilder.withLongOpt(CMD_IP).withValueSeparator(
+ '=').hasArg().create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_SENDER)
+ .withValueSeparator('=').hasArg().create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_HELO)
+ .withValueSeparator('=').hasArg().create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_DEFAULT_EXP)
+ .withValueSeparator('=').hasArg().create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_BEST_GUESS).create());
+
options.addOption(OptionBuilder.withLongOpt(CMD_TRUSTED_FORWARDER).create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_DEBUG).create());
+ options.addOption(OptionBuilder.withLongOpt(CMD_VERBOSE).create());
+ return options;
+ }
+
+ /**
+ * Print out the usage
+ */
+ private static void usage() {
+ // TODO: Use HelpFormatter for printing usage
+ System.out.println("Usage: java -jar jspf-x.jar --" + CMD_IP
+ + "=192.168.100.1 --" + CMD_SENDER + "[EMAIL PROTECTED] --"
+ + CMD_HELO + "=foo.bar [--" + CMD_DEFAULT_EXP
+ + "=\"explanation String\"] [--" + CMD_BEST_GUESS + "] [--"+
CMD_TRUSTED_FORWARDER +"]"
+ + CMD_DEBUG + "] [--" + CMD_VERBOSE + "]");
+ System.exit(UNKNOWN_RCODE);
+ }
+
+ /**
+ * Return the return code for the result
+ *
+ * @param result
+ * The result
+ * @return returnCode
+ */
+ private static int getReturnCode(String result) {
+
+ if (result.equals(SPF1Utils.PASS_CONV)) {
+ return PASS_RCODE;
+ } else if (result.equals(SPF1Utils.FAIL_CONV)) {
+ return FAIL_RCODE;
+ } else if (result.equals(SPF1Utils.SOFTFAIL_CONV)) {
+ return SOFTFAIL_RCODE;
+ } else if (result.equals(SPF1Utils.NEUTRAL_CONV)) {
+ return NEUTRAL_RCODE;
+ } else if (result.equals(SPF1Utils.TEMP_ERROR_CONV)) {
+ return TEMP_ERROR_RCODE;
+ } else if (result.equals(SPF1Utils.PERM_ERROR_CONV)) {
+ return PERM_ERROR_RCODE;
+ } else if (result.equals(SPF1Utils.NONE_CONV)) {
+ return NONE_RCODE;
+ }
+
+ return UNKNOWN_RCODE;
+ }
+
+}
Propchange:
james/jspf/trunk/src/main/java/org/apache/james/jspf/impl/SPFQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
URL:
http://svn.apache.org/viewvc/james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java?view=diff&rev=453285&r1=453284&r2=453285
==============================================================================
--- james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
(original)
+++ james/jspf/trunk/src/test/java/org/apache/james/jspf/LoggingDNSService.java
Thu Oct 5 09:43:45 2006
@@ -20,6 +20,7 @@
package org.apache.james.jspf;
import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.impl.DNSServiceXBillImpl;
import java.util.List;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]