From 3412e50b54e3daac8745234e21ab6e72be0ed165 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 04 Jun 2014 11:20:33 -0400
Subject: [PATCH] Fix attachment menu structure and aria-attributes

---
 program/lib/Roundcube/rcube_result_multifolder.php |   67 ++++++++++++++++++++++++++++++---
 1 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/program/lib/Roundcube/rcube_result_multifolder.php b/program/lib/Roundcube/rcube_result_multifolder.php
index b5473b8..4bbd218 100644
--- a/program/lib/Roundcube/rcube_result_multifolder.php
+++ b/program/lib/Roundcube/rcube_result_multifolder.php
@@ -28,6 +28,7 @@
 {
     public $multi = true;
     public $sets = array();
+    public $incomplete = false;
     public $folder;
 
     protected $meta = array();
@@ -54,15 +55,27 @@
      */
     public function add($result)
     {
-        if ($count = $result->count()) {
-            $this->sets[] = $result;
-            $this->meta['count'] += $count;
+        $this->sets[] = $result;
 
-            // append UIDs to global index
-            $folder = $result->get_parameters('MAILBOX');
-            $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get());
-            $this->index = array_merge($this->index, $index);
+        if ($result->count()) {
+            $this->append_result($result);
         }
+        else if ($result->incomplete) {
+            $this->incomplete = true;
+        }
+    }
+
+    /**
+     * Append message UIDs from the given result to our index
+     */
+    protected function append_result($result)
+    {
+        $this->meta['count'] += $result->count();
+
+        // append UIDs to global index
+        $folder = $result->get_parameters('MAILBOX');
+        $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get());
+        $this->index = array_merge($this->index, $index);
     }
 
     /**
@@ -266,6 +279,22 @@
         return $params;
     }
 
+    /**
+     * Returns the stored result object for a particular folder
+     *
+     * @param string $folder  Folder name
+     * @return false|obejct rcube_result_* instance of false if none found
+     */
+    public function get_set($folder)
+    {
+        foreach ($this->sets as $set) {
+            if ($set->get_parameters('MAILBOX') == $folder) {
+                return $set;
+            }
+        }
+
+        return false;
+    }
 
     /**
      * Returns length of internal data representation
@@ -276,4 +305,28 @@
     {
         return $this->count();
     }
+
+
+    /* Serialize magic methods */
+
+    public function __sleep()
+    {
+        return array('sets','folders','sorting','order');
+    }
+
+    public function __wakeup()
+    {
+        // restore index from saved result sets
+        $this->meta = array('count' => 0);
+
+        foreach ($this->sets as $result) {
+            if ($result->count()) {
+                $this->append_result($result);
+            }
+            else if ($result->incomplete) {
+                $this->incomplete = true;
+            }
+        }
+    }
+
 }

--
Gitblit v1.9.1