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.jetty.*;
14 import org.ibex.crypto.*;
15 import org.ibex.jetty.*;
16 import javax.net.ssl.SSLServerSocket;
17 import javax.net.ssl.SSLServerSocketFactory;
18 import javax.net.ssl.SSLSocket;
22 public static void main(String[] s) throws Exception {
24 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
25 if (f.exists()) f.delete();
26 } catch (Exception e) { Log.error(Main.class, e); }
30 public void main() throws Exception {
31 if (System.getProperty("javax.net.ssl.keyStore")==null)
32 System.setProperty("javax.net.ssl.keyStore", Mailbox.STORAGE_ROOT+"/conf/ssl/ssl.keystore");
33 if (System.getProperty("javax.net.ssl.keyStorePassword")==null)
34 System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
35 SSLServerSocketFactory sslserversocketfactory =
36 (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
37 ServerSocket sslserversocket =
38 (ServerSocket) sslserversocketfactory.createServerSocket(9999);
39 ServerSocket sock143 = new ServerSocket(143);
40 ServerSocket sock119 = new ServerSocket(119);
41 ServerSocket sock25 = new ServerSocket(25);
42 ServerSocket sock8025 = new ServerSocket(8025);
43 ServerSocket sock993 = new ServerSocket(993);
44 ServerSocket sock563 = new ServerSocket(563);
45 //ServerSocket sock995 = new ServerSocket(995);
46 //ServerSocket sock113 = new ServerSocket(113);
50 try { Thread.sleep(500); } catch (Exception e) { }
52 File f = new File(Mailbox.STORAGE_ROOT + "/restart");
54 Log.error("RESTART", "restarting...");
57 } catch (Exception e) { Log.error(this, e); }
61 new Acceptor(sock143).start();
62 new Acceptor(sock119).start();
63 new Acceptor(sock25).start();
64 new Acceptor(sock8025).start();
65 new Acceptor(sock993).start();
66 new Acceptor(sock563).start();
67 //new Acceptor(sock995).start();
68 //new Acceptor(sock113).start();
71 private class Acceptor extends Thread {
72 private ServerSocket ss;
73 public Acceptor(ServerSocket ss) { this.ss = ss; }
77 final Socket s = ss.accept();
82 accept(new Connection(s, "megacz.com"));
83 } catch (Exception e) { Log.error(Main.class, e); }
86 } catch (Exception e) { Log.error(Main.class, e); }
88 } catch (Exception e) { Log.error(Main.class, e); }
92 public void accept(Connection conn) {
94 if (conn.getLocalPort() == 143) new IMAP.Listener(auth).handleRequest(conn);
95 else if (conn.getLocalPort() == 993) new IMAP.Listener(auth).handleRequest(conn);
96 else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn);
97 else if (conn.getLocalPort() == 563) new NNTP.Listener(auth).handleRequest(conn);
98 else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn);
99 else if (conn.getLocalPort() == 8025) SMTP.whitelist.handleRequest(conn);
100 //else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn);
101 //else if (conn.getLocalPort() == 995) new POP3.Listener(auth).handleRequest(conn);
102 //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
103 } catch (Stream.Closed c) {
104 Log.error(this, "connection abruptly closed by client");
105 } catch (IOException e) {
112 private static final Auth auth = new Auth();
113 private static class Auth implements Login {
114 private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "godel.megacz.com");
115 public Account anonymous() {
118 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
119 if (root==null) return null;
120 return new Account("anonymous", null, root){
121 public Mailbox getMailbox(Class protocol) {
122 return super.getMailbox(protocol);
125 } catch (Exception e) { throw new RuntimeException(e); }
127 public Object login(String user, String pass, Class protocol) { return login(user, pass); }
128 public Account login(String user, String pass) {
129 if (!EtcPasswd.verify(user, pass)) return null;
131 // currently broken, but should be used
132 //if (!ka.auth(user, pass)) return null;
135 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
136 return new Account(user, null, root.slash(user, true)){
137 public Mailbox getMailbox(Class protocol) {
138 return super.getMailbox(protocol);