change num() to imapNumber() and nntpNumber(), add comments about semantics
[org.ibex.mail.git] / src / org / ibex / mail / protocol / IMAP.java
index f6c084f..5b98105 100644 (file)
@@ -207,7 +207,7 @@ public class IMAP {
         public int[] search(Query q, boolean uid) {
             Vec.Int vec = new Vec.Int();
             for(Mailbox.Iterator it = selected().iterator(q); it.next();) {
-                vec.addElement(uid ? it.uid() : it.num());
+                vec.addElement(uid ? it.uid() : it.imapNumber());
                 it.recent(false);
             }
             return vec.dump();
@@ -225,7 +225,7 @@ public class IMAP {
                 else if (style == 0) it.setFlags(flags);
                 else if (style == 1) it.addFlags(flags);
                 it.recent(recent);
-                if (!silent) client.fetch(it.num(), it.flags(), -1, null, it.uid());
+                if (!silent) client.fetch(it.imapNumber(), it.flags(), -1, null, it.uid());
             }
         }            
         public void rename(String from0, String to) {
@@ -239,7 +239,7 @@ public class IMAP {
                 Message message = ((spec & (BODYSTRUCTURE | ENVELOPE | INTERNALDATE | FIELDS | FIELDSNOT | RFC822 |
                                             RFC822TEXT | RFC822SIZE | HEADERNOT | HEADER)) != 0) ? it.cur() : null;
                 int size = message == null ? 0 : message.getLength();
-                client.fetch(it.num(), it.flags(), size, message, it.uid());
+                client.fetch(it.imapNumber(), it.flags(), size, message, it.uid());
                 it.recent(false);
             }
         }
@@ -301,7 +301,6 @@ public class IMAP {
                     case SUBSCRIBE:    api.subscribe(token().astring()); break;
                     case UNSUBSCRIBE:  api.unsubscribe(token().astring()); break;
                     case RENAME:       api.rename(token().astring(), token().astring()); break;
-                    case COPY:         selected(); api.copy(Query.set(uid, token().set(maxn(uid))), token().astring()); break;
                     case DELETE:       api.delete(token().atom()); break;
                     case CHECK:        selected(); api.check(); break;
                     case NOOP:         api.noop(); break;
@@ -309,8 +308,13 @@ public class IMAP {
                     case EXPUNGE:      selected(); api.expunge(); break;
                     case UNSELECT:     selected(); api.unselect(); selected = false; break;
                     case CREATE:       api.create(token().astring()); break;
-                    case FETCH:        selected(); fetch(Query.set(lastuid=uid, token().set(maxn(uid))),
+                    case FETCH:        selected(); fetch(((lastuid=uid)
+                                                          ? Query.uid(token().set(maxn(uid)))
+                                                          : Query.imapNumber(token().set(maxn(uid)))),
                                                         lastfetch=token().lx(), 0, 0, 0, uid, 0); break;
+                    case COPY:         selected(); api.copy(uid
+                                                            ? Query.uid(token().set(maxn(uid)))
+                                                            : Query.imapNumber(token().set(maxn(uid))), token().astring()); break;
                     case SEARCH: {
                         selected();
                         int[] result = api.search(query(maxn(uid)), uid);
@@ -357,7 +361,7 @@ public class IMAP {
                         break; }
                     case STORE: {
                         selected();
-                        Query q = uid ? Query.uid(token().set(maxn(uid))) : Query.num(token().set(maxn(uid)));
+                        Query q = uid ? Query.uid(token().set(maxn(uid))) : Query.imapNumber(token().set(maxn(uid)));
                         String s = token().atom().toUpperCase();
                         int flags = token().flags();
                         if (s.equals("FLAGS"))              api.setFlags(q,    flags, uid, false);
@@ -460,7 +464,7 @@ public class IMAP {
                 } else if (!(s.equals("BODY.PEEK") || s.equals("BODY"))) { throw new Server.No("unknown fetch argument: " + s);
                 } else {
                     if (s.equalsIgnoreCase("BODY.PEEK"))   spec |= PEEK;
-                    //else if (e) api.addFlags(Query.num(new int[] { num, num }), Mailbox.Flag.SEEN, false, false);
+                    //else if (e) api.addFlags(Query.imapNumber(new int[] { num, num }), Mailbox.Flag.SEEN, false, false);
                     if (i >= t.length - 1 || t[i+1].type != Parser.Token.LIST) {
                        spec |= BODYSTRUCTURE;
                        if (e) { r.append(" "); r.append(Printer.bodystructure(m)); } continue;
@@ -563,7 +567,7 @@ public class IMAP {
                 Parser.Token t = token(false);
                 if (t == null) break;
                 if (t.type == t.LIST) throw new Server.No("nested queries not yet supported FIXME");
-                else if (t.type == t.SET) return Query.num(t.set(max));
+                else if (t.type == t.SET) return Query.imapNumber(t.set(max));
                 s = t.atom().toUpperCase();
                 if (s.equals("NOT"))   return Query.not(query(max, maxuid));
                 if (s.equals("OR"))    return Query.or(query(max, maxuid), query(max, maxuid));    // FIXME parse rest of list