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.jinetd.*;
14 import org.ibex.crypto.*;
16 public class Main implements Listener {
18 public void accept(Connection conn) {
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);
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);
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;
40 FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
41 return new Account(user, null, root.slash(user, true)){
42 public Mailbox getMailbox(Class protocol) {
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; }
57 return super.getMailbox(protocol);