--- /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);
+ }
+ }
+}