rename MailboxTree -> MailTree
authoradam <adam@megacz.com>
Mon, 9 Jul 2007 03:26:02 +0000 (03:26 +0000)
committeradam <adam@megacz.com>
Mon, 9 Jul 2007 03:26:02 +0000 (03:26 +0000)
darcs-hash:20070709032602-5007d-e2b096c37e65ba0b252e38a75957efebba2f4189.gz

src/org/ibex/mail/Account.java
src/org/ibex/mail/Acl.java
src/org/ibex/mail/FileBasedMailbox.java
src/org/ibex/mail/IMAP.java
src/org/ibex/mail/MailTree.java [new file with mode: 0644]
src/org/ibex/mail/Mailbox.java
src/org/ibex/mail/MailboxTree.java [deleted file]
src/org/ibex/mail/Main.java
src/org/ibex/mail/NNTP.java
src/org/ibex/mail/Script.java

index 76fe06e..aa739d9 100644 (file)
@@ -9,11 +9,11 @@ public class Account {
 
     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; }
 
 }
index e7558d4..432dbe6 100644 (file)
@@ -56,6 +56,10 @@ public class Acl {
 
         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;
index 066781a..4c9d4a5 100644 (file)
@@ -19,17 +19,17 @@ import javax.servlet.*;
 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 {
@@ -37,9 +37,9 @@ public class FileBasedMailbox extends Mailbox.Default implements MailboxTree {
     }
 
     // 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));
index dc3b8f3..a111429 100644 (file)
@@ -102,7 +102,7 @@ public class IMAP {
 
         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;
@@ -115,12 +115,12 @@ public class IMAP {
         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);
@@ -144,7 +144,7 @@ public class IMAP {
             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) {
@@ -183,11 +183,16 @@ public class IMAP {
         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); }
@@ -260,7 +265,7 @@ public class IMAP {
     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;
@@ -284,7 +289,7 @@ public class IMAP {
             } 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;
             }
diff --git a/src/org/ibex/mail/MailTree.java b/src/org/ibex/mail/MailTree.java
new file mode 100644 (file)
index 0000000..4a6a587
--- /dev/null
@@ -0,0 +1,59 @@
+// 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);
+        }
+    }
+}
index ec0612f..59c8268 100644 (file)
@@ -48,7 +48,7 @@ public abstract class Mailbox extends JS.Obj implements Target {
         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) {
diff --git a/src/org/ibex/mail/MailboxTree.java b/src/org/ibex/mail/MailboxTree.java
deleted file mode 100644 (file)
index 4728857..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-// 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);
-        }
-    }
-
-}
index a11b9a0..4d0659b 100644 (file)
@@ -121,11 +121,11 @@ public class Main {
         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);
                     }
                 };
@@ -136,10 +136,10 @@ public class Main {
             //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);
                     }
                 };
index f5c9fef..d758d73 100644 (file)
@@ -59,12 +59,12 @@ public class NNTP {
     }
 
     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) {
@@ -91,7 +91,7 @@ public class NNTP {
             } 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();
@@ -106,14 +106,14 @@ public class NNTP {
         }
 
         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));
index d43fcaa..875b178 100644 (file)
@@ -147,7 +147,7 @@ public class Script extends JS.Obj implements Target {
             } 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