Author: dbkr
Date: 2008-05-01 08:19:44 +0000 (Thu, 01 May 2008)
New Revision: 19642

Modified:
   trunk/apps/Freemail/src/freemail/OutboundContact.java
Log:
Muppet! Lowest UID, not highest - not that it worked anyway.


Modified: trunk/apps/Freemail/src/freemail/OutboundContact.java
===================================================================
--- trunk/apps/Freemail/src/freemail/OutboundContact.java       2008-05-01 
05:27:12 UTC (rev 19641)
+++ trunk/apps/Freemail/src/freemail/OutboundContact.java       2008-05-01 
08:19:44 UTC (rev 19642)
@@ -284,32 +284,39 @@
         */
        private String getCurrentLowestSlot() {
                QueuedMessage[] queue = getSendQueue();
-               if (queue.length > 0) {
-                       int messageWithHighestUid = 0;
-                       for (int i = 0; i < queue.length; i++) {
-                               if (queue[i] == null) continue;
-                               if (queue[i].uid > messageWithHighestUid) 
messageWithHighestUid = i;
+               int messageWithLowestUid = 0;
+               int lowestUid = Integer.MAX_VALUE;
+               // queue.length == 0 doesn't necessarily imply there's anything
+               // in the queue - the array can contain null values (due to the
+               // sucky way in which getSendQueue() works by returning an 
array)
+               for (int i = 0; i < queue.length; i++) {
+                       if (queue[i] == null) continue;
+                       if (queue[i].uid < lowestUid) {
+                               messageWithLowestUid = i;
+                               lowestUid = queue[i].uid;
                        }
-                       return queue[messageWithHighestUid].slot;
+               }
+               if (lowestUid < Integer.MAX_VALUE) return 
queue[messageWithLowestUid].slot;
+
+               // No messages in the queue, so the current lowest slot is the
+               // next slot we'll insert a message to.
+               String retval = this.contactfile.get("nextslot");
+               if (retval != null) {
+                       return retval;
                } else {
-                       String retval = this.contactfile.get("nextslot");
-                       if (retval != null) {
-                               return retval;
-                       } else {
-                               Logger.minor(this, "Generating first slot for 
contact");
-                               SecureRandom rnd = new SecureRandom();
-                               SHA256Digest sha256 = new SHA256Digest();
-                               byte[] buf = new byte[sha256.getDigestSize()];
-                               
-                               rnd.nextBytes(buf);
-                               
-                               String firstSlot = Base32.encode(buf);
-                               
-                               this.contactfile.put("nextslot", 
Base32.encode(buf));
-                               
-                               return firstSlot;
+                       Logger.minor(this, "Generating first slot for contact");
+                       SecureRandom rnd = new SecureRandom();
+                       SHA256Digest sha256 = new SHA256Digest();
+                       byte[] buf = new byte[sha256.getDigestSize()];
+                       
+                       rnd.nextBytes(buf);
+                       
+                       String firstSlot = Base32.encode(buf);
+                       
+                       this.contactfile.put("nextslot", Base32.encode(buf));
+                       
+                       return firstSlot;
                        }
-               }
        }

        private byte[] getAESParams() {


Reply via email to