From 5f8adabb6286fdcb0ff8a0ea5d1d58f40eef51f4 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 27 Aug 2012 03:28:16 -0400
Subject: [PATCH] Add simple (constructor) tests for Framework classes

---
 program/include/rcube_imap.php |   48 ++++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 57b85c3..5dd9c12 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -359,11 +359,11 @@
 
         return array(
             $this->search_string,
-	        $this->search_set,
-        	$this->search_charset,
-        	$this->search_sort_field,
-        	$this->search_sorted,
-	    );
+            $this->search_set,
+            $this->search_charset,
+            $this->search_sort_field,
+            $this->search_sorted,
+        );
     }
 
 
@@ -1012,8 +1012,8 @@
                 $a_msg_headers, $this->sort_field, $this->sort_order);
 
             // only return the requested part of the set
-            $a_msg_headers = array_slice(array_values($a_msg_headers),
-                $from, min($cnt-$to, $this->page_size));
+            $slice_length  = min($this->page_size, $cnt - ($to > $cnt ? $from : $to));
+            $a_msg_headers = array_slice(array_values($a_msg_headers), $from, $slice_length);
 
             if ($slice) {
                 $a_msg_headers = array_slice($a_msg_headers, -$slice, $slice);
@@ -2138,14 +2138,17 @@
 
     /**
      * Sends the whole message source to stdout
+     *
+     * @param int  $uid       Message UID
+     * @param bool $formatted Enables line-ending formatting
      */
-    public function print_raw_body($uid)
+    public function print_raw_body($uid, $formatted = true)
     {
         if (!$this->check_connection()) {
             return;
         }
 
-        $this->conn->handlePartBody($this->folder, $uid, true, NULL, NULL, true);
+        $this->conn->handlePartBody($this->folder, $uid, true, null, null, true, null, $formatted);
     }
 
 
@@ -3229,8 +3232,9 @@
         $cache_key = 'mailboxes.folder-info.' . $folder;
         $cached = $this->get_cache($cache_key);
 
-        if (is_array($cached))
+        if (is_array($cached)) {
             return $cached;
+        }
 
         $acl       = $this->get_capability('ACL');
         $namespace = $this->get_namespace();
@@ -3267,10 +3271,9 @@
         $options['name']       = $folder;
         $options['attributes'] = $this->folder_attributes($folder, true);
         $options['namespace']  = $this->folder_namespace($folder);
-        $options['rights']     = $acl && !$options['is_root'] ? (array)$this->my_rights($folder) : array();
         $options['special']    = in_array($folder, $this->default_folders);
 
-        // Set 'noselect' and 'norename' flags
+        // Set 'noselect' flag
         if (is_array($options['attributes'])) {
             foreach ($options['attributes'] as $attrib) {
                 $attrib = strtolower($attrib);
@@ -3283,6 +3286,15 @@
             $options['noselect'] = true;
         }
 
+        // Get folder rights (MYRIGHTS)
+        if ($acl && !$options['noselect']) {
+            // skip shared roots
+            if (!$options['is_root'] || $options['namespace'] == 'personal') {
+                $options['rights'] =  (array)$this->my_rights($folder);
+            }
+        }
+
+        // Set 'norename' flag
         if (!empty($options['rights'])) {
             $options['norename'] = !in_array('x', $options['rights']) && !in_array('d', $options['rights']);
 
@@ -3838,12 +3850,12 @@
     protected function rsort($folder, $delimiter, &$list, &$out)
     {
         while (list($key, $name) = each($list)) {
-	        if (strpos($name, $folder.$delimiter) === 0) {
-	            // set the type of folder name variable (#1485527)
-    	        $out[] = (string) $name;
-	            unset($list[$key]);
-	            $this->rsort($name, $delimiter, $list, $out);
-	        }
+            if (strpos($name, $folder.$delimiter) === 0) {
+                // set the type of folder name variable (#1485527)
+                $out[] = (string) $name;
+                unset($list[$key]);
+                $this->rsort($name, $delimiter, $list, $out);
+            }
         }
         reset($list);
     }

--
Gitblit v1.9.1