reshuffling of file locations to make package structure flatter
[org.ibex.mail.git] / src / org / ibex / mail / IMAP.java
similarity index 97%
rename from src/org/ibex/mail/protocol/IMAP.java
rename to src/org/ibex/mail/IMAP.java
index 848feb2..0632ea4 100644 (file)
@@ -2,7 +2,7 @@
 // Licensed under the Apache Public Source License 2.0 ("the License").
 // You may not use this file except in compliance with the License.
 
-package org.ibex.mail.protocol;
+package org.ibex.mail;
 import org.ibex.io.*;
 import org.ibex.crypto.*;
 import org.ibex.jinetd.Listener;
@@ -208,7 +208,7 @@ public class IMAP {
             Vec.Int vec = new Vec.Int();
             for(Mailbox.Iterator it = selected().iterator(q); it.next();) {
                 vec.addElement(uid ? it.uid() : it.imapNumber());
-                it.setFlag(Mailbox.Flag.RECENT, false);
+                it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT);
             }
             return vec.dump();
         }
@@ -218,14 +218,14 @@ public class IMAP {
         public void removeFlags(Query q, int f, boolean uid, boolean silent) { doFlags(q, f, uid, -1, silent); }
         private void doFlags(Query q, int flags, boolean uid, int style, boolean silent) {
             for(Mailbox.Iterator it = selected().iterator(q);it.next();) {
-                boolean recent = it.getFlag(Mailbox.Flag.RECENT);
+                // FIXME: what's going on here with the recent flag?
+                //boolean recent = it.getFlag(Mailbox.Flag.RECENT);
                 try { throw new Exception("flags " + flags); } catch (Exception e) { Log.error(this, e); }
-                for(int flag : Mailbox.Flag.all)
-                    if (style == -1)     { if ((flags & flag)!=0) it.setFlag(flag, false); }
-                    else if (style == 0) { it.setFlag(flag, ((flags & flag)!=0)); }
-                    else if (style == 1) { if ((flags & flag)!=0) it.setFlag(flag, true); }
-                it.setFlag(Mailbox.Flag.RECENT, recent);
-                if (!silent) client.fetch(it.imapNumber(), flags(it), -1, null, it.uid());
+                if (style == -1)     it.setFlags(it.getFlags() & ~flags);
+                else if (style == 0) it.setFlags(flags);
+                else if (style == 1) it.setFlags(it.getFlags() | flags);
+                //it.setFlag(Mailbox.Flag.RECENT, recent);
+                if (!silent) client.fetch(it.imapNumber(), it.getFlags(), -1, null, it.uid());
             }
         }
 
@@ -240,20 +240,12 @@ 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.imapNumber(), flags(it), size, message, it.uid());
-                it.setFlag(Mailbox.Flag.RECENT, false);
+                client.fetch(it.imapNumber(), it.getFlags(), size, message, it.uid());
+                it.setFlags(it.getFlags() & ~Mailbox.Flag.RECENT);
             }
         }
     }
 
-    private static int flags(Mailbox.Iterator it) {
-        int ret = 0;
-        for(int flag : Mailbox.Flag.all)
-            if (it.getFlag(flag))
-                ret |= flag;
-        return ret;
-    }
-
     // Single Session Handler //////////////////////////////////////////////////////////////////////////////
 
     /** takes an IMAP.Server and exposes it to the world as an IMAP server on a TCP socket */
@@ -790,12 +782,12 @@ public class IMAP {
             }
             static String flags(Mailbox.Iterator it) {
                 return
-                    (it.getFlag(Mailbox.Flag.DELETED)  ? "\\Deleted "  : "") +
-                    (it.getFlag(Mailbox.Flag.SEEN)     ? "\\Seen "     : "") +
-                    (it.getFlag(Mailbox.Flag.FLAGGED)  ? "\\Flagged "  : "") +
-                    (it.getFlag(Mailbox.Flag.DRAFT)    ? "\\Draft "    : "") +
-                    (it.getFlag(Mailbox.Flag.ANSWERED) ? "\\Answered " : "") +
-                    (it.getFlag(Mailbox.Flag.RECENT)   ? "\\Recent "   : "");
+                    ((it.getFlags() & Mailbox.Flag.DELETED)!=0  ? "\\Deleted "  : "") +
+                    ((it.getFlags() & Mailbox.Flag.SEEN)!=0     ? "\\Seen "     : "") +
+                    ((it.getFlags() & Mailbox.Flag.FLAGGED)!=0  ? "\\Flagged "  : "") +
+                    ((it.getFlags() & Mailbox.Flag.DRAFT)!=0    ? "\\Draft "    : "") +
+                    ((it.getFlags() & Mailbox.Flag.ANSWERED)!=0 ? "\\Answered " : "") +
+                    ((it.getFlags() & Mailbox.Flag.RECENT)!=0   ? "\\Recent "   : "");
         }
         static String flags(int flags) {
             String ret = "(" +