6ef2763766813ebdd9582bb2b2adc66b4dfbe69f
[org.ibex.mail.git] / src / org / ibex / mail / Main.java
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.
4
5 package org.ibex.mail;
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.io.*;
11 import java.io.*;
12 import java.net.*;
13 import java.util.*;
14 import org.ibex.crypto.*;
15
16 public class Main implements Listener {
17
18     public void accept(Connection conn) {
19         try {
20             if      (conn.getLocalPort() == 143)  new IMAP.Listener(auth).handleRequest(conn);
21             else if (conn.getLocalPort() == 25)   new SMTP.Server().handleRequest(conn);
22             else if (conn.getLocalPort() == 119)  new NNTP.Listener(auth).handleRequest(conn);
23             else if (conn.getLocalPort() == 8099) GMail.handleRequest(conn);
24         } finally {
25             conn.close();
26         }
27     }
28
29     private static final Auth auth = new Auth();
30     private static class Auth implements Login {
31         public Account anonymous() { return null; }
32         public Object login(String user, String pass, Class protocol) {
33             //if (protocol == IMAP.class && user.endsWith("@gmail.com")) return GMail.getGMail(user, pass).getIMAP();
34             return login(user, pass);
35         }
36         public Account login(String user, String pass) {
37             //if (user.indexOf("@gmail.com") != -1) return GMail.getGMail(user, pass);
38             if (!EtcPasswd.verify(user, pass)) return null;
39             final Mailbox root =
40                 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
41             return new Account(user, null, root.slash(user, true)){
42                     public Mailbox getMailbox(Class protocol) {
43                         /*
44                         if (protocol == NNTP.class) {
45                             final Mailbox arch = new MailmanArchives();
46                             return new Mailbox.Default() {
47                                     public void add(Message m) { throw new RuntimeException("not supported"); }
48                                     public void add(Message m, int i) { throw new RuntimeException("not supported"); }
49                                     public int              uidValidity()  { return 1; }
50                                     public Mailbox.Iterator iterator()     { return null; }
51                                     public int              uidNext()      { return 0; }
52                                     public String[] children() { return new String[] { "us" }; }
53                                     public Mailbox slash(String name, boolean create) { return arch; }
54                                 };
55                         } else {
56                         */
57                             return super.getMailbox(protocol);
58                             //}
59                     }
60                 };
61         }
62     }
63
64 }