add mailbox acls, further separate Mailbox and MailboxTree
[org.ibex.mail.git] / src / org / ibex / mail / MailboxTree.java
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.
4
5 package org.ibex.mail;
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
8 import org.ibex.mail.*;
9 import org.ibex.js.*;
10 import java.io.*;
11 import java.net.*;
12 import java.util.*;
13 import java.text.*;
14
15 /** a node on the "mailbox tree" */
16 public interface MailboxTree {
17     public abstract MailboxTree  slash(String name, boolean create);
18     public abstract String[]     children();
19     public abstract void         rmdir(String subdir);
20     public abstract void         rename(String subdir, MailboxTree newParent, String newName);        /* FIXME: IMAP semantics require creating parent dirs */
21     public abstract Mailbox      getMailbox();
22
23     public static class Wrapper implements MailboxTree {
24         protected MailboxTree mt;
25         public Wrapper(MailboxTree mt) { this.mt = mt; }
26         public MailboxTree  slash(String name, boolean create) { return mt.slash(name, create); }
27         public String[]     children() { return mt.children(); }
28         public void         rmdir(String subdir) { mt.rmdir(subdir); }
29         public void         rename(String subdir, MailboxTree newParent, String newName) { mt.rename(subdir, newParent, newName); }
30         public Mailbox      getMailbox() { return mt.getMailbox(); }
31     }
32
33     public static class AclWrapper extends Wrapper {
34         protected Acl.Entry acl;
35         public AclWrapper(MailboxTree mt, Acl.Entry acl) { super(mt); this.acl = acl; }
36         public Mailbox      getMailbox() {
37             return new Mailbox.AclWrapper(mt.getMailbox(), acl) {
38                     public MailboxTree  slash(String name, boolean create) {
39                         return MailboxTree.AclWrapper.this.slash(name, create);
40                     }
41                 };
42         }
43         public MailboxTree slash(String name, boolean create) {
44             if (!acl.mkdir) create = false;
45             if (!acl.list) return null;
46             return super.slash(name, create);
47         }
48         public void rmdir(String subdir) {
49             if (!acl.delete) throw new Acl.PermissionDenied();
50             super.rmdir(subdir);
51         }
52         public void rename(String subdir, MailboxTree newParent, String newName) {
53             // FIXME: acl-checking on parent?
54             if (!acl.delete) throw new Acl.PermissionDenied();
55             super.rename(subdir, newParent, newName);
56         }
57     }
58
59 }