add support for standalone operation
authoradam <adam@megacz.com>
Sun, 21 Jan 2007 23:09:34 +0000 (23:09 +0000)
committeradam <adam@megacz.com>
Sun, 21 Jan 2007 23:09:34 +0000 (23:09 +0000)
darcs-hash:20070121230934-5007d-2f6872706b1bbb9512dd739418046439dc18b09e.gz

src/org/ibex/mail/Main.java

index d8d7562..e4971ed 100644 (file)
@@ -17,12 +17,45 @@ import org.ibex.jetty.*;
 
 public class Main implements Listener {
 
+    public static void main(String[] s) throws Exception {
+        new Main().main();
+    }
+
+    public void main() throws Exception {
+        ServerSocket sock143 = new ServerSocket(143);
+        ServerSocket sock119 = new ServerSocket(119);
+        ServerSocket sock25  = new ServerSocket(25);
+        new Acceptor(sock143).start();
+        new Acceptor(sock119).start();
+        new Acceptor(sock25).start();
+    }
+
+    private class Acceptor extends Thread {
+        private ServerSocket ss;
+        public Acceptor(ServerSocket ss) { this.ss = ss; }
+        public void run() {
+            try {
+                while(true) {
+                    final Socket s = ss.accept();
+                    try {
+                        new Thread() {
+                            public void run() {
+                                try {
+                                    accept(new Connection(s, "megacz.com"));
+                                } catch (Exception e) { Log.error(Main.class, e); }
+                            }
+                        }.start();
+                    } catch (Exception e) { Log.error(Main.class, e); }
+                }
+            } catch (Exception e) { Log.error(Main.class, e); }
+        }
+    }
+
     public boolean accept(Connection conn) {
         try {
             if      (conn.getLocalPort() == 143)  new IMAP.Listener(auth).handleRequest(conn);
-            else if (conn.getLocalPort() == 25)   new SMTP.Server().handleRequest(conn);
-            else if (conn.getLocalPort() == 8080) new SMTP.Server().handleRequest(conn);
             else if (conn.getLocalPort() == 119)  new NNTP.Listener(auth).handleRequest(conn);
+            else if (conn.getLocalPort() == 25)   new SMTP.Server().handleRequest(conn);
             //else if (conn.getLocalPort() == 110)  new POP3.Listener(auth).handleRequest(conn);
             //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
            else return false;