public final String user;
public final Address address;
- protected Mailbox root = null;
+ protected MailboxTree root = null;
- public Mailbox getMailbox(Class protocol) { return this.root; }
+ public MailboxTree getMailbox(Class protocol) { return this.root; }
protected Account(String user, Address address) { this.user = user; this.address = address; }
- public Account(String user, Address address, Mailbox root) { this.user = user; this.address = address; this.root = root; }
+ public Account(String user, Address address, MailboxTree root) { this.user = user; this.address = address; this.root = root; }
}
Mailbox inbox = null;
Mailbox selected = null;
- Mailbox root = null;
+ MailboxTree root = null;
Mailbox selected() { if (selected == null) throw new Bad("no mailbox selected"); return selected; }
final Login auth;
final Client client;
private Mailbox mailbox(String name, boolean create) { return mailbox(name, create, true); }
private Mailbox mailbox(String name, boolean create, boolean throwexn) {
if (name.equalsIgnoreCase("inbox")) return inbox;
- Mailbox m = root;
+ MailboxTree m = root;
for(StringTokenizer st = new StringTokenizer(name, sep + ""); st.hasMoreTokens();)
if ((m = m.slash(st.nextToken(), create)) == null) {
if (throwexn) throw new Server.No("no such mailbox " + name);
return null;
}
- return m;
+ return m.getMailbox();
}
// FEATURE: not accurate when a wildcard and subsequent non-wildcards both match a single component
/** takes an IMAP.Server and exposes it to the world as an IMAP server on a TCP socket */
public static class Listener implements Client {
String selectedName = null;
- Mailbox inbox = null, root = null;
+ Mailbox inbox = null;
+ MailboxTree root = null;
Server api;
Parser parser = null;
Connection conn = null;
Parser.Token token(boolean freak) { return parser.token(freak); }
void println(String s) {
conn.println(s);
- Log.info("", s);
+ //Log.info("", s);
}
void newline() { parser.newline(); }
Query query(int max) { return parser.query(max, maxn(true)); }
} else {
Account account = (Account)ret;
((MailboxWrapper)api).root = root = account.getMailbox(IMAP.class);
- Log.warn(this, "logged in, root="+root);
- ((MailboxWrapper)api).inbox = inbox = root.slash("INBOX", false);
- if (inbox == null) ((MailboxWrapper)api).inbox = inbox = root;
+ ((MailboxWrapper)api).inbox = inbox = root.slash("INBOX", false).getMailbox();
+ if (inbox == null) ((MailboxWrapper)api).inbox = inbox = root.getMailbox();
}
}
}
} catch (Server.Bad b) { println(tag==null ? "* BAD Invalid tag":(tag + " Bad " + b.toString())); Log.warn(this,b);
} catch (Server.No n) { println(tag==null?"* BAD Invalid tag":(tag+" No " + n.toString())); Log.warn(this,n);
- } finally {
- //Log.warn(this, conn.dumpLog()+"\n");
}
}
import java.text.*;
/** abstract superclass for mailboxes, which store messages along with their flags */
-public abstract class Mailbox extends JS.Obj implements Target {
+public abstract class Mailbox extends MailboxTree implements Target {
public JS get(JS key) throws JSExn {
return slash(JSU.toString(key), true);
public abstract int uidNext();
public abstract void rename(String newName); /* FIXME: IMAP semantics require creating parent dirs */
public abstract void destroy(boolean recursive);
- public abstract Mailbox slash(String name, boolean create);
- public abstract String[] children();
+ public Mailbox getMailbox() { return this; }
// Thunks ////////////////////////////////////////////////////////////////////////////
public int count(Query q) { int count = 0; for(Mailbox.Iterator it = iterator(q); it.next();) count++; return count; }
public void rename(String newName) { throw new MailException("not supported"); }
public void destroy(boolean recursive) { throw new MailException("not supported"); }
- public Mailbox slash(String name, boolean create) { return null; }
+ public MailboxTree slash(String name, boolean create) { return null; }
public String[] children() { return new String[] { }; }
public void post(Message message) { insert(message, Flag.RECENT); }
public void move(Query q, Mailbox dest) {
public int uidNext() { return m.uidNext(); }
public void rename(String newName) { m.rename(newName); }
public void destroy(boolean recursive) { m.destroy(recursive); }
- public Mailbox slash(String name, boolean create) { return m.slash(name, create); }
+ public MailboxTree slash(String name, boolean create) { return m.slash(name, create); }
public String[] children() { return m.children(); }
public Mailbox.Iterator iterator() { return m.iterator(); }
public int uidValidity() { return m.uidValidity(); }
--- /dev/null
+// 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.*;
+import org.ibex.util.*;
+import org.ibex.mail.*;
+import org.ibex.js.*;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.text.*;
+
+/** a node on the "mailbox tree" */
+public abstract class MailboxTree extends JS.Obj {
+ public abstract MailboxTree slash(String name, boolean create);
+ public abstract String[] children();
+ public Mailbox getMailbox() { return null; }
+}
// restrict the maximum number of open connections from any given source IP (probably max 4)
public class Main {
+ public static final ThreadPool threadPool = new ThreadPool(10);
+ public static final Cron cron = new Cron(threadPool);
+
public static void main(String[] s) throws Exception {
try {
File f = new File(Mailbox.STORAGE_ROOT + "/restart");
ServerSocket sock563 = (ServerSocket) sslserversocketfactory.createServerSocket(563);
//ServerSocket sock995 = new ServerSocket(995);
//ServerSocket sock113 = new ServerSocket(113);
- new Thread() {
+
+ cron.executeLater(500, new Runnable() {
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();
+ 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); }
+ cron.executeLater(500, this);
+ } });
+
new Acceptor(sock143).start();
new Acceptor(sock119).start();
new Acceptor(sock25).start();
try {
ss.setReuseAddress(true);
final Socket s = ss.accept();
- new Thread() {
+ threadPool.start(new Runnable() {
public void run() {
try {
accept(new Connection(s, "megacz.com"));
} catch (Throwable t) { Log.error(Main.class, t); }
}
- }.start();
+ });
} catch (Throwable t) {
Log.error(Main.class, t);
Misc.sleep(1000);
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
if (root==null) return null;
return new Account("anonymous", null, root){
- public Mailbox getMailbox(Class protocol) {
+ public MailboxTree getMailbox(Class protocol) {
return super.getMailbox(protocol);
}
};
//if (!EtcPasswd.verify(user, pass)) return null;
//if (!CheckPassword.verify(user, pass)) return null;
if (!ka.auth(user, pass)) return null;
- final Mailbox root =
+ final MailboxTree root =
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
return new Account(user, null, root.slash(user, true)){
- public Mailbox getMailbox(Class protocol) {
+ public MailboxTree getMailbox(Class protocol) {
return super.getMailbox(protocol);
}
};
}
public static class MailboxWrapper implements Server {
- private final Mailbox root;
+ private final MailboxTree root;
private Mailbox current;
private int ptr = 0;
private boolean post;
- public MailboxWrapper(Mailbox root) { this(root, false); }
- public MailboxWrapper(Mailbox root, boolean post) { this.root = root; this.post = post; }
+ public MailboxWrapper(MailboxTree root) { this(root, false); }
+ public MailboxWrapper(MailboxTree root, boolean post) { this.root = root; this.post = post; }
public boolean postok() { return post; }
public void post(Message m) throws IOException { current.post(m); }
public Group group(String s) {
} catch (Exception e) { return null; }
}
public Group[] list() { return list(root, ""); }
- private Group[] list(Mailbox who, String prefix) {
+ private Group[] list(MailboxTree who, String prefix) {
Vec v = new Vec();
if (who == null) who = root;
String[] s = who.children();
for(int i=0; i<s.length; i++) {
v.addElement(new Group(prefix + s[i], true, 0, 0, 0)); // FIXME numbers
- Group[] g2 = list(who.slash(s[i], false), prefix + s[i] + ".");
+ Group[] g2 = list(who.slash(s[i], false).getMailbox(), prefix + s[i] + ".");
for(int j=0; j<g2.length; j++) v.addElement(g2[j]);
}
Group[] ret = new Group[v.size()];
}
private void setgroup(String s) {
- Mailbox ncurrent = root;
+ MailboxTree ncurrent = root;
for(StringTokenizer st = new StringTokenizer(s, ".");
ncurrent != null && st.hasMoreTokens();
ncurrent = ncurrent.slash(st.nextToken(), false));
- if (ncurrent!=null) current=ncurrent;
+ if (ncurrent!=null) current=ncurrent.getMailbox();
}
private Group getgroup(String s) {
- Mailbox box = root;
+ MailboxTree box = root;
for(StringTokenizer st = new StringTokenizer(s, ".");
box!=null && st.hasMoreTokens();
box = box.slash(st.nextToken(), false));
if (box==null) return null;
- return new Group(s, true, 1, box.count(Query.all()), box.count(Query.all()));
+ return new Group(s, true, 1, box.getMailbox().count(Query.all()), box.getMailbox().count(Query.all()));
}
public Group[] newgroups(Date d, String[] distributions) { /* FEATURE */ return new Group[] { }; }
pass = st.nextToken();
account = login.login(user, pass);
if (account == null) { println("502 Invalid"); continue; }
- Mailbox box = account.getMailbox(NNTP.class);
- this.api = new MailboxWrapper(box, true);
+ this.api = new MailboxWrapper(account.getMailbox(NNTP.class), true);
println("281 Good to go");
continue;
}
Integer.parseInt(System.getProperty("org.ibex.mail.smtp.maxMessageSize", "-1"));
private static final Mailbox spool =
- FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT,false).slash("spool",true).slash("smtp",true);
+ FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT,false).slash("spool",true).slash("smtp",true).getMailbox();
static {
for(int i=0; i<numOutgoingThreads; i++)