X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FGraylist.java;h=1f65dd40a6b2fe50bb30fbff25a381e4cfbfc623;hb=5de1642861c256fd64b5e82826a9e24dd7c8688e;hp=06280626ece5c578e90d536ec015f9ec970bacba;hpb=d4992c14617d75464730affbe66be45fa07463e4;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Graylist.java b/src/org/ibex/mail/Graylist.java index 0628062..1f65dd4 100644 --- a/src/org/ibex/mail/Graylist.java +++ b/src/org/ibex/mail/Graylist.java @@ -7,21 +7,13 @@ import java.io.*; import java.util.*; import java.sql.Timestamp; -public class Graylist { +public class Graylist extends SqliteDB { - private Connection conn; - - public Graylist(String filename) { - try { - Class.forName("org.sqlite.JDBC"); - conn = DriverManager.getConnection("jdbc:sqlite:"+filename); - conn.prepareStatement("create table if not exists "+ - "'whitelist' (ip unique)").executeUpdate(); - conn.prepareStatement("create table if not exists "+ - "'graylist' (ip,fromaddr,toaddr,date, primary key(ip,fromaddr,toaddr))").executeUpdate(); - } - catch (SQLException e) { throw new RuntimeException(e); } - catch (ClassNotFoundException e) { throw new RuntimeException(e); } + public Graylist(String filename) throws SQLException { + super(filename); + SqliteTable whitelist = getTable("whitelist", "(ip unique)"); + SqliteTable graylist = getTable("graylist", "(ip,fromaddr,toaddr,date,PRIMARY KEY(ip,fromaddr,toaddr))"); + graylist.reap("date"); } public synchronized void addWhitelist(InetAddress ip) { @@ -45,7 +37,7 @@ public class Graylist { try { PreparedStatement check = conn.prepareStatement("select date from graylist where ip=? and fromaddr=? and toaddr=?"); - check.setString(1, ip.getHostAddress()); + check.setString(1, graylistAddress(ip)); check.setString(2, from); check.setString(3, to); ResultSet rs = check.executeQuery(); @@ -58,7 +50,7 @@ public class Graylist { try { PreparedStatement check = conn.prepareStatement("insert or replace into graylist (ip,fromaddr,toaddr,date) values(?,?,?,?)"); - check.setString(1, ip.getHostAddress()); + check.setString(1, graylistAddress(ip)); check.setString(2, from); check.setString(3, to); check.setTimestamp(4, new Timestamp(date)); @@ -66,5 +58,19 @@ public class Graylist { } catch (SQLException e) { throw new RuntimeException(e); } } + // + // this is mostly to deal with comcast's pathetic retry policy and + // rotating pool of outbound servers + // see: http://lists.puremagic.com/pipermail/greylist-users/2006-November/001255.html + // + private static String graylistAddress(InetAddress ipa) { + byte[] ip = ipa.getAddress(); + return + (ip[0] & 0xff)+"."+ + (ip[1] & 0xff)+"."+ + (ip[2] & 0xff)+"."+ + ".0"; + } + }