1 // Copyright 2007 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
8 import org.ibex.mail.*;
15 /** a node on the "mailbox tree" */
16 public interface MailTree {
18 public MailTree slash(String name, boolean create);
19 public String[] children();
20 public void rmdir(String subdir);
21 public void rename(String subdir, MailTree newParent, String newName);
22 public Mailbox getMailbox();
24 public static class Wrapper implements MailTree {
25 protected MailTree mt;
26 public Wrapper(MailTree mt) { this.mt = mt; }
27 public MailTree slash(String name, boolean create) { return mt.slash(name, create); }
28 public String[] children() { return mt.children(); }
29 public void rmdir(String subdir) { mt.rmdir(subdir); }
30 public void rename(String subdir, MailTree newParent, String newName) { mt.rename(subdir, newParent, newName); }
31 public Mailbox getMailbox() { return mt.getMailbox(); }
34 /** applies an Acl to a directory; requires directions on how to Acl-ize subdirectories */
35 public static abstract class AclWrapper extends Wrapper {
36 protected Acl.Entry acl;
37 public AclWrapper(MailTree mt, Acl.Entry acl) { super(mt); this.acl = acl; }
38 public Mailbox getMailbox() { return new Mailbox.AclWrapper(mt.getMailbox(), acl); }
39 public void rmdir(String subdir) {
40 if (!acl.delete) throw new Acl.PermissionDenied();
43 public void rename(String subdir, MailTree newParent, String newName) {
44 if (!acl.delete) throw new Acl.PermissionDenied();
45 super.rename(subdir, newParent, newName);
47 public abstract MailTree slash(String name, boolean create);
50 /** applies the Acl recursively to the entire subtree */
51 public static class RecursiveAclWrapper extends AclWrapper {
52 public RecursiveAclWrapper(MailTree mt, Acl.Entry acl) { super(mt, acl); }
53 public MailTree slash(String name, boolean create) {
54 if (!acl.list) throw new Acl.PermissionDenied();
55 if (!acl.mkdir) create = false;
56 return new RecursiveAclWrapper(mt.slash(name, create), acl);