bogus
[org.ibex.mail.git] / src / org / ibex / mail / protocol / IMAP.java
index 28cd51a..a354445 100644 (file)
@@ -2,7 +2,6 @@ package org.ibex.mail.protocol;
 import org.ibex.io.*;
 import org.ibex.jinetd.Listener;
 import org.ibex.jinetd.Worker;
-import org.ibex.net.*;
 import org.ibex.mail.*;
 import org.ibex.util.*;
 import org.ibex.mail.target.*;
@@ -286,23 +285,24 @@ public class IMAP {
                         String response = "";
                         for(int i=0; i<list.length; i++) {
                             String s = list[i].atom().toUpperCase();
+                            if (i>0) response += " ";
                             if (s.equals("MESSAGES"))    response += "MESSAGES "    + api.count(mailbox);
                             if (s.equals("RECENT"))      response += "RECENT "      + api.recent(mailbox);
                             if (s.equals("UIDNEXT"))     response += "UIDNEXT "     + api.uidNext(mailbox);
                             if (s.equals("UIDVALIDITY")) response += "UIDVALIDITY " + api.uidValidity(mailbox);
                             if (s.equals("UNSEEN"))      response += "UNSEEN "      + api.unseen(mailbox);
                         }
-                        println("* STATUS " + selectedName + " (" + response + ")");
+                        println("* STATUS " + mailbox + " (" + response + ")");
                         break;
                     }
                     case APPEND: { 
-                        String m = token().atom();
+                        String m = token().astring();
                         int flags = 0;
-                        Date arrival = null;
+                        Date arrival = new Date();
                         Parser.Token t = token();
                         if (t.type == t.LIST)   { flags = t.flags();      t = token(); }
-                        if (t.type == t.QUOTED) { arrival = t.datetime(); t = token(); }
-                        api.append(m, flags, arrival, token().q());
+                        if (t.type != t.QUOTED) { arrival = t.datetime(); t = token(); }
+                        api.append(m, flags, arrival, t.q());
                         break; }
                     case STORE: {
                         selected();
@@ -657,12 +657,18 @@ public class IMAP {
             if (c == '\r' || c == '\n') { if (freak) bad("unexpected end of line"); return null; }
             else if (c == '{') {
                 while(stream.peekc() != '}') sb.append(stream.getc());
+                stream.getc();
                 stream.println("+ Ready when you are...");
                 int octets = Integer.parseInt(sb.toString());
                 while(stream.peekc() == ' ') stream.getc();   // whitespace
-                while (stream.getc() != '\n' && stream.getc() != '\r') { }
+                while(stream.peekc() == '\n' || stream.peekc() == '\r') stream.getc();
                 byte[] bytes = new byte[octets];
-                stream.read(bytes, 0, bytes.length);
+                int numread = 0;
+                while(numread < bytes.length) {
+                    int n = stream.read(bytes, numread, bytes.length - numread);
+                    if (n == -1) bad("end of stream while reading IMAP qstring");
+                    numread += n;
+                }
                 return new Token(new String(bytes), true);
             } else if (c == '\"') {
                 while(true) {