Catch flag changes in DIMP mailbox refreshes.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 27 Jan 2010 18:32:09 +0000 (11:32 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 27 Jan 2010 18:37:08 +0000 (11:37 -0700)
Requires CONDSTORE support on the server.

imp/docs/CHANGES
imp/lib/Mailbox.php
imp/lib/Views/ListMessages.php

index 75986aa..854ad50 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Catch flag changes from other IMAP clients when refreshing if CONDSTORE
+      is available on the IMAP server (DIMP).
 [mms] Improved forwarding options.
 [mms] Add support for LIST-STATUS IMAP extension.
 [mms] Add hook to allow determination of compose attachments MIME type.
index 85168a2..032cf49 100644 (file)
@@ -821,6 +821,10 @@ class IMP_Mailbox
     /**
      * Returns a unique identifier for the current mailbox status.
      *
+     * This cache ID is guaranteed to change if messages are added/deleted from
+     * the mailbox. Additionally, if CONDSTORE is available on the remote
+     * IMAP server, this ID will change if flag information changes.
+     *
      * @return string  The cache ID string, which will change when the
      *                 composition of the mailbox changes.
      */
index 38943c8..32c92f5 100644 (file)
@@ -171,16 +171,24 @@ class IMP_Views_ListMessages
         }
 
         /* Get the cached list. */
-        if (empty($args['cache'])) {
-            $cached = array();
-        } else {
+        $cached = $changed = array();
+        if (!empty($args['cache'])) {
             if ($is_search) {
-                $cached = Horde_Serialize::unserialize($args['cache'], Horde_Serialize::JSON);
+                $cached = array_flip(Horde_Serialize::unserialize($args['cache'], Horde_Serialize::JSON));
             } else {
                 $cached = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($args['cache']);
-                $cached = reset($cached);
+                $cached = array_flip(reset($cached));
+
+                /* Check for cached entires marked as changed via CONDSTORE
+                 * IMAP extension. If changed, resend the entire entry to
+                 * update the browser cache (done below). */
+                if ($args['change']) {
+                    $status = $GLOBALS['imp_imap']->ob()->status($mbox, Horde_Imap_Client::STATUS_LASTMODSEQUIDS);
+                    if (!empty($status['lastmodsequids'])) {
+                        $changed = array_flip($status['lastmodsequids']);
+                    }
+                }
             }
-            $cached = array_flip($cached);
         }
 
         if (!empty($args['search_unseen'])) {
@@ -234,8 +242,10 @@ class IMP_Views_ListMessages
         foreach ($uidlist as $uid => $seq) {
             $msglist[$seq] = $sorted_list['s'][$seq];
             $rowlist[$uid] = $seq;
-            if (!isset($cached[$uid])) {
-                $data[] = $seq;
+            /* Send browser message data if not already cached or if CONDSTORE
+             * has indiciated that data has changed. */
+            if (!isset($cached[$uid]) || isset($changed[$uid])) {
+                $data[$seq] = 1;
             }
         }
         $result->rowlist = $rowlist;
@@ -271,7 +281,7 @@ class IMP_Views_ListMessages
         }
 
         /* Build the overview list. */
-        $result->data = $this->_getOverviewData($imp_mailbox, $mbox, $data, $is_search);
+        $result->data = $this->_getOverviewData($imp_mailbox, $mbox, array_keys($data), $is_search);
 
         /* Get unseen/thread information. */
         if (!$is_search) {