You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/08/16 15:49:33 UTC
svn commit: r431900 -
/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java
Author: norman
Date: Wed Aug 16 06:49:32 2006
New Revision: 431900
URL: http://svn.apache.org/viewvc?rev=431900&view=rev
Log:
Fix a bug which caused that the count and createtimestamo was never resetted.
Modified:
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java
Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java?rev=431900&r1=431899&r2=431900&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/GreylistHandler.java Wed Aug 16 06:49:32 2006
@@ -28,6 +28,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.sql.Timestamp;
@@ -77,10 +78,6 @@
// 4 hours
private long unseenLifeTime = 14400000;
- private long createTimeStamp = 0;
-
- private int count = 0;
-
private String selectQuery;
private String insertQuery;
@@ -289,26 +286,6 @@
}
/**
- * Setup the createTimeStamp
- *
- * @param createTimeStamp
- * the create time stamp in ms
- */
- public void setCreateTimeStamp(long createTimeStamp) {
- this.createTimeStamp = createTimeStamp;
- }
-
- /**
- * Setup the count
- *
- * @param count
- * The count
- */
- public void setCount(int count) {
- this.count = count;
- }
-
- /**
* @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
*/
public void onCommand(SMTPSession session) {
@@ -346,8 +323,19 @@
String ipAddress = session.getRemoteIPAddress();
try {
- // get the timesamp when he triplet was last seen
- setupGreyListData(datasource.getConnection(), ipAddress, sender, recip);
+ long createTimeStamp = 0;
+ int count = 0;
+
+ // get the timestamp when he triplet was last seen
+ Iterator data = getGreyListData(datasource.getConnection(), ipAddress, sender, recip);
+
+ if (data.hasNext()) {
+ createTimeStamp = Long.parseLong(data.next().toString());
+ count = Integer.parseInt(data.next().toString());
+ }
+
+ getLogger().debug("Triplet " + ipAddress + " | " + sender + " | " + recip +" -> TimeStamp: " + createTimeStamp);
+
// if the timestamp is bigger as 0 we have allready a triplet stored
if (createTimeStamp > 0) {
@@ -362,8 +350,12 @@
session.setStopHandlerProcessing(true);
} else {
+
+ getLogger().debug("Update triplet " + ipAddress + " | " + sender + " | " + recip + " -> timestamp: " + time);
+
// update the triplet..
updateTriplet(datasource.getConnection(), ipAddress, sender, recip, count, time);
+
}
} else {
getLogger().debug("New triplet " + ipAddress + " | " + sender + " | " + recip );
@@ -382,6 +374,9 @@
// some kind of random cleanup process
if (Math.random() > 0.99) {
// cleanup old entries
+
+ getLogger().debug("Delete old entries");
+
cleanupAutoWhiteListGreyList(datasource.getConnection(),(time - autoWhiteListLifeTime));
cleanupGreyList(datasource.getConnection(), (time - unseenLifeTime));
}
@@ -393,7 +388,7 @@
}
/**
- * Setup all necessary data for greylisting based on provided triplet
+ * Get all necessary data for greylisting based on provided triplet
*
* @param conn
* The Connection
@@ -403,11 +398,13 @@
* The mailFrom
* @param recip
* The rcptTo
+ * @return data
+ * The data
* @throws SQLException
*/
- private void setupGreyListData(Connection conn, String ipAddress,
+ private Iterator getGreyListData(Connection conn, String ipAddress,
String sender, String recip) throws SQLException {
-
+ Collection data = new ArrayList(2);
PreparedStatement mappingStmt = null;
try {
mappingStmt = conn.prepareStatement(selectQuery);
@@ -419,8 +416,8 @@
mappingRS = mappingStmt.executeQuery();
if (mappingRS.next()) {
- setCreateTimeStamp(mappingRS.getTimestamp(1).getTime());
- setCount(mappingRS.getInt(2));
+ data.add(String.valueOf(mappingRS.getTimestamp(1).getTime()));
+ data.add(String.valueOf(mappingRS.getInt(2)));
}
} finally {
theJDBCUtil.closeJDBCResultSet(mappingRS);
@@ -429,6 +426,7 @@
theJDBCUtil.closeJDBCStatement(mappingStmt);
theJDBCUtil.closeJDBCConnection(conn);
}
+ return data.iterator();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org