mail overhaul
[org.ibex.mail.git] / src / org / ibex / mail / Main.java
1 package org.ibex.mail;
2 import org.ibex.mail.target.*;
3 import org.ibex.mail.protocol.*;
4 import org.ibex.util.*;
5 import java.io.*;
6 import java.net.*;
7 import java.util.*;
8
9 public class Main {
10
11     /*
12     public static class Resin {
13         new extends com.caucho.server.port.Protocol() {
14             public String getProtocolName() { return "imap"; }
15             public com.caucho.server.port.ServerRequest createRequest(com.caucho.server.connection.Connection conn) {
16                 try {
17                     return new Listener(conn);
18                 } catch (Exception e) {
19                     Log.error(this, e);
20                     return null;
21                 }
22             }
23         }
24
25     public SMTP() { }
26     public String getProtocolName() { return "smtp"; }
27     public com.caucho.server.port.ServerRequest createRequest(com.caucho.server.connection.Connection conn) {
28         try {
29             return new Server(conn);
30         } catch (Exception e) {
31             Log.error(this, e);
32             return null;
33         }
34     }
35
36     }
37
38     public static void main(String[] s) throws Exception {
39
40         // set up logging
41         String logto = System.getProperty("ibex.mail.root", File.separatorChar + "var" + File.separatorChar + "org.ibex.mail");
42         logto += File.separatorChar + "log";
43
44         //Log.file(logto);
45         Log.color = true;
46
47         new IMAPThread().start();
48         new SMTPThread().start();
49
50     }
51     */
52     public static class BogusAuthenticator implements IMAP.Server.Authenticator {
53         final Mailbox root =
54             FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true).slash("user", true).slash("megacz", true);
55         public Mailbox authenticate(String u, String p) {
56             if (u.equals("megacz") && p.equals("pass")) return root;
57             return null;
58         }
59     }
60     /*
61     private static class IMAPThread extends Thread {
62         final int port = Integer.parseInt(System.getProperty("ibex.mail.imap.port", "143"));
63         public void run() {
64             try {
65                 Log.info(this, "binding to port " + port + "...");
66                 ServerSocket ss = new ServerSocket(port);
67                 Log.info(this, "listening for connections...");
68                 for(;;) {
69                     final Socket sock = ss.accept();
70                     new Thread() {
71                         public void run() {
72                             try {
73                                 new IMAP.Listener(sock, "megacz.com", new BogusAuthenticator()).handle();
74                             } catch (Exception e) {
75                                 Log.warn(this, e);
76                             }
77                         }
78                     }.start();
79                 }
80             } catch (Exception e) {
81                 Log.warn(this, e);
82             }
83         }
84     }
85
86     private static class SMTPThread extends Thread {
87         final int port = Integer.parseInt(System.getProperty("ibex.mail.smtp.port", "25"));
88         public void run() {
89             try {
90                 Log.info(this, "binding to port " + port + "...");
91                 ServerSocket ss = new ServerSocket(port);
92                 Log.info(this, "listening for connections...");
93                 while(true) {
94                     final Socket sock = ss.accept();
95                     final SMTP.Server smtp = new SMTP.Server(sock, "megacz.com");
96                     new Thread() {
97                         public void run() {
98                             try {
99                                 smtp.handle();
100                             } catch (Exception e) {
101                                 Log.warn(this, e);
102                             }
103                         }
104                     }.start();
105                 }
106             } catch (Exception e) {
107                 Log.warn(this, e);
108             }
109         }
110     }
111     */
112 }