Add additional Horde_Imap_Client_Base::status() returns.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 27 Jan 2010 18:21:24 +0000 (11:21 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 27 Jan 2010 18:21:24 +0000 (11:21 -0700)
Add STATUS_LASTMODSEQ and STATUS_LASTMODSEQUIDS to quickly determine the
list of changed UIDs in a mailbox if CONDSTORE is enabled.

framework/Imap_Client/lib/Horde/Imap/Client.php
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php

index c9408b0..3efd71f 100644 (file)
@@ -95,7 +95,9 @@ class Horde_Imap_Client
     const STATUS_FLAGS = 128;
     const STATUS_PERMFLAGS = 256;
     const STATUS_HIGHESTMODSEQ = 512;
-    const STATUS_UIDNOTSTICKY = 1024;
+    const STATUS_LASTMODSEQ = 1024;
+    const STATUS_LASTMODSEQUIDS = 2048;
+    const STATUS_UIDNOTSTICKY = 4096;
 
     /* Constants for search() */
     const SORT_ARRIVAL = 1;
index 97b3598..78f67d0 100644 (file)
@@ -961,6 +961,24 @@ abstract class Horde_Imap_Client_Base
      *                  not available or the mailbox does not support
      *                  mod-sequences.
      *
+     * Flag: Horde_Imap_Client::STATUS_LASTMODSEQ
+     *   Return key: 'lastmodseq'
+     *   Return format: (integer) If the server supports the CONDSTORE IMAP
+     *                  extension, this will be the cached mod-sequence value
+     *                  of the mailbox when it was first opened if
+     *                  HIGHESTMODSEQ changed. Else 0 if CONDSTORE not
+     *                  available, the mailbox does not support mod-sequences,
+     *                  or the mod-sequence did not change.
+     *
+     * Flag: Horde_Imap_Client::STATUS_LASTMODSEQUIDS
+     *   Return key: 'lastmodsequids'
+     *   Return format: (array) If the server supports the CONDSTORE IMAP
+     *                  extension, this will be the list of UIDs changed in
+     *                  the mailbox when it was first opened if HIGHESTMODSEQ
+     *                  changed. Else an empty array if CONDSTORE not
+     *                  available, the mailbox does not support mod-sequences,
+     *                  or the mod-sequence did not change.
+     *
      * Flag: Horde_Imap_Client::STATUS_UIDNOTSTICKY
      *   Return key: 'uidnotsticky'
      *   Return format: (boolean) If the server supports the UIDPLUS IMAP
@@ -1023,6 +1041,25 @@ abstract class Horde_Imap_Client_Base
             $flags &= ~Horde_Imap_Client::STATUS_UIDNOTSTICKY;
         }
 
+        /* Handle LASTMODSEQ related options. */
+        if ($flags & Horde_Imap_Client::STATUS_LASTMODSEQ) {
+            $ret['lastmodseq'] = 0;
+            if (isset($this->_init['enabled']['CONDSTORE']) &&
+                isset($this->_temp['lastmodseq'][$mailbox])) {
+                $ret['lastmodseq'] = $this->_temp['lastmodseq'][$mailbox];
+            }
+            $flags &= ~Horde_Imap_Client::STATUS_LASTMODSEQ;
+        }
+
+        if ($flags & Horde_Imap_Client::STATUS_LASTMODSEQUIDS) {
+            $ret['lastmodsequids'] = array();
+            if (isset($this->_init['enabled']['CONDSTORE']) &&
+                isset($this->_temp['lastmodsequids'][$mailbox])) {
+                $ret['lastmodsequids'] = $this->utils->fromSequenceString($this->_temp['lastmodsequids'][$mailbox]);
+            }
+            $flags &= ~Horde_Imap_Client::STATUS_LASTMODSEQUIDS;
+        }
+
         if (!$flags) {
             return $ret;
         }
@@ -2742,7 +2779,7 @@ abstract class Horde_Imap_Client_Base
      * 'mailbox' - (string) The mailbox to update.
      *             DEFAULT: The selected mailbox.
      * 'seq' - (boolean) Is data stored with sequence numbers?
-     *             DEFAULT: Data stored with UIDs.
+     *         DEFAULT: Data stored with UIDs.
      * 'uidvalid' - (integer) The UID Validity number.
      *              DEFAULT: UIDVALIDITY discovered via a status() call.
      * </pre>
@@ -2860,6 +2897,10 @@ abstract class Horde_Imap_Client_Base
             $metadata = $this->_cache->getMetaData($mailbox, $uidvalid, array('HICmodseq'));
             if (!isset($metadata['HICmodseq']) ||
                 ($metadata['HICmodseq'] != $modseq)) {
+                $this->_temp['lastmodseq'][$mailbox] = $metadata['HICmodseq'];
+                if (count($tocache)) {
+                    $this->_temp['lastmodsequids'][$mailbox] = $this->utils->toSequenceString(array_keys($tocache), array('nosort' => true));
+                }
                 $this->_updateMetaData($mailbox, array('HICmodseq' => $modseq), $uidvalid);
             }
         }
index 65d826c..1007a92 100644 (file)
@@ -1175,7 +1175,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             Horde_Imap_Client::STATUS_UIDNOTSTICKY => 'uidnotsticky',
         );
 
-        /* Don't include 'highestmodseq' return if server does not support it.
+        /* Don't include modseq returns if server does not support it.
          * OK to use queryCapability('CONDSTORE') here because we may not have
          * yet sent an enabling command. */
         if ($this->queryCapability('CONDSTORE')) {