Author: norman
Date: Fri Sep 28 23:49:03 2007
New Revision: 580552
URL: http://svn.apache.org/viewvc?rev=580552&view=rev
Log:
Upgrade jSPF version to last released version
Add SPF mailet
Added:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java
(with props)
james/server/trunk/stage/org.apache.james/jars/apache-jspf-0.9.5.jar
(with props)
Removed:
james/server/trunk/stage/org.apache.james/jars/jspf-0.9-SNAPSHOT.jar
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
Modified:
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=580552&r1=580551&r2=580552&view=diff
==============================================================================
---
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
(original)
+++
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
Fri Sep 28 23:49:03 2007
@@ -27,10 +27,11 @@
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.james.jspf.SPF;
-import org.apache.james.jspf.SPF1Utils;
-import org.apache.james.jspf.SPFResult;
+import org.apache.james.jspf.impl.DefaultSPF;
+import org.apache.james.jspf.impl.SPF;
import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.exceptions.SPFErrorConstants;
+import org.apache.james.jspf.executor.SPFResult;
import org.apache.james.smtpserver.CommandHandler;
import org.apache.james.smtpserver.MessageHandler;
import org.apache.james.smtpserver.SMTPSession;
@@ -110,9 +111,9 @@
*/
public void initialize() throws Exception {
if (dnsService == null) {
- spf = new SPF(new SPFLogger(getLogger()));
+ spf = new DefaultSPF(new SPFLoggerAdapter(getLogger()));
} else {
- spf = new SPF(dnsService, new SPFLogger(getLogger()));
+ spf = new SPF(dnsService, new SPFLoggerAdapter(getLogger()));
}
}
@@ -210,17 +211,17 @@
+ " = " + spfResult);
// Check if we should block!
- if ((spfResult.equals(SPF1Utils.FAIL_CONV))
- || (spfResult.equals(SPF1Utils.SOFTFAIL_CONV) &&
blockSoftFail)
- || (spfResult.equals(SPF1Utils.PERM_ERROR_CONV) &&
blockPermError)) {
+ if ((spfResult.equals(SPFErrorConstants.FAIL_CONV))
+ || (spfResult.equals(SPFErrorConstants.SOFTFAIL_CONV)
&& blockSoftFail)
+ ||
(spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV) && blockPermError)) {
- if (spfResult.equals(SPF1Utils.PERM_ERROR_CONV)) {
+ if (spfResult.equals(SPFErrorConstants.PERM_ERROR_CONV)) {
explanation = "Block caused by an invalid SPF record";
}
session.getState().put(SPF_DETAIL, explanation);
session.getState().put(SPF_BLOCKLISTED, "true");
- } else if (spfResult.equals(SPF1Utils.TEMP_ERROR_CONV)) {
+ } else if
(spfResult.equals(SPFErrorConstants.TEMP_ERROR_CONV)) {
session.getState().put(SPF_TEMPBLOCKLISTED, "true");
}
}
@@ -300,22 +301,20 @@
return data;
}
-
/**
* Inner class to provide a wrapper for loggin to avalon
*/
- class SPFLogger implements org.apache.james.jspf.core.Logger {
+ private class SPFLoggerAdapter implements
org.apache.james.jspf.core.Logger {
/**
* Avalon Logger
*/
- org.apache.avalon.framework.logger.Logger logger;
+ private org.apache.avalon.framework.logger.Logger logger;
- SPFLogger(org.apache.avalon.framework.logger.Logger logger) {
+ public SPFLoggerAdapter(org.apache.avalon.framework.logger.Logger
logger) {
this.logger = logger;
}
-
-
+
/**
* @see org.apache.james.jspf.core.Logger#debug(String)
*/
@@ -425,8 +424,9 @@
* @see org.apache.james.jspf.core.Logger#getChildLogger(String)
*/
public org.apache.james.jspf.core.Logger getChildLogger(String arg0) {
- return new SPFLogger(logger.getChildLogger(arg0));
+ return new SPFLoggerAdapter(logger.getChildLogger(arg0));
}
}
+
}
Added:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java?rev=580552&view=auto
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java
(added)
+++
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java
Fri Sep 28 23:49:03 2007
@@ -0,0 +1,178 @@
+/****************************************************************
+ * 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.transport.mailets;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.Logger;
+import org.apache.james.jspf.executor.SPFResult;
+import org.apache.james.jspf.impl.DefaultSPF;
+import org.apache.mailet.GenericMailet;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+
+/**
+ * Check the ip, sender, helo against SPF.
+ * Add the following attributes to the mail object:
+ *
+ * org.apache.james.transport.mailets.spf.explanation
+ * org.apache.james.transport.mailets.spf.result
+ *
+ * Sample configuration:
+ *
+ * <mailet match="All" class="SPF">
+ * <addHeader>true</addHeader>
+ * <debug>false</debug>
+ * </mailet>
+ */
+public class SPF extends GenericMailet {
+ private boolean addHeader = false;
+ private org.apache.james.jspf.impl.SPF spf;
+ public final static String EXPLANATION_ATTRIBUTE =
"org.apache.james.transport.mailets.spf.explanation";
+ public final static String RESULT_ATTRIBUTE =
"org.apache.james.transport.mailets.spf.result";
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.mailet.GenericMailet#init()
+ */
+ public void init() {
+ addHeader = new Boolean(getInitParameter("addHeader", "false"))
+ .booleanValue();
+ SPFLoggerAdapter logger = new SPFLoggerAdapter(new Boolean(
+ getInitParameter("debug", "false")).booleanValue());
+
+ spf = new DefaultSPF(logger);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.mailet.GenericMailet#service(org.apache.mailet.Mail)
+ */
+ public void service(Mail mail) throws MessagingException {
+ String sender = null;
+ MailAddress senderAddr = mail.getSender();
+ String remoteAddr = mail.getRemoteAddr();
+ String helo = mail.getRemoteHost();
+
+ if (remoteAddr.equals("127.0.0.1") == false) {
+ if (senderAddr != null) {
+ sender = senderAddr.toString();
+ } else {
+ sender = "";
+ }
+ SPFResult result = spf.checkSPF(remoteAddr, sender, helo);
+ mail.setAttribute(EXPLANATION_ATTRIBUTE, result.getExplanation());
+ mail.setAttribute(RESULT_ATTRIBUTE, result.getResult());
+
+ log("ip:" + remoteAddr + " from:" + sender + " helo:" + helo
+ + " = " + result.getResult());
+ if (addHeader) {
+ try {
+ MimeMessage msg = mail.getMessage();
+ msg.addHeader(result.getHeaderName(), result
+ .getHeaderText());
+ msg.saveChanges();
+ } catch (MessagingException e) {
+ // Ignore not be able to add headers
+ }
+ }
+ }
+ }
+
+ private class SPFLoggerAdapter implements Logger {
+ private boolean debug = false;
+
+ public SPFLoggerAdapter(boolean debug) {
+
+ }
+
+ public void debug(String arg0) {
+ if (debug) {
+ log(arg0);
+ }
+ }
+
+ public void debug(String arg0, Throwable arg1) {
+ if (debug) {
+ log(arg0, arg1);
+ }
+ }
+
+ public void error(String arg0) {
+ log(arg0);
+ }
+
+ public void error(String arg0, Throwable arg1) {
+ log(arg0, arg1);
+ }
+
+ public void fatalError(String arg0) {
+ log(arg0);
+ }
+
+ public void fatalError(String arg0, Throwable arg1) {
+ log(arg0, arg1);
+ }
+
+ public Logger getChildLogger(String arg0) {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ public void info(String arg0) {
+ log(arg0);
+ }
+
+ public void info(String arg0, Throwable arg1) {
+ log(arg0, arg1);
+ }
+
+ public boolean isDebugEnabled() {
+ return debug;
+ }
+
+ public boolean isErrorEnabled() {
+ return true;
+ }
+
+ public boolean isFatalErrorEnabled() {
+ return true;
+ }
+
+ public boolean isInfoEnabled() {
+ return true;
+ }
+
+ public boolean isWarnEnabled() {
+ return true;
+ }
+
+ public void warn(String arg0) {
+ log(arg0);
+ }
+
+ public void warn(String arg0, Throwable arg1) {
+ log(arg0, arg1);
+ }
+
+ }
+
+}
Propchange:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/SPF.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/trunk/stage/org.apache.james/jars/apache-jspf-0.9.5.jar
URL:
http://svn.apache.org/viewvc/james/server/trunk/stage/org.apache.james/jars/apache-jspf-0.9.5.jar?rev=580552&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/stage/org.apache.james/jars/apache-jspf-0.9.5.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]