major simplifications to Iterator api
[org.ibex.mail.git] / src / org / ibex / mail / protocol / SMTP.java
index 90fb2ec..35855f1 100644 (file)
@@ -19,8 +19,6 @@ import javax.naming.directory.*;
 // FIXME: loop prevention
 // FIXME: probably need some throttling on outbound mail
 
-// graylisting?
-
 // FEATURE: infer messageid, date, if not present (?)
 // FEATURE: exponential backoff on retry time?
 // FEATURE: RFC2822, section 4.5.1: special "postmaster" address
@@ -36,7 +34,10 @@ public class SMTP {
     public static final int GRAYLIST_MAXWAIT =  1000 * 60 * 60 * 24 * 5;  // five days
 
     public static final Graylist graylist =
-        new Graylist(Mailbox.STORAGE_ROOT+"/graylist.sqlite");
+        new Graylist(Mailbox.STORAGE_ROOT+"/db/graylist.sqlite");
+
+    public static final Whitelist whitelist =
+        new Whitelist(Mailbox.STORAGE_ROOT+"/db/whitelist.sqlite");
 
     public static final int MAX_MESSAGE_SIZE =
         Integer.parseInt(System.getProperty("org.ibex.mail.smtp.maxMessageSize", "-1"));
@@ -73,7 +74,7 @@ public class SMTP {
     // Server //////////////////////////////////////////////////////////////////////////////
 
     public static class Server {
-        public void handleRequest(Connection conn) {
+        public void handleRequest(Connection conn) throws IOException {
             conn.setTimeout(5 * 60 * 1000);
             conn.setNewline("\r\n");
             conn.println("220 " + conn.vhost + " SMTP " + this.getClass().getName());
@@ -83,7 +84,7 @@ public class SMTP {
             String remotehost = null;
             for(String command = conn.readln(); ; command = conn.readln()) try {
                 if (command == null) return;
-                Log.warn("**"+conn.getRemoteAddress()+"**", command);
+                //Log.warn("**"+conn.getRemoteAddress()+"**", command);
                 String c = command.toUpperCase();
                 if (c.startsWith("HELO"))        {
                     remotehost = c.substring(5).trim();
@@ -126,6 +127,7 @@ public class SMTP {
                     } else {
                         conn.println("551 sorry, " + addr + " is not on this machine");
                     }
+                    conn.flush();
                 } else if (c.startsWith("DATA")) {
                     //if (from == null) { conn.println("503 MAIL FROM command must precede DATA"); continue; }
                     if (to == null || to.size()==0) { conn.println("503 RCPT TO command must precede DATA"); continue; }
@@ -189,11 +191,6 @@ public class SMTP {
                     } catch (MailException.Malformed mfe) {   conn.println("501 " + mfe.toString());
                     } catch (MailException.MailboxFull mbf) { conn.println("452 " + mbf);
                     } catch (Later.LaterException le) {       conn.println("453 try again later");
-                    } catch (IOException ioe) {               
-                        //conn.println("554 " + ioe.toString());
-                        Log.error(this, ioe);
-                        conn.close();
-                        return;
                     }
                 } else                    { conn.println("500 unrecognized command"); }                    
             } catch (Message.Malformed e) { conn.println("501 " + e.toString()); }
@@ -220,7 +217,7 @@ public class SMTP {
                 }
             }
             synchronized(Outgoing.class) {
-                spool.add(m);
+                spool.insert(m, Mailbox.Flag.defaultFlags);
                 Outgoing.class.notifyAll();
             }
         }