add mailbox acls, further separate Mailbox and MailboxTree
[org.ibex.mail.git] / src / org / ibex / mail / FileBasedMailbox.java
index 2340a16..066781a 100644 (file)
@@ -6,7 +6,9 @@ package org.ibex.mail;
 import org.prevayler.*;
 import org.ibex.mail.*;
 import org.ibex.util.*;
+import org.ibex.js.*;
 import org.ibex.io.*;
+import org.ibex.io.Fountain;
 import java.io.*;
 import java.nio.*;
 import java.nio.channels.*;
@@ -17,26 +19,31 @@ import javax.servlet.*;
 import javax.servlet.http.*;
 
 /** An exceptionally crude implementation of Mailbox relying on POSIXy filesystem semantics */
-public class FileBasedMailbox extends Mailbox.Default {
+public class FileBasedMailbox extends Mailbox.Default implements MailboxTree {
 
     public static final long MAGIC_DATE = 0;
     private static final char slash = File.separatorChar;
-    private static final WeakHashMap<String,Mailbox> instances = new WeakHashMap<String,Mailbox>();
+    private static final WeakHashMap<String,FileBasedMailbox> instances = new WeakHashMap<String,FileBasedMailbox>();
     public String toString() { return "[FileBasedMailbox " + path.getAbsolutePath() + "]"; }
-    public Mailbox slash(String name, boolean create) { return getFileBasedMailbox(path.getAbsolutePath()+slash+name, create); }
+
+    public MailboxTree 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 Mailbox      getMailbox() { return this; }
+
+    public JS get(JS key) throws JSExn {
+        return (JS)slash(JSU.toString(key), true);
+    }
 
     // FIXME: should be a File()
-    public static synchronized Mailbox getFileBasedMailbox(String path, boolean create) {
+    public static synchronized MailboxTree getFileBasedMailbox(String path, boolean create) {
         try {
-            Mailbox ret = instances.get(path);
+            MailboxTree ret = instances.get(path);
             if (ret == null) {
                 if (!create && !(new File(path).exists())) return null;
-                if (new File(new File(path)+"/subscribers").exists()) {
-                    ret = new MailingList(new File(path), new FileBasedMailbox(new File(path)));
-                } else {
-                    ret = new FileBasedMailbox(new File(path));
-                }
-                instances.put(path, ret);
+                ret = new FileBasedMailbox(new File(path));
+                instances.put(path, (FileBasedMailbox)ret);
             }
             return ret;
         } catch (Exception e) {
@@ -218,7 +225,7 @@ public class FileBasedMailbox extends Mailbox.Default {
             if (request.getServletPath().indexOf("..") != -1) throw new IOException(".. not allowed in image paths");
             ServletContext cx = getServletContext();
             String path = cx.getRealPath(request.getServletPath());
-            Mailbox mbox = FileBasedMailbox.getFileBasedMailbox(path, false);
+            Mailbox mbox = FileBasedMailbox.getFileBasedMailbox(path, false).getMailbox();
             if (mbox == null) throw new IOException("no such mailbox: " + path);
 
             Vec msgs = new Vec();