Mailbox -> MailboxTree separation
[org.ibex.mail.git] / src / org / ibex / mail / IMAP.java
index 5f0d11e..4f60d0d 100644 (file)
@@ -102,7 +102,7 @@ public class IMAP {
 
         Mailbox inbox = null;
         Mailbox selected = null;
-        Mailbox root = null;
+        MailboxTree root = null;
         Mailbox selected() { if (selected == null) throw new Bad("no mailbox selected"); return selected; }
         final Login auth;
         final Client client;
@@ -113,13 +113,13 @@ public class IMAP {
         private Mailbox mailbox(String name, boolean create) { return mailbox(name, create, true); }
         private Mailbox mailbox(String name, boolean create, boolean throwexn) {
             if (name.equalsIgnoreCase("inbox")) return inbox;
-            Mailbox m = root;
+            MailboxTree m = root;
             for(StringTokenizer st = new StringTokenizer(name, sep + ""); st.hasMoreTokens();)
                 if ((m = m.slash(st.nextToken(), create)) == null) {
                     if (throwexn) throw new Server.No("no such mailbox " + name);
                     return null;
                 }
-            return m;
+            return m.getMailbox();
         }
 
         // FEATURE: not accurate when a wildcard and subsequent non-wildcards both match a single component
@@ -251,7 +251,8 @@ public class IMAP {
     /** takes an IMAP.Server and exposes it to the world as an IMAP server on a TCP socket */
     public static class Listener implements Client {
         String selectedName = null;
-        Mailbox inbox = null, root = null;
+        Mailbox inbox = null;
+        MailboxTree root = null;
         Server api;
         Parser parser = null;
         Connection conn = null;
@@ -261,7 +262,7 @@ public class IMAP {
         Parser.Token token(boolean freak) { return parser.token(freak); }
         void println(String s) {
             conn.println(s);
-            Log.info("", s);
+            //Log.info("", s);
         }
         void newline() { parser.newline(); }
         Query query(int max) { return parser.query(max, maxn(true)); }
@@ -275,9 +276,8 @@ public class IMAP {
             } else {
                 Account account = (Account)ret;
                 ((MailboxWrapper)api).root = root = account.getMailbox(IMAP.class);
-                Log.warn(this, "logged in, root="+root);
-                ((MailboxWrapper)api).inbox = inbox = root.slash("INBOX", false);
-                if (inbox == null) ((MailboxWrapper)api).inbox = inbox = root;
+                ((MailboxWrapper)api).inbox = inbox = root.slash("INBOX", false).getMailbox();
+                if (inbox == null) ((MailboxWrapper)api).inbox = inbox = root.getMailbox();
             }
         }
 
@@ -389,8 +389,6 @@ public class IMAP {
                 }
             } catch (Server.Bad b) { println(tag==null ? "* BAD Invalid tag":(tag + " Bad " + b.toString())); Log.warn(this,b);
             } catch (Server.No n)  { println(tag==null?"* BAD Invalid tag":(tag+" No "  + n.toString())); Log.warn(this,n);
-            } finally {
-                //Log.warn(this, conn.dumpLog()+"\n");
             }
         }