Aleksander Machniak
2015-07-19 8bed5e0151eb375e2d2dc91e4e6c6d5aa62daa5c
program/lib/Roundcube/rcube_result_multifolder.php
@@ -1,6 +1,6 @@
<?php
/*
/**
 +-----------------------------------------------------------------------+
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
@@ -26,16 +26,16 @@
 */
class rcube_result_multifolder
{
    public $multi = true;
    public $sets = array();
    public $multi      = true;
    public $sets       = array();
    public $incomplete = false;
    public $folder;
    protected $meta = array();
    protected $index = array();
    protected $meta    = array();
    protected $index   = array();
    protected $folders = array();
    protected $order   = 'ASC';
    protected $sorting;
    protected $order = 'ASC';
    /**
@@ -44,9 +44,8 @@
    public function __construct($folders = array())
    {
        $this->folders = $folders;
        $this->meta = array('count' => 0);
        $this->meta    = array('count' => 0);
    }
    /**
     * Initializes object with SORT command response
@@ -57,17 +56,26 @@
    {
        $this->sets[] = $result;
        if ($count = $result->count()) {
            $this->meta['count'] += $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);
        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);
    }
    /**
@@ -81,7 +89,7 @@
        }
        $this->sorting = $sort_field;
        $this->order = $sort_order;
        $this->order   = $sort_order;
    }
    /**
@@ -94,7 +102,6 @@
        return false;
    }
    /**
     * Checks if the result is empty
     *
@@ -104,7 +111,6 @@
    {
        return empty($this->sets) || $this->meta['count'] == 0;
    }
    /**
     * Returns number of elements in the result
@@ -116,7 +122,6 @@
        return $this->meta['count'];
    }
    /**
     * Returns number of elements in the result.
     * Alias for count() for compatibility with rcube_result_thread
@@ -127,7 +132,6 @@
    {
        return $this->count();
    }
    /**
     * Reverts order of elements in the result
@@ -142,12 +146,13 @@
            if ($this->order != $set->get_parameters('ORDER')) {
                $set->revert();
            }
            $folder = $set->get_parameters('MAILBOX');
            $index = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $set->get());
            $index  = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $set->get());
            $this->index = array_merge($this->index, $index);
        }
    }
    /**
     * Check if the given message ID exists in the object
@@ -163,9 +168,9 @@
        if (!empty($this->folder)) {
            $msgid .= '-' . $this->folder;
        }
        return array_search($msgid, $this->index);
    }
    /**
     * Filters data set. Removes elements listed in $ids list.
@@ -180,6 +185,7 @@
            if ($set->get_parameters('MAILBOX') == $folder) {
                $set->filter($ids);
            }
            $this->meta['count'] += $set->count();
        }
    }
@@ -219,7 +225,6 @@
        return $this->index;
    }
    /**
     * Return all messages in the result.
     *
@@ -229,7 +234,6 @@
    {
        return '';
    }
    /**
     * Return result element at specified index
@@ -247,7 +251,6 @@
        }
    }
    /**
     * Returns response parameters, e.g. ESEARCH's MIN/MAX/COUNT/ALL/MODSEQ
     * or internal data e.g. MAILBOX, ORDER
@@ -259,8 +262,8 @@
    public function get_parameters($param=null)
    {
        $params = array(
            'SORT' => $this->sorting,
            'ORDER' => $this->order,
            'SORT'    => $this->sorting,
            'ORDER'   => $this->order,
            'MAILBOX' => $this->folders,
        );
@@ -312,18 +315,12 @@
        $this->meta = array('count' => 0);
        foreach ($this->sets as $result) {
            if ($count = $result->count()) {
                $this->meta['count'] += $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);
            if ($result->count()) {
                $this->append_result($result);
            }
            else if ($result->incomplete) {
                $this->incomplete = true;
            }
        }
    }
}