1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
6 import org.ibex.mail.target.*;
7 import org.ibex.mail.protocol.*;
8 import org.ibex.util.*;
9 import org.ibex.jinetd.*;
10 import org.ibex.jetty.*;
15 import org.ibex.crypto.*;
16 import org.ibex.jetty.*;
18 public class Main implements Listener {
20 public static void main(String[] s) throws Exception {
22 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
23 if (f.exists()) f.delete();
24 } catch (Exception e) { Log.error(Main.class, e); }
28 public void main() throws Exception {
29 ServerSocket sock143 = new ServerSocket(143);
30 ServerSocket sock119 = new ServerSocket(119);
31 ServerSocket sock25 = new ServerSocket(25);
35 try { Thread.sleep(500); } catch (Exception e) { }
37 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
39 Log.error("RESTART", "restarting...");
42 } catch (Exception e) { Log.error(this, e); }
46 new Acceptor(sock143).start();
47 new Acceptor(sock119).start();
48 new Acceptor(sock25).start();
51 private class Acceptor extends Thread {
52 private ServerSocket ss;
53 public Acceptor(ServerSocket ss) { this.ss = ss; }
57 final Socket s = ss.accept();
62 accept(new Connection(s, "megacz.com"));
63 } catch (Exception e) { Log.error(Main.class, e); }
66 } catch (Exception e) { Log.error(Main.class, e); }
68 } catch (Exception e) { Log.error(Main.class, e); }
72 public boolean accept(Connection conn) {
74 if (conn.getLocalPort() == 143) new IMAP.Listener(auth).handleRequest(conn);
75 else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
76 else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn);
77 //else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn);
78 //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
86 private static final Auth auth = new Auth();
87 private static class Auth implements Login {
88 public Account anonymous() {
91 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
92 if (root==null) return null;
93 return new Account("anonymous", null, root){
94 public Mailbox getMailbox(Class protocol) {
95 return super.getMailbox(protocol);
98 } catch (Exception e) { throw new RuntimeException(e); }
100 public Object login(String user, String pass, Class protocol) { return login(user, pass); }
101 public Account login(String user, String pass) {
102 if (!EtcPasswd.verify(user, pass)) return null;
104 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
105 return new Account(user, null, root.slash(user, true)){
106 public Mailbox getMailbox(Class protocol) {
107 return super.getMailbox(protocol);