path fixes
[org.ibex.mail.git] / src / org / ibex / mail / Main.java
index edc22c0..d8d7562 100644 (file)
@@ -1,21 +1,32 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
 package org.ibex.mail;
 import org.ibex.mail.target.*;
 import org.ibex.mail.protocol.*;
 import org.ibex.util.*;
 import org.ibex.jinetd.*;
+import org.ibex.jetty.*;
 import org.ibex.io.*;
 import java.io.*;
 import java.net.*;
 import java.util.*;
 import org.ibex.crypto.*;
+import org.ibex.jetty.*;
 
 public class Main implements Listener {
 
-    public void accept(Connection conn) {
+    public boolean accept(Connection conn) {
         try {
-            if (conn.getLocalPort() == 25)       new SMTP.Server().handleRequest(conn);
-            else if (conn.getLocalPort() == 143) new IMAP.Listener(auth).handleRequest(conn);
-            else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
+            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() == 110)  new POP3.Listener(auth).handleRequest(conn);
+            //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
+           else return false;
+           return true;
         } finally {
             conn.close();
         }
@@ -23,26 +34,26 @@ public class Main implements Listener {
 
     private static final Auth auth = new Auth();
     private static class Auth implements Login {
-        final Mailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true).slash("user", true);
-        public Account anonymous() { return null; }
+        public Account anonymous() {
+            try {
+                final Mailbox root =
+                    FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
+                if (root==null) return null;
+                return new Account("anonymous", null, root){
+                    public Mailbox getMailbox(Class protocol) {
+                        return super.getMailbox(protocol);
+                    }
+                };
+            } catch (Exception e) { throw new RuntimeException(e); }
+        }
+        public Object login(String user, String pass, Class protocol) { return login(user, pass); }
         public Account login(String user, String pass) {
             if (!EtcPasswd.verify(user, pass)) return null;
+            final Mailbox root =
+                FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
             return new Account(user, null, root.slash(user, true)){
                     public Mailbox getMailbox(Class protocol) {
-                        if (protocol == NNTP.class) {
-                            final Mailbox arch = new MailmanArchives();
-                            return new Mailbox.Default() {
-                                    public void add(Message m) { throw new RuntimeException("not supported"); }
-                                    public void add(Message m, int i) { throw new RuntimeException("not supported"); }
-                                    public int              uidValidity()  { return 1; }
-                                    public Mailbox.Iterator iterator()     { return null; }
-                                    public int              uidNext()      { return 0; }
-                                    public String[] children() { return new String[] { "us" }; }
-                                    public Mailbox slash(String name, boolean create) { return arch; }
-                                };
-                        } else {
-                            return super.getMailbox(protocol);
-                        }
+                        return super.getMailbox(protocol);
                     }
                 };
         }