Whitelist.java: never send a challenge in response to a List-Id or List-Post
[org.ibex.mail.git] / src / org / ibex / mail / Whitelist.java
index 81e4b64..9842320 100644 (file)
@@ -17,8 +17,11 @@ public class Whitelist extends SqliteDB {
     public Whitelist(String filename) throws SQLException {
         super(filename);
         SqliteTable whitelist = getTable("whitelist", "(email)");
+        whitelist.createIndex("email");
         SqliteTable pending   = getTable("pending",   "(spamid,email,message,date)");
         pending.reap("date");
+        pending.createIndex("spamid");
+        pending.createIndex("email");
     }
 
     public boolean handleRequest(org.ibex.net.Connection c) {
@@ -96,6 +99,9 @@ public class Whitelist extends SqliteDB {
                     a = m.envelopeFrom;
                     if (a!=null) addWhitelist(a);
                     hsm.add(m);
+                    if (m.cc != null) for(Address aa : m.cc) {
+                        if (aa!= null) addWhitelist(aa);
+                    }
                 } while (rs.next());
             }
             for(Message m : hsm)
@@ -135,6 +141,10 @@ public class Whitelist extends SqliteDB {
                          "with Auto-Submitted=\""+m.headers.get("Auto-Submitted")+"\"");
                 return;
             }
+            if (m.headers.get("List-Id") != null || m.headers.get("List-Post") != null) {
+                Log.warn(this, "refusing to send a challenge to a message with a List-Id or List-Post header");
+                return;
+            }
 
             Address from = Address.parse("adam@megacz.com");
 
@@ -213,18 +223,12 @@ public class Whitelist extends SqliteDB {
                 PreparedStatement add = conn.prepareStatement("insert into pending values(?,?,?,?)");
                 add.setString(1, messageid);
                 add.setString(2, to.toString(false));
-                add.setString(3, streamToString(m.getStream()));
+                add.setString(3, SqliteDB.streamToString(m.getStream()));
                 add.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
                 add.executeUpdate();
             }
         } catch (Exception e) { throw new RuntimeException(e); }
     }
 
-    private static String streamToString(Stream stream) throws Exception {
-        StringBuffer b = new StringBuffer();
-        for(String s = stream.readln(); s!=null; s=stream.readln())
-            b.append(s+"\n");
-        return b.toString();
-    }
 }