public final String user;
public final Address address;
- protected MailboxTree root = null;
+ protected MailTree root = null;
- public MailboxTree getMailbox(Class protocol) { return this.root; }
+ public MailTree getMailbox(Class protocol) { return this.root; }
protected Account(String user, Address address) { this.user = user; this.address = address; }
- public Account(String user, Address address, MailboxTree root) { this.user = user; this.address = address; this.root = root; }
+ public Account(String user, Address address, MailTree root) { this.user = user; this.address = address; this.root = root; }
}
public Entry(String asString) {
this.toString = asString;
+ if (asString == null) asString = "";
+ if (asString.equals("read")) asString = "rl";
+ if (asString.equals("post")) asString = "rlp";
+ if (asString.equals("write")) asString = "rlidwkpfm";
this.read = asString.indexOf('r') != -1;
this.list = asString.indexOf('l') != -1;
this.insert = asString.indexOf('i') != -1;
import javax.servlet.http.*;
/** An exceptionally crude implementation of Mailbox relying on POSIXy filesystem semantics */
-public class FileBasedMailbox extends Mailbox.Default implements MailboxTree {
+public class FileBasedMailbox extends Mailbox.Default implements MailTree {
public static final long MAGIC_DATE = 0;
private static final char slash = File.separatorChar;
private static final WeakHashMap<String,FileBasedMailbox> instances = new WeakHashMap<String,FileBasedMailbox>();
public String toString() { return "[FileBasedMailbox " + path.getAbsolutePath() + "]"; }
- public MailboxTree slash(String name, boolean create) { return getFileBasedMailbox(path.getAbsolutePath()+slash+name, create); }
+ public MailTree slash(String name, boolean create) { return getFileBasedMailbox(path.getAbsolutePath()+slash+name, create); }
public void rmdir(String subdir) { throw new RuntimeException("FIXME not implemented"); }
- public void rename(String subdir, MailboxTree newParent, String newName) { throw new RuntimeException("FIXME not implemented"); }
+ public void rename(String subdir, MailTree newParent, String newName) { throw new RuntimeException("FIXME not implemented"); }
public Mailbox getMailbox() { return this; }
public JS get(JS key) throws JSExn {
}
// FIXME: should be a File()
- public static synchronized MailboxTree getFileBasedMailbox(String path, boolean create) {
+ public static synchronized MailTree getFileBasedMailbox(String path, boolean create) {
try {
- MailboxTree ret = instances.get(path);
+ MailTree ret = instances.get(path);
if (ret == null) {
if (!create && !(new File(path).exists())) return null;
ret = new FileBasedMailbox(new File(path));
Mailbox inbox = null;
Mailbox selected = null;
- MailboxTree root = null;
+ MailTree 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;
- MailboxTree mt = mailboxTree(name, create, throwexn);
+ MailTree mt = mailboxTree(name, create, throwexn);
return mt==null ? null : mt.getMailbox();
}
- private MailboxTree mailboxTree(String name, boolean create) { return mailboxTree(name, create, true); }
- private MailboxTree mailboxTree(String name, boolean create, boolean throwexn) {
- MailboxTree m = root;
+ private MailTree mailboxTree(String name, boolean create) { return mailboxTree(name, create, true); }
+ private MailTree mailboxTree(String name, boolean create, boolean throwexn) {
+ MailTree 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);
for(int i=0; i<children.length; i++) {
String s = children[i], pre = ref, kid = start + (start.length() > 0 ? sep+"" : "") + s;
if (mailbox(kid, false) == null) continue;
- MailboxTree phant = mailboxTree(kid, false, false);
+ MailTree phant = mailboxTree(kid, false, false);
if (phant != null) {
boolean phantom = phant.getMailbox()==null;
while(true) {
public void unselect() { selected = null; }
public void delete(String m0) { mailboxTree(dirname(m0),false).rmdir(basename(m0)); }
+
public void rename(String from0, String to) {
Mailbox from = mailbox(from0, false);
if (from.equals(inbox)) { from.copy(Query.all(), mailbox(to, true)); }
else if (to.equalsIgnoreCase("inbox")) { from.copy(Query.all(), mailbox(to, true)); delete(from0); }
- else mailboxTree(dirname(from0), false).rename(dirname(from0), mailboxTree(dirname(to), false), basename(to));
+ else mailboxTree(dirname(from0), false)
+ .rename(dirname(from0),
+ mailboxTree(dirname(to),
+ true /* required by IMAP */),
+ basename(to));
}
public void create(String m) { mailbox(m, true, false); }
public static class Listener implements Client {
String selectedName = null;
Mailbox inbox = null;
- MailboxTree root = null;
+ MailTree root = null;
Server api;
Parser parser = null;
Connection conn = null;
} else {
Account account = (Account)ret;
((MailboxWrapper)api).root = root = account.getMailbox(IMAP.class);
- MailboxTree ibt = root.slash("INBOX", false);
+ MailTree ibt = root.slash("INBOX", false);
Mailbox ib = ibt==null ? null : ibt.getMailbox();
((MailboxWrapper)api).inbox = inbox = ib;
}
--- /dev/null
+// Copyright 2007 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 interface MailTree {
+
+ public MailTree slash(String name, boolean create);
+ public String[] children();
+ public void rmdir(String subdir);
+ public void rename(String subdir, MailTree newParent, String newName);
+ public Mailbox getMailbox();
+
+ public static class Wrapper implements MailTree {
+ protected MailTree mt;
+ public Wrapper(MailTree mt) { this.mt = mt; }
+ public MailTree slash(String name, boolean create) { return mt.slash(name, create); }
+ public String[] children() { return mt.children(); }
+ public void rmdir(String subdir) { mt.rmdir(subdir); }
+ public void rename(String subdir, MailTree newParent, String newName) { mt.rename(subdir, newParent, newName); }
+ public Mailbox getMailbox() { return mt.getMailbox(); }
+ }
+
+ /** applies an Acl to a directory; requires directions on how to Acl-ize subdirectories */
+ public static abstract class AclWrapper extends Wrapper {
+ protected Acl.Entry acl;
+ public AclWrapper(MailTree mt, Acl.Entry acl) { super(mt); this.acl = acl; }
+ public Mailbox getMailbox() { return new Mailbox.AclWrapper(mt.getMailbox(), acl); }
+ public void rmdir(String subdir) {
+ if (!acl.delete) throw new Acl.PermissionDenied();
+ super.rmdir(subdir);
+ }
+ public void rename(String subdir, MailTree newParent, String newName) {
+ if (!acl.delete) throw new Acl.PermissionDenied();
+ super.rename(subdir, newParent, newName);
+ }
+ public abstract MailTree slash(String name, boolean create);
+ }
+
+ /** applies the Acl recursively to the entire subtree */
+ public static class RecursiveAclWrapper extends AclWrapper {
+ public RecursiveAclWrapper(MailTree mt, Acl.Entry acl) { super(mt, acl); }
+ public MailTree slash(String name, boolean create) {
+ if (!acl.list) throw new Acl.PermissionDenied();
+ if (!acl.mkdirs) create = false;
+ return new RecursiveAclWrapper(super.slash(name, create), acl);
+ }
+ }
+}
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 MailboxTree slash(String name, boolean create) { return null; }
+ public MailTree 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) {
+++ /dev/null
-// Copyright 2007 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 interface MailboxTree {
- public abstract MailboxTree slash(String name, boolean create);
- public abstract String[] children();
- public abstract void rmdir(String subdir);
- public abstract void rename(String subdir, MailboxTree newParent, String newName); /* FIXME: IMAP semantics require creating parent dirs */
- public abstract Mailbox getMailbox();
-
- public static class Wrapper implements MailboxTree {
- protected MailboxTree mt;
- public Wrapper(MailboxTree mt) { this.mt = mt; }
- public MailboxTree slash(String name, boolean create) { return mt.slash(name, create); }
- public String[] children() { return mt.children(); }
- public void rmdir(String subdir) { mt.rmdir(subdir); }
- public void rename(String subdir, MailboxTree newParent, String newName) { mt.rename(subdir, newParent, newName); }
- public Mailbox getMailbox() { return mt.getMailbox(); }
- }
-
- public static class AclWrapper extends Wrapper {
- protected Acl.Entry acl;
- public AclWrapper(MailboxTree mt, Acl.Entry acl) { super(mt); this.acl = acl; }
- public Mailbox getMailbox() {
- return new Mailbox.AclWrapper(mt.getMailbox(), acl) {
- public MailboxTree slash(String name, boolean create) {
- return MailboxTree.AclWrapper.this.slash(name, create);
- }
- };
- }
- public MailboxTree slash(String name, boolean create) {
- if (!acl.mkdir) create = false;
- if (!acl.list) return null;
- return super.slash(name, create);
- }
- public void rmdir(String subdir) {
- if (!acl.delete) throw new Acl.PermissionDenied();
- super.rmdir(subdir);
- }
- public void rename(String subdir, MailboxTree newParent, String newName) {
- // FIXME: acl-checking on parent?
- if (!acl.delete) throw new Acl.PermissionDenied();
- super.rename(subdir, newParent, newName);
- }
- }
-
-}
private KerberosAuth ka = new KerberosAuth("MEGACZ.COM", "chaitin.megacz.com");
public Account anonymous() {
try {
- final MailboxTree root =
+ final MailTree root =
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/list", false);
if (root==null) return null;
return new Account("anonymous", null, root) {
- public MailboxTree getMailbox(Class protocol) {
+ public MailTree 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 MailboxTree root =
+ final MailTree root =
FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT + "/user", true);
return new Account(user, null, root.slash(user, true)){
- public MailboxTree getMailbox(Class protocol) {
+ public MailTree getMailbox(Class protocol) {
return super.getMailbox(protocol);
}
};
}
public static class MailboxWrapper implements Server {
- private final MailboxTree root;
+ private final MailTree root;
private Mailbox current;
private int ptr = 0;
private boolean post;
- public MailboxWrapper(MailboxTree root) { this(root, false); }
- public MailboxWrapper(MailboxTree root, boolean post) { this.root = root; this.post = post; }
+ public MailboxWrapper(MailTree root) { this(root, false); }
+ public MailboxWrapper(MailTree 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(MailboxTree who, String prefix) {
+ private Group[] list(MailTree who, String prefix) {
Vec v = new Vec();
if (who == null) who = root;
String[] s = who.children();
}
private void setgroup(String s) {
- MailboxTree ncurrent = root;
+ MailTree ncurrent = root;
for(StringTokenizer st = new StringTokenizer(s, ".");
ncurrent != null && st.hasMoreTokens();
ncurrent = ncurrent.slash(st.nextToken(), false));
if (ncurrent!=null) current=ncurrent.getMailbox();
}
private Group getgroup(String s) {
- MailboxTree box = root;
+ MailTree box = root;
for(StringTokenizer st = new StringTokenizer(s, ".");
box!=null && st.hasMoreTokens();
box = box.slash(st.nextToken(), false));
} catch (IOException e) { throw new JSExn(e.toString()); }
case "mail.whitelist": return JSReflection.wrap(org.ibex.mail.SMTP.whitelist);
case "mail.my.mailbox":
- MailboxTree root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
+ MailTree root = FileBasedMailbox.getFileBasedMailbox(Mailbox.STORAGE_ROOT, true);
return (JS)root.slash("user", true).slash("megacz", true);
case "mail.list": return METHOD;
//#end