add Mailbox.get(JS)
[org.ibex.mail.git] / src / org / ibex / mail / Mailbox.java
index ec0612f..3d3f8bb 100644 (file)
@@ -41,21 +41,29 @@ public abstract class Mailbox extends JS.Obj implements Target {
     private int randomUidValidity = new Random().nextInt();
     public  int uidValidity()  { return randomUidValidity; }
 
+    public int maxuid() {
+        int ret = -1;
+        for(Mailbox.Iterator it = iterator(); it.next(); ) ret = Math.max(ret, it.uid());
+        return ret;
+    }
+
     /** default, inefficient implementation of Mailbox; only requires a few methods to be implemented */
-    public static abstract class Default extends Mailbox {
+    public static abstract class Default extends Mailbox /* implements MailTree? */ {
         public Mailbox.Iterator iterator(Query q) { return new Mailbox.Iterator.QueryIterator(q, this); }
         public void copy(Query q, Mailbox dest) { for(Mailbox.Iterator it = iterator(q); it.next();) dest.insert(it.cur(), it.getFlags()); }
         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 JS get(JS key) throws JSExn {
+            return (JS)slash(JSU.toString(key), true);
+        }
         public void move(Query q, Mailbox dest) {
             for(Mailbox.Iterator it = iterator(q);it.next();) { dest.insert(it.cur(), it.getFlags()); it.delete(); }
         }
         public static abstract class Iterator implements Mailbox.Iterator {
             // FIXME: NNTP spec allows us to use longs (64-bit) here
+            // FIXME: NNTP spec requires that the minimum nntpNumber of a group must never, ever decrease (no, that's not a typo)
             public int     nntpNumber() { throw new MailException("not supported"); }
             public int     getFlags() { return 0; }
             public void    setFlags(int flags) { throw new MailException("not supported"); }
@@ -68,7 +76,11 @@ public abstract class Mailbox extends JS.Obj implements Target {
     public static interface Iterator {
         public abstract Message cur();
         public abstract Headers head();
+
+        // FIXME: change all code to actually use this convention!
+        /** JDBC convention: iterator starts "before the first element" */
         public abstract boolean next();
+
         public abstract void    delete();
 
         /** a unique identifier for this message */
@@ -76,10 +88,10 @@ public abstract class Mailbox extends JS.Obj implements Target {
 
         /**
          *  Message number according to IMAP semantics.
+         *    - must range from 1..numMessagesInMailbox
          *    - no two messages in the same mailbox may have the same imapNumber
          *    - sorting by uid must yield the same order as sorting them by imapNumber
-         *    - imapNumber may only change if uidValidity changes
-         *    - if uidValidity changes, imapNumbers may change or be reused
+         *    - imapNumber changes when messages with lower imapNumbers are deleted
          */
         public abstract int     imapNumber();
 
@@ -169,7 +181,7 @@ public abstract class Mailbox extends JS.Obj implements Target {
         public int              uidValidity()  { return m.uidValidity(); }
     }
 
-    public static abstract class AclWrapper extends MailboxWrapper {
+    public static class AclWrapper extends MailboxWrapper {
         private Mailbox m;
         private Acl.Entry acl;
         public AclWrapper(Mailbox m, Acl.Entry acl) { super(m); this.acl = acl; }