treat BODY[1] as BODY for now
[org.ibex.mail.git] / src / org / ibex / mail / protocol / IMAP.java
index 1c9b5c6..e0cc718 100644 (file)
@@ -98,11 +98,15 @@ public class IMAP {
 
         public MailboxWrapper(Login auth, Client c) { this.auth=auth; this.client=c;}
 
-        private Mailbox mailbox(String name, boolean create) {
+        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;
             for(StringTokenizer st = new StringTokenizer(name, sep + ""); st.hasMoreTokens();)
-                if ((m = m.slash(st.nextToken(), create)) == null) throw new Server.No("no such mailbox " + name);
+                if ((m = m.slash(st.nextToken(), create)) == null) {
+                    if (throwexn) throw new Server.No("no such mailbox " + name);
+                    return null;
+                }
             return m;
         }
 
@@ -116,6 +120,7 @@ public class IMAP {
             String[] children = (start.length() == 0 ? root : mailbox(start, false)).children();
             for(int i=0; i<children.length; i++) {
                 String s = children[i], pre = ref, kid = start + (start.length() > 0 ? sep+"" : "") + s;                
+                if (mailbox(kid, false) == null) continue;
                 boolean phantom = mailbox(kid, false).phantom();
                 while(true) {
                     if (pre.length() == 0) {
@@ -153,12 +158,13 @@ public class IMAP {
             Account account = null;
             if ((account = auth.login(u,p)) == null) throw new No("Login failed.");
             root = account.getMailbox(IMAP.class);
-            inbox = mailbox("INBOX", false);  // FEATURE: ??
+            inbox = root.slash("INBOX", false);
+            if (inbox == null) inbox = root;
         }
         public void unselect() { selected = null; }
         public void delete(String m0) { delete(mailbox(m0,false)); }
         public void delete(Mailbox m) { if (!m.equals(inbox)) m.destroy(false); else throw new Bad("can't delete inbox"); }
-        public void create(String m) { mailbox(m, true); }
+        public void create(String m) { mailbox(m, true, false); }
         public void append(String m,int f,Date a,String b) { try {
             mailbox(m,false).add(new Message(new Stream(b), new Message.Envelope(null,null,a)),f|Mailbox.Flag.RECENT);
         } catch (Message.Malformed e) { throw new No(e.getMessage()); } }
@@ -254,7 +260,7 @@ public class IMAP {
                     case CAPABILITY:   println("* CAPABILITY " + Printer.join(" ", api.capability())); break;
                     case AUTHENTICATE: throw new Server.No("AUTHENTICATE not supported");
                     case LOGOUT:       api.logout(); println("* BYE"); conn.close(); return;
-                    case LIST:         api.list(token().q(), token().q()); break;
+                    case LIST:         api.list(token().q(), token().astring()); break; /*astring is a hack for EUDORA*/
                     case LSUB:         api.lsub(token().q(), token().q()); break;
                     case SUBSCRIBE:    api.subscribe(token().astring()); break;
                     case UNSUBSCRIBE:  api.unsubscribe(token().astring()); break;
@@ -412,7 +418,7 @@ public class IMAP {
                     s = list.length == 0 ? "" : list[0].s.toUpperCase();
                     r.append(s);
                     if (list.length == 0)                   { spec |= RFC822TEXT;   if(e) payload = m.headers.raw+"\r\n"+m.body; }
-                    else if (s.equals(""))                  { spec |= RFC822TEXT;   if(e) payload = m.headers.raw+"\r\n"+m.body; }
+                    else if (s.equals("") || s.equals("1")) { spec |= RFC822TEXT;   if(e) payload = m.headers.raw+"\r\n"+m.body; }
                     else if (s.equals("TEXT"))              { spec |= RFC822TEXT;   if(e) payload = m.body; }
                     else if (s.equals("HEADER"))            { spec |= HEADER;       if(e) payload = m.headers.raw+"\r\n"; }
                     else if (s.equals("HEADER.FIELDS"))     { spec |= FIELDS;     payload=headers(r,t[i].l()[1].sl(),false,m,e); }
@@ -745,7 +751,7 @@ public class IMAP {
             return "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" "+m.size()+" "+m.lines+")";
         }
         static String message(Message m) { return m.toString(); }
-        static String date(Date d) { return d.toString(); }
+        static String date(Date d) { return "\""+d.toString()+"\""; }
         static String envelope(Message m) {
             return
                 "(" + quotify(m.envelope.arrival.toString()) +