X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fmail%2FMain.java;h=f354734c415d0e77e648d023594eaf7a1d83ec70;hb=9a82f176e6cd96b6a2dc081a27ef124ce23d3307;hp=5898f552e8ab7f95656a5820db5d34b02d56ab2c;hpb=684ee6c79114e33aedcbcf69a20dc8b310b543a2;p=org.ibex.mail.git diff --git a/src/org/ibex/mail/Main.java b/src/org/ibex/mail/Main.java index 5898f55..f354734 100644 --- a/src/org/ibex/mail/Main.java +++ b/src/org/ibex/mail/Main.java @@ -1,22 +1,113 @@ +// 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 org.ibex.net.*; import java.io.*; import java.net.*; import java.util.*; import org.ibex.crypto.*; +import org.ibex.jetty.*; +import javax.net.ssl.SSLServerSocket; +import javax.net.ssl.SSLServerSocketFactory; +import javax.net.ssl.SSLSocket; + +public class Main { + + public static void main(String[] s) throws Exception { + try { + File f = new File(Mailbox.STORAGE_ROOT + "/restart"); + if (f.exists()) f.delete(); + } catch (Exception e) { Log.error(Main.class, e); } + new Main().main(); + } -public class Main implements Listener { + public void main() throws Exception { + if (System.getProperty("javax.net.ssl.keyStore")==null) + System.setProperty("javax.net.ssl.keyStore", Mailbox.STORAGE_ROOT+"/conf/ssl/ssl.keystore"); + if (System.getProperty("javax.net.ssl.keyStorePassword")==null) + System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); + SSLServerSocketFactory sslserversocketfactory = + (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); + ServerSocket sslserversocket = (ServerSocket) sslserversocketfactory.createServerSocket(9999); + ServerSocket sock8025 = new ServerSocket(8025); + ServerSocket sock143 = new ServerSocket(143); + ServerSocket sock119 = new ServerSocket(119); + ServerSocket sock25 = new ServerSocket(25); + ServerSocket sock465 = (ServerSocket) sslserversocketfactory.createServerSocket(465); + ServerSocket sock993 = (ServerSocket) sslserversocketfactory.createServerSocket(993); + ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563); + //ServerSocket sock995 = new ServerSocket(995); + //ServerSocket sock113 = new ServerSocket(113); + new Thread() { + public void run() { + while(true) { + try { Thread.sleep(500); } catch (Exception e) { } + try { + File f = new File(Mailbox.STORAGE_ROOT + "/restart"); + if (f.exists()) { + Log.error("RESTART", "restarting..."); + System.exit(0); + } + } catch (Exception e) { Log.error(this, e); } + } + } + }.start(); + new Acceptor(sock143).start(); + new Acceptor(sock119).start(); + new Acceptor(sock25).start(); + new Acceptor(sock465).start(); + new Acceptor(sock8025).start(); + new Acceptor(sock993).start(); + new Acceptor(sock563).start(); + //new Acceptor(sock995).start(); + //new Acceptor(sock113).start(); + } + + private class Acceptor extends Thread { + private ServerSocket ss; + public Acceptor(ServerSocket ss) { this.ss = ss; } + public void run() { + try { + ss.setReuseAddress(true); + + 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 void 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() == 993) new IMAP.Listener(auth).handleRequest(conn); else if (conn.getLocalPort() == 119) new NNTP.Listener(auth).handleRequest(conn); - else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn); + else if (conn.getLocalPort() == 563) new NNTP.Listener(auth).handleRequest(conn); + else if (conn.getLocalPort() == 25) new SMTP.Server().handleRequest(conn); + else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn); + else if (conn.getLocalPort() == 465) new SMTP.Server().handleRequest(conn); + else if (conn.getLocalPort() == 8025) SMTP.whitelist.handleRequest(conn); + //else if (conn.getLocalPort() == 110) new POP3.Listener(auth).handleRequest(conn); + //else if (conn.getLocalPort() == 995) new POP3.Listener(auth).handleRequest(conn); + //else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn); + } catch (Stream.Closed c) { + Log.error(this, "connection abruptly closed by client"); + } catch (IOException e) { + Log.error(this, e); } finally { conn.close(); } @@ -24,31 +115,31 @@ public class Main implements Listener { private static final Auth auth = new Auth(); private static class Auth implements Login { - public Account anonymous() { return null; } - public Object login(String user, String pass, Class protocol) { - if (protocol == IMAP.class && user.endsWith("@gmail.com")) return GMail.getGMail(user, pass).getIMAP(); - return login(user, pass); + private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "godel.megacz.com"); + 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 (user.indexOf("@gmail.com") != -1) return GMail.getGMail(user, pass); if (!EtcPasswd.verify(user, pass)) return null; - final Mailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true).slash("user", true); + + // currently broken, but should be used + //if (!ka.auth(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); } }; }