From 46f7b7096450939fe03c95aa81ce06ae4bfca89d Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 28 Mar 2016 06:51:43 -0400
Subject: [PATCH] Enable reply/reply-all/forward buttons also in preview frame of message/rfc822

---
 program/lib/Roundcube/rcube_result_thread.php |   66 +++++++++++++-------------------
 1 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/program/lib/Roundcube/rcube_result_thread.php b/program/lib/Roundcube/rcube_result_thread.php
index 7657550..5388eb1 100644
--- a/program/lib/Roundcube/rcube_result_thread.php
+++ b/program/lib/Roundcube/rcube_result_thread.php
@@ -1,6 +1,6 @@
 <?php
 
-/*
+/**
  +-----------------------------------------------------------------------+
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
@@ -26,6 +26,8 @@
  */
 class rcube_result_thread
 {
+    public $incomplete = false;
+
     protected $raw_data;
     protected $mailbox;
     protected $meta = array();
@@ -44,7 +46,6 @@
         $this->mailbox = $mailbox;
         $this->init($data);
     }
-
 
     /**
      * Initializes object with IMAP command response
@@ -81,7 +82,6 @@
         $this->raw_data = $this->parse_thread($data);
     }
 
-
     /**
      * Checks the result from IMAP command
      *
@@ -92,7 +92,6 @@
         return $this->raw_data === null ? true : false;
     }
 
-
     /**
      * Checks if the result is empty
      *
@@ -102,7 +101,6 @@
     {
         return empty($this->raw_data) ? true : false;
     }
-
 
     /**
      * Returns number of elements (threads) in the result
@@ -126,7 +124,6 @@
 
         return $this->meta['count'];
     }
-
 
     /**
      * Returns number of all messages in the result
@@ -153,7 +150,6 @@
         return $this->meta['messages'];
     }
 
-
     /**
      * Returns maximum message identifier in the result
      *
@@ -167,7 +163,6 @@
         return $this->meta['max'];
     }
 
-
     /**
      * Returns minimum message identifier in the result
      *
@@ -180,7 +175,6 @@
         }
         return $this->meta['min'];
     }
-
 
     /**
      * Slices data set.
@@ -197,7 +191,6 @@
         $this->meta['count'] = count($data);
         $this->raw_data      = implode(self::SEPARATOR_ELEMENT, $data);
     }
-
 
     /**
      * Filters data set. Removes threads not listed in $roots list.
@@ -238,7 +231,6 @@
         $this->raw_data = ltrim($result, self::SEPARATOR_ELEMENT);
     }
 
-
     /**
      * Reverts order of elements in the result
      */
@@ -267,7 +259,6 @@
 
         $this->raw_data = rtrim($result, self::SEPARATOR_ELEMENT);
     }
-
 
     /**
      * Check if the given message ID exists in the object
@@ -312,7 +303,6 @@
         return false;
     }
 
-
     /**
      * Return IDs of all messages in the result. Threaded data will be flattened.
      *
@@ -331,7 +321,6 @@
         return preg_split($regexp, $this->raw_data);
     }
 
-
     /**
      * Return all messages in the result.
      *
@@ -345,7 +334,6 @@
 
         return rcube_imap_generic::compressMessageSet($this->get());
     }
-
 
     /**
      * Return result element at specified index (all messages, not roots)
@@ -416,17 +404,16 @@
         return $data[$index];
     }
 
-
     /**
      * Returns response parameters e.g. MAILBOX, ORDER
      *
-     * @param string $param  Parameter name
+     * @param string $param Parameter name
      *
      * @return array|string Response parameters or parameter value
      */
     public function get_parameters($param=null)
     {
-        $params = $this->params;
+        $params = array();
         $params['MAILBOX'] = $this->mailbox;
         $params['ORDER']   = $this->order;
 
@@ -436,7 +423,6 @@
 
         return $params;
     }
-
 
     /**
      * THREAD=REFS sorting implementation (based on provided index)
@@ -453,7 +439,7 @@
 
         // when sorting search result it's good to make the index smaller
         if ($index->count() != $this->count_messages()) {
-            $index->intersect($this->get());
+            $index->filter($this->get());
         }
 
         $result  = array_fill_keys($index->get(), null);
@@ -507,7 +493,6 @@
         $this->raw_data = implode(self::SEPARATOR_ELEMENT, $result);
     }
 
-
     /**
      * Returns data as tree
      *
@@ -532,7 +517,6 @@
         return $result;
     }
 
-
     /**
      * Returns thread depth and children data
      *
@@ -549,7 +533,6 @@
         return array($depth, $children);
     }
 
-
     /**
      * Creates 'depth' and 'children' arrays from stored thread 'tree' data.
      */
@@ -564,7 +547,6 @@
             }
         }
     }
-
 
     /**
      * Converts part of the raw thread into an array
@@ -588,7 +570,6 @@
         return $result;
     }
 
-
     /**
      * IMAP THREAD response parser
      */
@@ -606,33 +587,39 @@
         // arrays handling is much more expensive
         // For the following structure: THREAD (2)(3 6 (4 23)(44 7 96))
         // -- 2
-        //
         // -- 3
         //     \-- 6
         //         |-- 4
         //         |    \-- 23
         //         |
         //         \-- 44
-        //              \-- 7
-        //                   \-- 96
+        //               \-- 7
+        //                    \-- 96
         //
         // The output will be: 2,3^1:6^2:4^3:23^2:44^3:7^4:96
 
         if ($str[$begin] != '(') {
-            $stop = $begin + strspn($str, '1234567890', $begin, $end - $begin);
-            $msg  = substr($str, $begin, $stop - $begin);
-            if (!$msg) {
+            // find next bracket
+            $stop      = $begin + strcspn($str, '()', $begin, $end - $begin);
+            $messages  = explode(' ', trim(substr($str, $begin, $stop - $begin)));
+
+            if (empty($messages)) {
                 return $node;
             }
 
-            $this->meta['messages']++;
-
-            $node .= ($depth ? self::SEPARATOR_ITEM.$depth.self::SEPARATOR_LEVEL : '').$msg;
-
-            if ($stop + 1 < $end) {
-                $node .= $this->parse_thread($str, $stop + 1, $end, $depth + 1);
+            foreach ($messages as $msg) {
+                if ($msg) {
+                    $node .= ($depth ? self::SEPARATOR_ITEM.$depth.self::SEPARATOR_LEVEL : '').$msg;
+                    $this->meta['messages']++;
+                    $depth++;
+                }
             }
-        } else {
+
+            if ($stop < $end) {
+                $node .= $this->parse_thread($str, $stop, $end, $depth);
+            }
+        }
+        else {
             $off = $begin;
             while ($off < $end) {
                 $start = $off;
@@ -649,7 +636,8 @@
                     if ($p1 !== false && $p1 < $p) {
                         $off = $p1 + 1;
                         $n++;
-                    } else {
+                    }
+                    else {
                         $off = $p + 1;
                         $n--;
                     }

--
Gitblit v1.9.1