import org.ibex.mail.target.*;
import org.ibex.mail.protocol.*;
import org.ibex.util.*;
+import org.ibex.jinetd.*;
+import org.ibex.io.*;
import java.io.*;
import java.net.*;
import java.util.*;
+import org.ibex.crypto.*;
-public class Main {
+public class Main implements Listener {
- public static void main(String[] s) throws Exception {
-
- // set up logging
- String logto = System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
- logto += File.separatorChar + "log";
- Log.file(logto);
-
- new IMAPThread().start();
- new SMTPThread().start();
-
- }
-
- private static class BogusAuthenticator implements IMAP.Server.Authenticator {
- final Mailbox root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
- public Mailbox authenticate(String u, String p) {
- if (u.equals("megacz") && p.equals("pass")) return root;
- return null;
- }
- }
-
- private static class IMAPThread extends Thread {
- final int port = Integer.parseInt(System.getProperty("ibex.mail.imap.port", "143"));
- public void run() {
- try {
- Log.info(this, "binding to port " + port + "...");
- ServerSocket ss = new ServerSocket(port);
- Log.info(this, "listening for connections...");
- for(;;) {
- final Socket sock = ss.accept();
- new Thread() {
- public void run() {
- try {
- new IMAP.Listener(sock, "megacz.com", new BogusAuthenticator()).handle();
- } catch (Exception e) {
- Log.warn(this, e);
- }
- }
- }.start();
- }
- } catch (Exception e) {
- Log.warn(this, e);
- }
+ public void accept(Connection conn) {
+ Log.error(this, "connection port is " + conn.getLocalPort());
+ if (conn.getLocalPort() == 25) {
+ new SMTP.Server().handleRequest(conn);
+ } else if (conn.getLocalPort() == 143) {
+ new IMAP.Listener().handleRequest(conn);
}
}
- private static class SMTPThread extends Thread {
- final int port = Integer.parseInt(System.getProperty("ibex.mail.smtp.port", "25"));
- public void run() {
- try {
- Log.info(this, "binding to port " + port + "...");
- ServerSocket ss = new ServerSocket(port);
- Log.info(this, "listening for connections...");
- while(true) {
- final Socket sock = ss.accept();
- final SMTP.Server smtp = new SMTP.Server(sock, "megacz.com");
- new Thread() {
- public void run() {
- try {
- smtp.handle();
- } catch (Exception e) {
- Log.warn(this, e);
- }
- }
- }.start();
- }
- } catch (Exception e) {
- Log.warn(this, e);
- }
- }
- }
}